-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathImplement DevOps in Google Cloud: Challenge Lab.txt
97 lines (63 loc) · 3.53 KB
/
Implement DevOps in Google Cloud: Challenge Lab.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---------------Task 1-----------------
gcloud auth list
gcloud config list project
gcloud config set compute/zone us-east1-b
git clone https://source.developers.google.com/p/$DEVSHELL_PROJECT_ID/r/sample-app
gcloud container clusters get-credentials jenkins-cd
kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user=$(gcloud config get-value account)
helm repo add stable https://charts.helm.sh/stable
helm repo update
helm install cd stable/jenkins
export 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}")
kubectl port-forward $POD_NAME 8080:8080 >> /dev/null &
printf $(kubectl get secret cd-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
cd sample-app
kubectl create ns production
kubectl apply -f k8s/production -n production
kubectl apply -f k8s/canary -n production
kubectl apply -f k8s/services -n production
kubectl get svc
kubectl get service gceme-frontend -n production
Now let's do jenkins part then we move forward
Open Jenkins --> Click on Jenkins Admin --> Credentials --> global --> adding some credentials --> Select Kind (Google Service Account From Metadata --> Select Project Name From Drop Down Menu --> Click OK
Go to Dashboard --> New Item --> Give name sample-app --> Select Multi Branch Pipeline --> Click Ok
Go to Add source and select Git --> Give Project Repository Link Given in lab (You can find it at bottm of the lab under section Tip 3) --> Change [Project ID] as per your account --> Select Credentials --> Scroll down & find "Periodically if not otherwise run" & Select 1 min --> Click Apply --> Click Save
Then run below Cpmmands in Cloud Shell
git init
git config credential.helper gcloud.sh
git remote add origin https://source.developers.google.com/p/$DEVSHELL_PROJECT_ID/r/sample-app
git config --global user.email "<user email>"
git config --global user.name "<user name>"
git add .
git commit -m "initial commit"
git push origin master
---------------Task 2------------------
git checkout -b new-feature
After this command make the required changes!
Firstly Open Editor then...
Edit the file main.go in the root folder of the repo and change the version number to Version .
const version string = "Version" (It's mentioned in your lab)
Edit the file html.go in the root folder of the repo and change both lines that contains the word blue to Colour .
<div class="card Colour"> (It's mentioned in your lab)
git add Jenkinsfile html.go main.go
git commit -m "Version 2.0.0"
git push origin new-feature
------------------Task 3------------------
curl http://localhost:8001/api/v1/namespaces/new-feature/services/gceme-frontend:80/proxy/version
kubectl get service gceme-frontend -n production
git checkout -b canary
git push origin canary
export FRONTEND_SERVICE_IP=$(kubectl get -o \
jsonpath="{.status.loadBalancer.ingress[0].ip}" --namespace=production services gceme-frontend)
git checkout master
git push origin master
----------------Task 4-------------------
export FRONTEND_SERVICE_IP=$(kubectl get -o \
jsonpath="{.status.loadBalancer.ingress[0].ip}" --namespace=production services gceme-frontend)
while true; do curl http://$FRONTEND_SERVICE_IP/version; sleep 1; done
kubectl get service gceme-frontend -n production
git merge canary
git push origin master
export FRONTEND_SERVICE_IP=$(kubectl get -o \
jsonpath="{.status.loadBalancer.ingress[0].ip}" --namespace=production services gceme-frontend)
----------------DONE-----------------------