GSP-330: Implement DevOps in Google Cloud

GSP-330: Implement DevOps in Google Cloud

Overview

 1gcloud config set compute/zone us-east1-b
 2
 3git clone https://source.developers.google.com/p/$DEVSHELL_PROJECT_ID/r/sample-app
 4
 5gcloud container clusters get-credentials jenkins-cd
 6
 7kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user=$(gcloud config get-value account)
 8
 9helm repo add stable https://kubernetes-charts.storage.googleapis.com/  → this might not work… use the next line of code instead…
10
11helm repo add stable https://charts.helm.sh/stable
12
13helm repo update
14
15helm install cd stable/jenkins
16
17kubectl get pods
18
19export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/component=jenkins-master" -l "app.kubernetes.io/instance=cd" -o jsonpath="{.items[0].metadata.name}")
20kubectl port-forward $POD_NAME 8080:8080 >> /dev/null &
21printf $(kubectl get secret cd-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
1cd sample-app
2kubectl create ns production
3kubectl apply -f k8s/production -n production
4kubectl apply -f k8s/canary -n production
5kubectl apply -f k8s/services -n production
6
7kubectl get svc
8kubectl get service gceme-frontend -n production

Branch Sources: Git

click Periodically if not...... 1 min

1git init
2git config credential.helper gcloud.sh
3git remote add origin https://source.developers.google.com/p/$DEVSHELL_PROJECT_ID/r/sample-app
4git config --global user.email "<user email>"
5git config --global user.name "<user name>"
6git add .
7git commit -m "initial commit"
8git push origin master

Now save your work.

 1git checkout -b new-feature
 2
 3git add Jenkinsfile html.go main.go
 4git commit -m "Version 2.0.0"
 5git push origin new-feature
 6
 7curl http://localhost:8001/api/v1/namespaces/new-feature/services/gceme-frontend:80/proxy/version
 8kubectl get service gceme-frontend -n production
 9git checkout -b canary
10git push origin canary
11export FRONTEND_SERVICE_IP=$(kubectl get -o \
12jsonpath="{.status.loadBalancer.ingress[0].ip}" --namespace=production services gceme-frontend)
13git checkout master
14git push origin master
15
16
17export FRONTEND_SERVICE_IP=$(kubectl get -o \
18jsonpath="{.status.loadBalancer.ingress[0].ip}" --namespace=production services gceme-frontend)
19while true; do curl http://$FRONTEND_SERVICE_IP/version; sleep 1; done
20
21kubectl get service gceme-frontend -n production
22
23git merge canary
24git push origin master
25export FRONTEND_SERVICE_IP=$(kubectl get -o \
26jsonpath="{.status.loadBalancer.ingress[0].ip}" --namespace=production services gceme-frontend)

Congratulations, you're all done with the lab 😄