@@ -14,6 +14,8 @@ Machine 2 *has* to be a cloud VM (such as a EC2 instance).
1414Feel free to choose either a EC2 instance or Google Compute Engine instance
1515Make sure you allow TCP traffic to port 8080 on your VM instance.
1616
17+ If using EC2, create a Free tier Ubuntu 16.04 VM
18+
1719Note: It is fine to use a single VM as Machine 1 and Machine 2. It is up to you.
1820
1921
@@ -22,6 +24,7 @@ A] Setup your developer workspace/Machine 1:
22241) Install Google Cloud CLI
2325 - sudo apt-get install python
2426 - curl https://sdk.cloud.google.com | bash
27+ - log out and log back in
2528
26292) Configure authentication for gcloud CLI
2730 - gcloud auth login --> Follow the prompts (you will have to open browser window and paste the generated link,
@@ -36,20 +39,30 @@ A] Setup your developer workspace/Machine 1:
3639 - gcloud sql instances create instance1 --tier=db-f1-micro --authorized-networks=0.0.0.0/0
3740
38414) Create testdb database on the Cloud SQL instance
39- - gcloud sql users set-password root % --instance instance1 --password 'testpass123!@#'
40- - sudo apt-get install mysql-client
4142 - gcloud sql instances list
42- - mysql -h <IP-address-of-SQL-Instance> --user=root --password='testpass123!@#'
43- - mysql>create database testdb;
43+ - Once the Cloud SQL instance is in 'RUNNABLE' state, do following steps:
44+ - gcloud sql users set-password root % --instance instance1 --password 'testpass123!@#'
45+ - sudo apt-get install mysql-client
46+ - mysql -h <IP-address-of-SQL-Instance> --user=root --password='testpass123!@#'
47+ - mysql>create database testdb;
48+ - mysql>quit;
4449
45505) Create a static IP address for our application
4651 - gcloud compute addresses create greetings-ip --global
4752
48536) Create your Bitbucket repository named "assignment6"
4954 - Make it Public
50- - Generate a SSH Key pair and add it to your Bitbucket account
55+ - Generate a SSH Key pair for your developer workspace VM
56+ and add it to your Bitbucket account
5157 - Account -> Settings -> Add Key
5258 - You can either generate an SSH key or add an existing key if you have one
59+ - ssh-keygen
60+ - It is fine if you provide an empty passphrase
61+ - more ~/.ssh/id_rsa.pub
62+ - Copy the key and paste it in the "Add Key" box in Bitbucket.
63+ - When you paste the key, make sure that there are no extra spaces between the characters.
64+ The pasting operation will unevenly break the key into multiple lines. Find such lines
65+ and remove any extra spaces by hitting the Backspace key.
5366
54677) Download Sample CI/CD project
5568 - git clone https://github.com/devdattakulkarni/CloudComputing
@@ -65,6 +78,8 @@ A] Setup your developer workspace/Machine 1:
6578 - git remote add origin1 git@bitbucket.org:<your-bitbucket-username>/assignment6.git
6679 - git push origin1 master
6780
81+ 8) Create GKE cluster
82+ - gcloud container clusters create --machine-type=g1-small --num-nodes=1 testcluster1
6883
6984
7085B] Setup your Jenkins Server/Machine 2:
@@ -73,18 +88,32 @@ B] Setup your Jenkins Server/Machine 2:
7388 - Login to your Cloud VM instance (Machine2)
7489 - Install Java (JRE and JDK)
7590 - sudo apt-add-repository ppa:openjdk-r/ppa
91+ - sudo apt-get update
7692 - sudo apt-get install -y openjdk-8-jre openjdk-8-jdk wget
7793 - Install Google Cloud CLI
7894 - sudo apt-get install python
7995 - curl https://sdk.cloud.google.com | bash
80- - Install Kubectl
81- - gcloud components install kubectl
8296 - Install Docker
8397 - git clone https://github.com/devdattakulkarni/CloudComputing.git
84- - cd Containers/Kubernetes-examples/GCP/
98+ - cd CloudComputing/ Containers/Kubernetes-examples/GCP/
8599 - ./install-docker-ubuntu.sh
86- - exit from Cloud VM instance
100+ - Exit from Cloud VM instance
87101 - SSH back into Cloud VM instance
102+ - Install Kubectl
103+ - gcloud components install kubectl
104+
105+ - Generate a SSH Key pair for the Jenkins Server and add it to your Bitbucket account
106+ - Account -> Settings -> Add Key
107+ - You can either generate an SSH key or add an existing key if you have one
108+ - ssh-keygen
109+ - It is fine if you provide an empty passphrase
110+ - more ~/.ssh/id_rsa.pub
111+ - Copy the key and paste it in the "Add Key" box in Bitbucket.
112+ - When you paste the key, make sure that there are no extra spaces between the characters.
113+ The pasting operation will unevenly break the key into multiple lines. Find such lines
114+ and remove any extra spaces by hitting the Backspace key.
115+
116+
88117
891182) Download and Start Jenkins Server:
90119 - wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war
@@ -93,25 +122,30 @@ B] Setup your Jenkins Server/Machine 2:
931223) Configure Jenkins Server
94123 - Point your browser to the DNS name of the Jenkins Server at port 8080
95124 https://<DNS-of-Jenkins-Server>:8080/
96- - Keep the user as 'admin'
97- - Install recommended plugins
125+ - Enter admin password from $HOME/.jenkins/secrets/initialAdminPassword
126+ - Choose Install suggested plugins option
98127
991284) Once Jenkins starts up do following:
100129 4.1) Login as admin user
101130 - Password is stored in: $HOME/.jenkins/secrets/initialAdminPassword
102131 4.2) Set the path in Jenkins for Git
103- Jenkins -> Manage Jenkins -> Configure -> Global Properties
132+ Jenkins -> Manage Jenkins -> Configure System -> Global Properties
104133 - Check Tool Locations
105- - List of tool locations (Choose Git)
134+ - List of tool locations -> Add
106135 - Set the path of Git from your VM
107136 (You can find the path by running 'which git' on VM)
108- 4.3) Install the Post build task Plugin
109- Jenkins -> Manage Jenkins -> Manage Plugins -> Post build task plugin
110- 4.4) Install Bitbucket Plugin
111- Jenkins -> Manage Jenkins -> Manage Plugins -> Bitbucket
137+ - Save
138+ 4.3) Install the Post build task Plugin and Bitbucket Plugin
139+ Jenkins -> Manage Jenkins -> Manage Plugins
140+ - In Available tab, search "Post build task" and select
141+ - In Available tab, search "Bitbucket" and select
142+ (Note: There are several Bitbucket plugins -- you want to choose whose
143+ name contains only the word "Bitbucket" and nothing else)
144+ - Choose Install without restarting option
145+
112146
1131475) Add a WebHook to your Bitbucket repository
114- 5.1) Go to your Bitbucket repository -> Settings -> URL. E
148+ 5.1) Go to your Bitbucket repository -> Settings -> Webhooks -> Add webhook
115149 - http://<DNS-of-Jenkins-server>:8080/bitbucket-hook/
116150 (Note: The trailing slash '/' is important. Don't forget that!!)
117151 - Make Status as "Active"
@@ -125,20 +159,26 @@ B] Setup your Jenkins Server/Machine 2:
125159 6.1) Make sure your Bitbucket repository ("assignment6") is Public
126160 - This will make it possible to be cloned by Jenkins.
127161 6.2) Jenkins -> New Item -> Give name -> Select Freestyle project
128- -> Source Code Management -> Give Bitbucket Repository URL (in git)
162+ -> Source Code Management -> Git -> Give Bitbucket Repository URL (using git protocol)
163+ (e.g.: git@bitbucket.org:devdattakulkarni/assignment6.git)
164+ -> Leave Branches to build as empty
129165 6.3) Build Triggers
130166 -> Choose "Build when a change is pushed to BitBucket"
131- 6.4) Buid Section -> Choose Execute Shell script
167+ 6.4) Buid Section -> Add a build step -> Execute Shell script
132168 -> In the Execute shell Command section:
133169 - Add contents of build-steps.txt
134170 - Notes:
135171 - First modify build-steps.txt to use your GCP Project ID
136172 - Make sure that the image tag that use here is what you defined
137173 in deployment.yaml (Part A, step 7)
138174 6.5) In Post-build Actions
139- -> Tasks -> Log text "SUCCESS" -> Operation "-- OR --"
175+ -> Add post-build action -> Post build task
176+ -> Log text "SUCCESS" -> Operation "-- OR --"
140177 -> In the Tasks -> Script section:
141- - Add contents of deploy-steps.txt (modify the steps with your assignment's name)
178+ - Add contents of deploy-steps.txt (modify the steps as required)
179+ 6.6) Save
180+
181+
142182
143183
144184
@@ -159,11 +199,25 @@ CI/CD Experiment:
159199
1602004) On Machine 2 (Jenkins server):
161201 - kubectl get ingress
162- - Navigate to the IP address and verify that your changes
163- (Note: It may take 6/7 minutes before the ingress filtering routes will take effect
202+ - Check the AGE field. It usually takes 7/8 minutes before the changes are reflected
203+ on the Ingress IP address
204+ - Navigate to the IP address and verify that your changes are visible
205+ (Note: It may take 7/8 minutes before the ingress filtering routes will take effect
164206 and your changes are visible.)
165207
166- 5) Repeat steps 2-3-4
208+ 5) Repeat steps 2-3-4 with different changes to index.html
209+
210+
211+
212+
213+ Kubernetes YAML files:
214+ ----------------------
215+ 1) greetings-deployment.yaml
216+ -> Environment variables need to be set with Google Cloud SQL instance details
217+
218+ 2) greetings-ingress.yaml
219+ -> Contains configuration for the Global IP address that we create in Part A step 5
220+
167221
168222
169223
@@ -172,10 +226,9 @@ Clean up:
172226From Google Cloud Console:
173227- Delete Kubernetes Cluster
174228- Delete Google Cloud SQL Instance
175- - Delete the Static IP address
176-
177-
178229
230+ Delete the Static IP address using gcloud CLI:
231+ - gcloud compute addresses delete greetings-ip --global
179232
180233
181234
@@ -188,8 +241,10 @@ Troubleshooting:
188241 - Re-run Jenkins using the java command
189242
1902432) Jenkins URL location
244+ Jenkins -> Manage Jenkins -> Jenkins Location
191245
192- 3)
246+ 3) Jenkins workspace
247+ - On Jenkins Server at $HOME/.jenkins/workspace
193248
194249
195250
0 commit comments