Kubernetes 0 Downtime using Readiness Probe and RollBack strategy not working

12/7/2018

I have set up a Node app on Kubernetes. I'm running a single replica and I want 0 down-time when the image is updated. I update my Pod using set Image on Kubernetes.

'set', 'image', 'deployment/dev-web'

Here's my YAML file

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "2"
  generation: 2
  labels:
    io.kompose.service: dev-web
  name: dev-web
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: dev-web
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: dev-web
    spec:
      containers:
      - env:
        image: gcr.io/my-project-link/my-image-link
        imagePullPolicy: Always
        name: dev-web-container
        ports:
        - containerPort: 2000
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            port: 2000
            scheme: HTTP
          initialDelaySeconds: 5
          periodSeconds: 5
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          requests:
            cpu: 20m
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  availableReplicas: 1
  conditions:
  - lastTransitionTime: 2018-12-07T11:13:21Z
    lastUpdateTime: 2018-12-07T11:13:21Z
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
  observedGeneration: 2
  readyReplicas: 1
  replicas: 1
  updatedReplicas: 1

My app does give 200 response on '/' get therefore Readiness Probe works but when I update the Image, and test it but continuously hitting CURL, it gives me downtime which lasts for like 20-40 seconds.

-- Alamgir Qazi
kubectl
kubernetes

1 Answer

12/7/2018

You setup your maxUnavailable as 1 even when you have only one replica, you should be having maxUnavailable to 0.

strategy:
 type: RollingUpdate
 rollingUpdate:
   maxUnavailable: 0
   maxSurge: 1

It basically tells Kubernetes that there should be zero unavailable pods while deploying (maxUnavailable: 0) and there should be one new pod at a time (maxSurge: 1).

I am hoping you setup the readiness probe something like this:

readinessProbe:
  httpGet:
    path: /
    port: 80
  initialDelaySeconds: 5
  periodSeconds: 5
  successThreshold: 1

Basically, this is a check that Kubernetes does in order to make sure that your pod is ready to send traffic to it. Until it is not ready, Kubernetes will not use your pod.

-- Prafull Ladha
Source: StackOverflow