Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes Rolling Updates: Respect pod readiness before updating

Tags:

kubernetes

My deployment's pods are doing work that should not be interrupted. Is it possible that K8s is polling an endpoint about update readiness, or inform my pod that it is about to go down so it can get its affairs in order and then declare itself ready for an update?

Ideal process:

  1. An updated pod is ready to replace an old one
  2. A request is sent to the old pod by k8s, telling it that it is about to be updated
  3. Old pod gets polled about update readiness
  4. Old pod gets its affairs in order (e.g. stop receiving new tasks, finishes existing tasks)
  5. Old pod says it is ready
  6. Old pod gets replaced
like image 556
Kosmas Papadatos Avatar asked Nov 20 '25 10:11

Kosmas Papadatos


1 Answers

You could perhaps look into using container lifecycle hooks - specifically prestop in this case.

apiVersion: v1
kind: Pod
metadata:
  name: your-pod
spec:
  containers:
  - name: your-awesome-image
    image: image-name
    lifecycle:
      postStart:
        exec:
          command: ["/bin/sh", "my-app", "-start"]
      preStop:
        exec:
          # specifically by adding the cmd you want your image to run here
          command: ["/bin/sh","my-app","-stop"]
like image 74
syllabix Avatar answered Nov 23 '25 02:11

syllabix