Skip to content

Instantly share code, notes, and snippets.

@lsauer
Forked from joshy91/k8UpdateRollback.sh
Created October 2, 2020 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsauer/0907bafff6045f4d10744efe91349c33 to your computer and use it in GitHub Desktop.
Save lsauer/0907bafff6045f4d10744efe91349c33 to your computer and use it in GitHub Desktop.
Deployments, Rolling Update, Rollback
#!/bin/bash
#Deployments, Rolling Update, Rollback
#Nginx deployment yaml
echo “apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
namespace: default
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80” >> nginx-deployment.yaml
kubectl create -f nginx-deployment.yaml
#status of all deployments in default namespace
kubectl get deployments
#Detailed description of deployment
kubectl describe deployment nginx-deployment
#Generate yaml file based off deployment
kubectl get deployment nginx-deployment -o yaml
#Update nginx set image of deployment
kubectl set image deployment/nginx-deployment nginx=nginx:1.8
#Rollout deployment after the previous update
kubectl rollout status deployment/nginx-deployment
#Detailed description of deployment update
kubectl describe deployment nginx-deployment
#Change set image in nginx deployment yaml
sed -i 's/image: nginx:1.7.9/image: nginx:1.9.1/g' /home/user/nginx-deployment.yaml
#Apply changes to nginx deployment yaml
kubectl apply -f nginx-deployment.yaml
#Rollout deployment after the previous update
kubectl rollout status deployment/nginx-deployment
#Detailed description of deployment update
kubectl describe deployment nginx-deployment
#Show history of 3rd revision rollout of nginx deployment
kubectl rollout history deployment/nginx-deployment --revision=3
#Rollback deployment to 2nd revision
kubectl rollout undo deployment/nginx-deployment --to-revision=2
#Detailed description of deployment update
kubectl describe deployment nginx-deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment