Delay kubernetes pod creation for zero downtime

10/29/2018

I am trying to implement the Rolling update of deployments in Kubernetes. I have followed a lot of articles that say that there would be zero downtime but when I run curl continuously. A couple of my requests failed before getting a response back. Below is the deployment file.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: myapp-deployment
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp-container
        image: my-image
        imagePullPolicy: Always
        ports:
          - containerPort: 80
            protocol: TCP
        readinessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 5
          successThreshold: 1

The next thing I did was added

MinReadySeconds: 120

This takes care of this issue but it is not an optimum solution since we want to switch to the next pod as soon as it starts servicing requests and kill the old pod. I have two questions -

  1. Can there be a condition when both the pods - the new and the old are running and both start servicing the traffic? That would also not be ideal as well. Since we want only one pod to service the request at a time.
  2. Is there any other out of the box solution that Kubernetes provides to do a rolling deployment?
-- Anshul Tripathi
kubectl
kubernetes
kubernetes-deployment

1 Answer

10/29/2018

Try this. this should work for you . try doing a update of your image.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: myapp-deployment
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp-container
        image: nginx
        imagePullPolicy: Always
        ports:
          - containerPort: 80
            protocol: TCP
        readinessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 5
          successThreshold: 1

For your better understanding check this link

-- Shashank Pai
Source: StackOverflow