Skip to content

Instantly share code, notes, and snippets.

@aojea
Created April 3, 2023 11:50
Show Gist options
  • Save aojea/84fc66fde269f8aef1a4932d074285db to your computer and use it in GitHub Desktop.
Save aojea/84fc66fde269f8aef1a4932d074285db to your computer and use it in GitHub Desktop.
zero downtime deployment rolling update
  1. Create the deployment and expose it using a Load Balancer
 kubectl apply -f demo.yaml
  1. Wait for the LoadBalancer
$ kubectl get services lb-service --watch
NAME         TYPE           CLUSTER-IP    EXTERNAL-IP     PORT(S)        AGE
lb-service   LoadBalancer   10.76.7.155   35.205.231.57   80:30526/TCP   10m
  1. Poll the application constantly
$ while true; do curl 35.205.231.57/hostname; echo ; sleep 1; done

server-deployment-8c8d64764-jsmsm
server-deployment-8c8d64764-jsmsm
server-deployment-8c8d64764-sggwl
server-deployment-8c8d64764-jsmsm
server-deployment-8c8d64764-sggwl
  1. Update the deployment image and observe how the pods names change without any disruption
kubectl set image deployment/server-deployment agnhost=k8s.gcr.io/e2e-test-images/agnhost:2.40
apiVersion: apps/v1
kind: Deployment
metadata:
name: server-deployment
labels:
app: MyApp
spec:
replicas: 2
selector:
matchLabels:
app: MyApp
template:
metadata:
labels:
app: MyApp
spec:
terminationGracePeriodSeconds: 30
containers:
- name: agnhost
image: k8s.gcr.io/e2e-test-images/agnhost:2.39
args:
- netexec
- --http-port=80
- --delay-shutdown=30
---
apiVersion: v1
kind: Service
metadata:
name: lb-service
spec:
type: LoadBalancer
externalTrafficPolicy: Local
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment