I created postgres deployment with containerPort as 55432 and same for service. My understanding was when pod is deployed I could access postgres at 55432 but somehow it is not working. I could access postgres on 5432 instead. What am I missing here?
Also does all the pods that gets deployed with k8s have their own set of ports?
From your stack overflow post: you only “told” Kubernetes at what port something is listening inside the container, you didn’t specify to which port you’d like to map that.
kind: Service
apiVersion: v1
metadata:
name: my-postgres-service
spec:
selector:
app: my-postgres-app
ports:
- protocol: TCP
port: 80 #That's the port you'll use to connect
targetPort: 55432 # that's the port at which your app (your postgres) is listening
So I cant connect to postgres running on the pod if I am trying to access it on IP and port of the deployment pod?
I tried on IP from kubectl describe deployment postgrespostgres deployment and port as containerport from deployment. dint work. But it worked on same IP and port as 5432. I am guessing somehow container is using containerPort option and just configuring 5432 for it.
I went through it before. From my understanding it exposes port specified on the pod container is running. I guess for now I will go with 5432 and revisit it once I encounter a problem. Thanks Rira you have been great help.