How is container port
different from targetports
in a container in Kubernetes?
Are they used interchangeably, if so why?
I came across the below code snippet where containerPort
is used to denote the port
on a pod in Kubernetes.
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
In the above code snippet, they have given 5432 for the containerPort
parameter (in the last line). So, how is this containerPort
different from targetport
?
As far as I know, the term port
in general refers to the port
on the service
(Kubernetes). Correct me if I'm incorrect.