J
J
jenig2021-02-10 10:34:36
Kubernetes
jenig, 2021-02-10 10:34:36

What port to specify in service kubernetes?

I created a pod in kubernetes with image Postgre with port 6009, but when I look at the logs of the pod, it writes the following:

LOG:  listening on IPv4 address "0.0.0.0", port 5432
LOG:  listening on IPv6 address "::", port 5432

I also have a service
Service

---
apiVersion: v1
kind: Service
metadata:
name: database
spec:
ports:
- port: 8080
targetPort: 6009
selector:
app: my-db
type: ClusterIP

Tell me, if in my image, Postgresql is listening on port 5432, then when I create deploy do I need to specify the container port 5432 accordingly?
Does it work like port forwarding?
And what target port to specify in service?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2021-02-10
@jenig

I created a pod in kubernetes with image Postgre with port 6009

Apparently, the port remained 5432.
port - the port on which the Service will accept connections
targetPort - the port on which the service in the pod is listening - 5432 at the moment

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question