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#
- 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/v1kind: Deploymentmetadata:creationTimestamp: nulllabels:app: q5-bluename: q5-bluespec:replicas: 1selector:matchLabels:app: q5-bluestrategy: {}template:metadata:creationTimestamp: nulllabels:app: q5-bluespec:containers:- image: paulbouwer/hello-kubernetes:1.5name: helloports:- containerPort: 8080resources: {}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: v1kind: Servicemetadata:creationTimestamp: nulllabels:app: q5-servicename: q5-servicespec:ports:- port: 80protocol: TCPtargetPort: 8080selector:app: q5-bluetype: LoadBalancerstatus: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/v1kind: Deploymentmetadata:creationTimestamp: nulllabels:app: q5-greenname: q5-greenspec:replicas: 1selector:matchLabels:app: q5-greenstrategy: {}template:metadata:creationTimestamp: nulllabels:app: q5-greenspec:containers:- image: paulbouwer/hello-kubernetes:1.5name: helloports:- containerPort: 8080resources: {}status: {}
swich the service to the green deployment by update and apply change to the q5_service.yaml
apiVersion: v1kind: Servicemetadata:creationTimestamp: nulllabels:app: q5-servicename: q5-servicespec:ports:- port: 80protocol: TCPtargetPort: 8080selector:app: q5-greentype: LoadBalancerstatus: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#
- 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/v1kind: Deploymentmetadata:creationTimestamp: nulllabels:tier: backendname: deployspec:replicas: 3selector:matchLabels:app: v1strategy: {}template:metadata:creationTimestamp: nulllabels:app: v1spec:containers:- image: nginxname: nginxresources: {}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#
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