How to define Pod health check port for livenessProbe/readinessProbe

1/28/2020

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
-- Everton
kubernetes
kubernetes-health-check
kubernetes-pod

4 Answers

1/28/2020
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

-- pr-pal
Source: StackOverflow

1/28/2020

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.

-- Shashank V
Source: StackOverflow

1/28/2020

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.

-- suren
Source: StackOverflow

1/28/2020

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
-- garlicFrancium
Source: StackOverflow