Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example code for blog post "Speed Limits for Rolling Restarts in Kubernetes"
https://alexklibisz.com/2021/07/20/speed-limits-for-rolling-updates-in-kubernetes.html
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
readinessProbe:
httpGet:
path: /
port: 80
livenessProbe:
httpGet:
path: /
port: 80
replicas: 4
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
readinessProbe:
httpGet:
path: /
port: 80
livenessProbe:
httpGet:
path: /
port: 80
replicas: 4
strategy:
rollingUpdate:
maxUnavailable: 0 # New!
maxSurge: 1 # New!
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
readinessProbe:
httpGet:
path: /
port: 80
livenessProbe:
httpGet:
path: /
port: 80
replicas: 4
strategy:
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
minReadySeconds: 3 # New!
#!/bin/bash
set -e
echo "Deleting existing deployments..."
kubectl delete deployment --wait=true --all
kubectl delete replicaset --wait=true --all
echo "Creating new deployment..."
kubectl apply -f $1
echo "Waiting for deployment to be available..."
kubectl rollout status --watch deployment/nginx
kubectl wait --for=condition=available --timeout=5s deployment/nginx
echo "Restarting the deployment..."
kubectl get replicaset
kubectl rollout restart deployment/nginx &> /dev/null
while true
do
echo "---"
kubectl rollout status deployment/nginx --timeout=1s &> /dev/null && break || true
kubectl get replicaset | tail -n +2
done
kubectl get replicaset | tail -n +2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment