Kubernetes Rolling Updates: Respect pod readiness before updating

3/24/2019

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
-- Kosmas Papadatos
kubernetes

1 Answer

3/24/2019

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"]
-- syllabix
Source: StackOverflow