Introduction#

this section shows some practices,

  • question 6 deployment blue/green
  • question 7 deployment and rollout
  • question 8 deployment canary
  • question 9 helm chart

Question 6 Blue/Green#

ckad question 3
  • create blue.yaml for blue deployment
  • create prod_service.yaml with blue backend
  • create test_service.yaml with blue backend
  • create green backend, and update test_service.yaml
  • switch prod_service.yaml to use green backend

create blue deployment

kubectl create deployment blue-deploy --image=paulbouwer/hello-kubernetes:1.5 --port=8080 --dry-run=client --output=yaml > q5_blue_deploy.yaml

then update the q5_blue_deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: q5-blue
name: q5-blue
spec:
replicas: 1
selector:
matchLabels:
app: q5-blue
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: q5-blue
spec:
containers:
- image: paulbouwer/hello-kubernetes:1.5
name: hello
ports:
- containerPort: 8080
resources: {}
status: {}

get the pod internal ip then take note it

kubect get pods --output=wide

shell into a temporary busybox to check it

kubect run test --image=busybox -it --rm --command -- /bin/sh

then check the service

wget -O- POD_IP:8080

expose blue backend as a service on port 80 using aws load balancer

kubectl create service q5-service --tcp=80:8080 --dry-run=client --output=yaml > q5_service.yaml

then update the q5_service.yaml as

apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: q5-service
name: q5-service
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: q5-blue
type: LoadBalancer
status:
loadBalancer: {}

get the load balancer endpoint which should be publicly accessible

kubect get service

then curl to the the endpoint, please wait a minut for the endpoint readly (aws classic load balancer behind it )

curl http://endpoint:80

now create the green deployment

apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: q5-green
name: q5-green
spec:
replicas: 1
selector:
matchLabels:
app: q5-green
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: q5-green
spec:
containers:
- image: paulbouwer/hello-kubernetes:1.5
name: hello
ports:
- containerPort: 8080
resources: {}
status: {}

swich the service to the green deployment by update and apply change to the q5_service.yaml

apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: q5-service
name: q5-service
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: q5-green
type: LoadBalancer
status:
loadBalancer: {}

apply changle

kubectl apply -f q5_service.yaml

open the http://endpoint and notice the pod change blue pod => green pod

Question 7 Rollout#

ckad question 3
  • create a deployment named with three replicas, pods should use image nginx and the name nginx, deployment uses label tier=backend, pod label app=v1
  • list deployment and ensure the correct number of replicas are running
  • update the image to nginx:latest, verify that the change has been rolled out to all replicas
  • scale the deployment to 5 replicas, have a look at the deployment rollout history
  • revert the deployment to revision 1, ensure the pods are running the image nginx

create a deployment

kubectl create deployment deploy --image=nginx --dry-run=client --output=yaml > q11.yaml

update the yaml with label for deployment and pod, replicas=3

apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
tier: backend
name: deploy
spec:
replicas: 3
selector:
matchLabels:
app: v1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: v1
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}

deploy or apply

kubectl create -f q11.yaml

list deployment

kubectl get deployments

update image nginx to nginx:latest for the deployments (deploy)

kubectl set image deployment/deploy nginx=nginx:latest

rollout history to see how many revision

kubectl rollout history

check one revision to confirm that nginx:latest is running

kubectl rollout history deployment/deploy --revision=2

double check

kubectl get deployment/deploy

scale the deploy replicas to 5

kubectl scale --replicas=5 -f q11.yaml

check the rollout history

kubectl rollout history deployment/deploy

revert to reversion 1

kubectl rollout undo deployment/deploy --revision=1

double check the nginx:nginx is running (not the latest)

kubectl rollout history deployment/deploy --revision=3

or

kubectl get describe pod PODNAME

Question 8 Canary#

(TODO)

Question 9 Helm Chart#

ckad question 3

step 1. install heml

step 2. initialize helm

helm repo add bitnami https://charts.bitnami.com/bitnami

check

helm search repo bitnami

step 3. install mysql by heml

helm install bitnami/mysql --generate-name

step 4. follow the guide from terminal to setup db credentials and access the mysql

step 5. uninstall the mysql

hel list to get the current installed version of mysql-xxx

heml list

then

heml uninstall mysql-xxx