Everton
Everton

Reputation: 13825

How to define Pod health check port for livenessProbe/readinessProbe

How do I define distinct Pod ports, one for application and another for health check (readinessProbe)?

Is the specification for ports, shown below, a correct way to make the readinessProbe to check the health check port TCP/9090 ? I mean, is the readinessProbe going to reach port 9090 (assuming it is open by the running container of course) ? Or does one need to specify any other port (nodePort, targetPort, port, whatever) ?

kind: Deployment
spec:
  template:
    spec:
      containers:
      - name: myapp
        image: <image>
        ports:
        - name: myapp-port
          containerPort: 8080
          protocol: TCP
        - name: healthcheck-port
          containerPort: 9090
          protocol: TCP

        readinessProbe:
          httpGet:
            port: healthcheck-port
            scheme: HTTP
          initialDelaySeconds: 60
          timeoutSeconds: 5
          periodSeconds: 10
          successThreshold: 2
          failureThreshold: 2

Upvotes: 2

Views: 14023

Answers (4)

pr-pal
pr-pal

Reputation: 3538

readinessProbe:
  tcpSocket:
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 10

Good reference:

https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-tcp-liveness-probe

Upvotes: 0

garlicFrancium
garlicFrancium

Reputation: 2259

Your current configuration is almost correct as mentioned by @shashank-v except the port name.

What i would rather like to point out here apart from the name is to use the same port as best practice, which is TCP/8080 but have a healthz path where you application responds with ok or running. then in your httpget:

readinessProbe:
      httpGet:
        port: 8080
        path: /healthz

Upvotes: 2

suren
suren

Reputation: 8766

You can specify any port and path (assuming it's http) for livenessProbe and readinessProbe, but, of course, you need to be serving something there.

It shouldn't be a service port, so NodePort is not an option, as that's kubelet in charge of the health of the containers, and it has direct access to the containers.

Upvotes: 1

Shashank V
Shashank V

Reputation: 11183

Yes, your specification snippet is almost correct. You don't need to specify any thing else to make readiness probe work.

Port names cannot be more than 15 characters, so the name healthcheck-port won't work. You might want to change the name to something smaller like healthcheck.

Upvotes: 7

Related Questions