0

I've got a simple question but I can't find out the right answer.

I have a couple of pods runnig my applications in python in kubernetes. I didn't implement liveness and readiness yet. When I was talking to my leader, he told me that I had to create the liveness and readiness for check and restart my pods when necessary and I had to find a way to make the liveness and readiness check if the python is also running because it could get stuck and the container could show that's everything fine.

I'v got confused because for my liveness and readiness would do this. I must create it using command, as this microservices doesn't have endpoint or healthcheck as they are just workers.

Any clue for how can I do that? Or a good answer that can explain that liveness and readiness check whether the python is running or not.

Thanks a lot!

Arthur Ávila
  • 69
  • 2
  • 9
  • What do you mean with ` python is also running because it could get stuck and the container could show that's everything fine.` ? About readiness and liveness the k8s [documentation](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-command) has good examples of how configure it. – Mr.KoopaKiller Oct 13 '20 at 13:23
  • I mean, does the liveness check if just if the pod is runnig or it check if python is running too? My leader told me that in some cases, the python can get stuck and the pod maybe running well and the liveness won't know if python is running or not. Is that possible or liveness would check the python and my pod? – Arthur Ávila Oct 13 '20 at 17:48

1 Answers1

1

Readiness won't restart your pod, it'll just make your worker not reachable through a load balancer/service, Liveness will do restart if the condition failed. You don't need to have liveness run through an endpoint, you can make sure that it's just reachable:

        livenessProbe:
          failureThreshold: 3
          initialDelaySeconds: 30
          periodSeconds: 20
          successThreshold: 1
          tcpSocket:
            port: <port-number>
          timeoutSeconds: 5

You can expose a port on the running python worker and just make sure that it's reachable, otherwise, think logically about when you do want to restart the pod? what do you mean by it could get stuck

islamhamdi
  • 207
  • 2
  • 8
  • I mean that the liveness with restart the pod whether if get stuck, right? My leader told me that the python running in a container can get stuck and maybe the pod can still showing to the liveness that is everything fine. – Arthur Ávila Oct 14 '20 at 02:23
  • You need then to add your own logical instrumentation that detects "when python is stuck", i.e: livenessProbe can be other things than `tcpSocket` for instance it can be an http request to an endpoint in your service where you specify the logic you want in this endpoint, e.g: check that you can connect to a DB, otherwise fail. Http: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-http-request You'll find there `exec command` as well. – islamhamdi Oct 20 '20 at 12:40
  • Great! Thanks for that! – Arthur Ávila Oct 21 '20 at 13:25