title: Difference between Container port and targetport in Kubernetes?
body: <p>How is <code>container port</code> different from <code>targetports</code> in a container in Kubernetes?
  Are they used interchangeably, if so why?</p>
  <p>I came across the below code snippet where <code>containerPort</code> is used to denote the <code>port</code> on a pod in Kubernetes.</p>
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: postgres-deployment
    labels:
      app: demo-voting-app
  spec:
    replicas: 1
    selector:
      matchLabels:
        name: postgres-pod
        app: demo-voting-app
    template:
      metadata:
        name: postgres-pod
        labels:
          name: postgres-pod
          app: demo-voting-app
  
      spec:
        containers:
        - name: postgres
          image: postgres:9.4
          ports:
          - containerPort: 5432
          
  </code></pre>
  <p>In the above code snippet, they have given 5432 for the <code>containerPort</code> parameter (in the last line). So, how is this <code>containerPort</code> different from <code>targetport</code>?</p>
  <p>As far as I know, the term <code>port</code> in general refers to the <code>port</code> on the <code>service</code> (Kubernetes). Correct me if I'm incorrect.</p>