1

I am trying to create a RollingUpdate and trying to use below code to see if pod came up or not. Should i create explicit API path like /healthz in my application so that kubernetes pings it and gets 200 status back or else its internal url for kubernetes?

specs:
   containers:
   - name: liveness
     readinessProbe:
    httpGet:
      path: /healthz
      port: 80
Hacker
  • 7,798
  • 19
  • 84
  • 154
  • Hi, yea application needs to tell kubelt that its healthy, so these endpoints are one of the way. or you can use tcp probe or script execution in the container. – Suresh Vishnoi Apr 18 '19 at 08:14

2 Answers2

4

As@Thomas answered the Http probe, If application does not provide a endpoint to validate the success response. you can use TCP Probe

kubelet tries to establish a TCP connection on the container's port. If it can establish a connection, the container is considered healthy; if it can’t it is considered unhealthy

for example, in your case it would be like this

    ports:
    - containerPort: 80
    readinessProbe:
      tcpSocket:
        port: 80
      initialDelaySeconds: 5
      periodSeconds: 10
    livenessProbe:
      tcpSocket:
        port: 80
      initialDelaySeconds: 15
      periodSeconds: 20

You can get further information over here configure-liveness-readiness-probes/

Suresh Vishnoi
  • 17,341
  • 8
  • 47
  • 55
  • Is livenessProbe mandatory? If i don't provide it, wont my pod get recreated when pod dies?] – Hacker Apr 18 '19 at 08:30
  • 1
    You should be aware, that if your application takes time to initialize, but the tcp probe already gets an open port, you might end up routing production traffic to an application pod that is not finished initializing. If you are providing an HTTP API I strongly suggest to use the http probe for that use case. – Thomas Apr 18 '19 at 08:35
  • I agree with thomas, use tcp probe unless and untill you do not have possibility to have http probe or it's a non-http application such as grpc based or ftp – Suresh Vishnoi Apr 18 '19 at 08:47
3

Kubernetes will make a request to the container on port 80 and path /healthz and expects a status code in the range of 2xx-3xx to be considered successful. If your application does not provide a mapping for the path and returns a 404, kubernetes assumes that the health check fails. Depending on your application you need to manually provide the API, if it is not done by your framework. (You can check using a curl or wget to the path from another pod and verify the result)

Thomas
  • 11,272
  • 2
  • 24
  • 40