How to create deployments with more than one pod?

4/5/2019

I'm hosting an application on the Google Cloud Platform via Kubernetes, and I've managed to set up this continuous deployment pipeline:

  1. Application code is updated
  2. New Docker image is automatically generated
  3. K8s Deployment is automatically updated to use the new image

This works great, except for one issue - the deployment always seems to have only one pod. Because of this, when the next update cycle comes around, the entire application goes down, which is unacceptable.

I've tried modifying the YAML of the deployment to increase the number of replicas, and it works... until the next image update, where it gets reset back to one pod again.

This is the command I use to update the image deployment:

set image deployment foo-server gcp-cd-foo-server-sha256=gcr.io/project-name/gcp-cd-foo-server:$REVISION_ID
-- Artem Zakharov
google-cloud-platform
kubernetes

3 Answers

4/5/2019

In your orgional deployment.yml file keep the replicas to 2 or more, othervise you cant avoid down time if only one pod is running and you are going to re-deploy/upgrade etc.

Deployment with 3 replicas( example):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80

Deployment can ensure that only a certain number of Pods may be down while they are being updated. By default, it ensures that at least 25% less than the desired number of Pods are up (25% max unavailable).

Deployment can also ensure that only a certain number of Pods may be created above the desired number of Pods. By default, it ensures that at most 25% more than the desired number of Pods are up (25% max surge).

https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

-- Ijaz Ahmad Khan
Source: StackOverflow

4/6/2019

Nevermind, I had just set up my deployments wrong - had something to do with using the GCP user interface to create the deployments rather than console commands. I created the deployments with kubectl run app --image ... instead and it works now.

-- Artem Zakharov
Source: StackOverflow

4/5/2019

You can use this command if you dont want to edit deployment yaml file:

kubectl scale deployment foo-server --replicas=2

Also, look at update strategy with maxUnavailable and maxsurge properties.

-- Prateek Jain
Source: StackOverflow