@@ -14,10 +14,6 @@ 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-
19- Note: It is fine to use a single VM as Machine 1 and Machine 2. It is up to you.
20-
2117
2218A] Setup your developer workspace/Machine 1:
2319--------------------------------------------
@@ -26,7 +22,7 @@ A] Setup your developer workspace/Machine 1:
2622 - curl https://sdk.cloud.google.com | bash
2723 - log out and log back in
2824
29- 2) Configure authentication for gcloud CLI
25+ 2) Configure authentication for gcloud CLI. We need this step to create Google Cloud SQL instance and static IP.
3026 - gcloud auth login --> Follow the prompts (you will have to open browser window and paste the generated link,
3127 then paste the generated code in the verification field in your console.)
3228 - Create Project in Google Cloud Console --> Note down the Project ID. Remember that Project ID is different than the Project's Name.
@@ -50,12 +46,15 @@ A] Setup your developer workspace/Machine 1:
50465) Create a static IP address for our application
5147 - gcloud compute addresses create greetings-ip --global
5248
53- 6) Create your Bitbucket repository named "assignment6"
49+ 6) Create GKE cluster
50+ - gcloud container clusters create --machine-type=g1-small --num-nodes=1 testcluster1
51+
52+
53+ 7) Create your Bitbucket repository named "assignment4"
5454 - Make it Public
5555 - Generate a SSH Key pair for your developer workspace VM
5656 and add it to your Bitbucket account
5757 - Account -> Settings -> Add Key
58- - You can either generate an SSH key or add an existing key if you have one
5958 - ssh-keygen
6059 - It is fine if you provide an empty passphrase
6160 - more ~/.ssh/id_rsa.pub
@@ -64,22 +63,20 @@ A] Setup your developer workspace/Machine 1:
6463 The pasting operation will unevenly break the key into multiple lines. Find such lines
6564 and remove any extra spaces by hitting the Backspace key.
6665
67- 7 ) Download Sample CI/CD project
66+ 8 ) Download Sample CI/CD project
6867 - git clone https://github.com/devdattakulkarni/CloudComputing
6968 - cd CloudComputing/CICD/greetings
7069 - Edit greetings-deployment.yaml and set the environment variables corresponding to
7170 the Google Cloud SQL instance
7271 (Note: In the image tag don't include any version.
73- i.e.: Define your image tag as: "gcr.io/<project-id>/greetings" and NOT as
72+ i.e.: Define your image tag as: "gcr.io/<project-id>/greetings:latest " and NOT as
7473 "gcr.io/<project-id>/greetings:v1")
7574
7675 - Add a remote for your Bitbucket repository and Push the sample CI/CD project to that remote
7776 - cd ../../
7877 - git remote add origin1 git@bitbucket.org:<your-bitbucket-username>/assignment6.git
7978 - git push origin1 master
8079
81- 8) Create GKE cluster
82- - gcloud container clusters create --machine-type=g1-small --num-nodes=1 testcluster1
8380
8481
8582B] Setup your Jenkins Server/Machine 2:
@@ -90,19 +87,20 @@ B] Setup your Jenkins Server/Machine 2:
9087 - sudo apt-add-repository ppa:openjdk-r/ppa
9188 - sudo apt-get update
9289 - sudo apt-get install -y openjdk-8-jre openjdk-8-jdk wget
93- - Install Google Cloud CLI
90+ - Install Google Cloud CLI (this is needed for Jenkins Server to authenticate to GCP)
9491 - sudo apt-get install python
9592 - curl https://sdk.cloud.google.com | bash
96- - Install Docker
93+ - Install Docker (this is needed for Jenkins Server to build container image)
9794 - git clone https://github.com/devdattakulkarni/CloudComputing.git
9895 - cd CloudComputing/Containers/Kubernetes-examples/GCP/
9996 - ./install-docker-ubuntu.sh
10097 - Exit from Cloud VM instance
10198 - SSH back into Cloud VM instance
102- - Install Kubectl
99+ - Install Kubectl (this is needed for Jenkins Server to deploy to GKE)
103100 - gcloud components install kubectl
104101
105102 - Generate a SSH Key pair for the Jenkins Server and add it to your Bitbucket account
103+ (this is needed so that Jenkins Server can clone your github repo)
106104 - Account -> Settings -> Add Key
107105 - You can either generate an SSH key or add an existing key if you have one
108106 - ssh-keygen
@@ -113,6 +111,13 @@ B] Setup your Jenkins Server/Machine 2:
113111 The pasting operation will unevenly break the key into multiple lines. Find such lines
114112 and remove any extra spaces by hitting the Backspace key.
115113
114+ - Workaround (If running into SSH host key verification issues, you can disable it as follows):
115+ - Disable Host key verification:
116+ - create .ssh/config file
117+ - Include following lines in it:
118+ Host *
119+ StrictHostKeyChecking no
120+
1161212) Configure authentication for gcloud CLI
117122 - gcloud auth login --> Follow the prompts (you will have to open browser window and paste the generated link,
118123 then paste the generated code in the verification field in your console.)
@@ -122,43 +127,42 @@ B] Setup your Jenkins Server/Machine 2:
122127 - export CLOUDSDK_COMPUTE_ZONE=us-central1-b
123128 - gcloud config set project ${PROJECT_ID}
124129
125- 3) Disable Host key verification:
126- - create .ssh/config file
127- - Include following lines in it:
128- Host *
129- StrictHostKeyChecking no
130130
131- 4 ) Download and Start Jenkins Server:
131+ 3 ) Download and Start Jenkins Server:
132132 - wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war
133133 - nohup java -jar jenkins.war --httpPort=8080 &
134+ -> This will start Jenkins process on port 8080
134135
135- 5 ) Configure Jenkins Server
136+ 4 ) Configure Jenkins Server
136137 - Point your browser to the DNS name of the Jenkins Server at port 8080
137138 https://<DNS-of-Jenkins-Server>:8080/
138139 - Enter admin password from $HOME/.jenkins/secrets/initialAdminPassword
139140 - Choose Install suggested plugins option
140141
141- 6 ) Once Jenkins starts up do following:
142- 4 .1) Login as admin user
142+ 5 ) Once Jenkins starts up do following:
143+ 5 .1) Login as admin user
143144 - Password is stored in: $HOME/.jenkins/secrets/initialAdminPassword
144- 4 .2) Set the path in Jenkins for Git
145+ 5 .2) Set the path in Jenkins for Git
145146 Jenkins -> Manage Jenkins -> Configure System -> Global Properties
146147 - Check Tool Locations
147148 - List of tool locations -> Add
148149 - Set the path of Git from your VM
149150 (You can find the path by running 'which git' on VM)
150151 - Save
151- 4 .3) Install the Post build task Plugin and Bitbucket Plugin
152+ 5 .3) Install the Post build task Plugin and Bitbucket Plugin
152153 Jenkins -> Manage Jenkins -> Manage Plugins
153154 - In Available tab, search "Post build task" and select
154155 - In Available tab, search "Bitbucket" and select
155156 (Note: There are several Bitbucket plugins -- you want to choose whose
156157 name contains only the word "Bitbucket" and nothing else)
157158 - Choose Install without restarting option
159+ - Bitbucket plugin will be used to clone Bitbucket repo
160+ - Post build task plugin will be used to perform build and deploy tasks
161+
158162
163+ C] Add a WebHook to your Bitbucket repository
159164
160- 7) Add a WebHook to your Bitbucket repository
161- 5.1) Go to your Bitbucket repository -> Settings -> Webhooks -> Add webhook
165+ 1) Go to your Bitbucket repository -> Settings -> Webhooks -> Add webhook
162166 - http://<DNS-of-Jenkins-server>:8080/bitbucket-hook/
163167 (Note: The trailing slash '/' is important. Don't forget that!!)
164168 - Make Status as "Active"
@@ -168,30 +172,30 @@ B] Setup your Jenkins Server/Machine 2:
168172 - Repository->Push, Pull Request->Created, Updated, Comment created, Comment updated, Comment deleted
169173 Issue->Created, Issue->Updated, Issue->Comment Created
170174
171- 8 ) Set up a Jenkins Job
172- 6 .1) Make sure your Bitbucket repository ("assignment6 ") is Public
175+ 2 ) Set up a Jenkins Job on Jenkins VM
176+ 2 .1) Make sure your Bitbucket repository ("assignment4 ") is Public
173177 - This will make it possible to be cloned by Jenkins.
174- 6 .2) Jenkins -> New Item -> Give name -> Select Freestyle project
178+ 2 .2) Jenkins -> New Item -> Give name -> Select Freestyle project
175179 -> Source Code Management -> Git -> Give Bitbucket Repository URL (using git protocol)
176- (e.g.: git@bitbucket.org:devdattakulkarni/assignment6 .git)
180+ (e.g.: git@bitbucket.org:devdattakulkarni/assignment4 .git)
177181 -> Leave Branches to build as empty
178- 6 .3) Build Triggers
182+ 2 .3) Build Triggers
179183 -> Choose "Build when a change is pushed to BitBucket"
180- 6 .4) Buid Section -> Add a build step -> Execute Shell script
184+ 2 .4) Buid Section -> Add a build step -> Execute Shell script
181185 -> In the Execute shell Command section:
182186 - Add contents of build-steps.txt
183187 - Notes:
184188 - First modify build-steps.txt to use your GCP Project ID
185189 - Make sure that the image tag that use here is what you defined
186190 in deployment.yaml (Part A, step 7)
187- 6 .5) In Post-build Actions
191+ 2 .5) In Post-build Actions
188192 -> Add post-build action -> Post build task
189193 -> Log text "SUCCESS" -> Operation "-- OR --"
190194 -> In the Tasks -> Script section:
191195 - Add contents of deploy-steps.txt (modify the steps as required)
192- 6 .6) Save
196+ 2 .6) Save
193197
194- 6 .7) Bitbucket host key verification
198+ 2 .7) Bitbucket host key verification
195199
196200 Once you hit 'Save', you will see a prompt to verify the key for bitbucket server.
197201 This indicates that Jenkins has received the web hook and wants to clone your repository.
@@ -209,7 +213,7 @@ CI/CD Experiment:
209213 - git commit
210214 - git push origin1 master
211215
212- 3) ( If Part B step 6 .7 was not executed for some reason) On the Jenkins machine,
216+ 3) If Part C step 2 .7 was not executed for some reason, on the Jenkins server,
213217 you should see a prompt to verify the key for bitbucket server.
214218 This indicates that Jenkins has received the web hook and wants to clone your repository.
215219 In order to clone the repo, it needs to first verify the host key. Enter 'yes' to accept
@@ -236,7 +240,7 @@ CI/CD Experiment:
236240Kubernetes YAML files:
237241----------------------
2382421) greetings-deployment.yaml
239- -> Environment variables need to be set with Google Cloud SQL instance details
243+ -> Environment variables need to be set with appropriate Google Cloud SQL instance details
240244
2412452) greetings-ingress.yaml
242246 -> Contains configuration for the Global IP address that we create in Part A step 5
0 commit comments