forked from mschmidt712/kubernetes-ci-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
steps.yml
237 lines (160 loc) · 12.6 KB
/
steps.yml
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
parts:
- name: Part 1
intro: In this part we will setup a local cluster with minikube, deploy a public image from dockerhub, customize that image, and then finally deploy it inside our local cluster.
steps:
- cap: Start up the cluster with minikibe
com: minikube start --memory 8000 --cpus 2 --kubernetes-version v1.6.0
- cap: Enable addons
com: minikube addons enable heapster; minikube addons enable ingress
- cap: Wait 20 seconds and view minikube dashboard
com: sleep 20; minikube service kubernetes-dashboard --namespace kube-system
- cap: Deploy the public nginx image from DockerHub
com: kubectl run nginx --image nginx --port 80
- cap: Create a service for deployment
com: kubectl expose deployment nginx --type NodePort --port 80
- cap: Launch browser to test service
com: minikube service nginx
- cap: Install registry
com: kubectl apply -f manifests/registry.yml
- cap: Wait for registry to deploy
com: kubectl rollout status deployments/registry
- cap: View registry UI
com: minikube service registry-ui
- cap: Edit the contents of applications/hello-kenzan/index.html. This will open the file with the nano editor. When finished press ctrl + x to exit and confirm save.
com: nano applications/hello-kenzan/index.html
- cap: We will now build the image with a special name that is pointing at our cluster registry.
com: docker build -t 127.0.0.1:30400/hello-kenzan:latest -f applications/hello-kenzan/Dockerfile applications/hello-kenzan
- cap: Before we can push our image we need to set up a temporary proxy. This is a container that listens on 127.0.0.1:30400 and forwads to our cluster. By default the docker client can only push to non https via localhost.
com: docker stop socat-registry; docker rm socat-registry; docker run -d -e "REGIP=`minikube ip`" --name socat-registry -p 30400:5000 chadmoon/socat:latest bash -c "socat TCP4-LISTEN:5000,fork,reuseaddr TCP4:`minikube ip`:30400"
- cap: We can now push our image.
com: docker push 127.0.0.1:30400/hello-kenzan:latest
- cap: Stop the registry proxy.
com: docker stop socat-registry;
- cap: Now that our image is on the cluster we can deploy the manifests
com: kubectl apply -f applications/hello-kenzan/k8s/deployment.yaml
- cap: View the app
com: minikube service hello-kenzan
- name: Part 2
intro: In this part we will Setup Jenkins, and setup an automated jon to build, push and deploy our custom appliction.
steps:
- cap: Install Jenkins
com: kubectl apply -f manifests/jenkins.yml; kubectl rollout status deployment/jenkins
- cap: Open the Jenkins service running in our cluster. You will retrieve the admin password in the next step.
com: minikube service jenkins
- cap: Get Jenkins admin password with the following command.
com: kubectl exec -it `kubectl get pods --selector=app=jenkins --output=jsonpath={.items..metadata.name}` cat /root/.jenkins/secrets/initialAdminPassword
- cap: Enter the password above into the Jenkins page and choose to install the suggested plugins.
com: echo 'Enter the password above into the Jenkins page and choose to install the suggested plugins.'
- cap: Create an admin user when prompted in Jenkins (or click the skip link in the lower right).
com: echo 'Create an admin user when prompted in Jenkins (or click the skip link in the lower right).'
- cap: Click "New Item" and create an item with a name like "Hello-Kenzan Pipeline", choosing the type "Pipeline". Click OK.
com: echo 'Click "New Item" and create an item with a name like "Hello-Kenzan Pipeline", choosing the type "Pipeline". Click OK.'
- cap: From pipeline configuration, scroll down to Pipeline and change the Definition selection from "Pipeline script" to "Pipeline script from SCM".
com: echo 'From pipeline configuration, scroll down to Pipeline and change the Definition selection from "Pipeline script" to "Pipeline script from SCM".'
- cap: Set the SCM property to GIT.
com: echo 'Set the SCM property to GIT.'
- cap: Fork the kenzanlabs repository in github and set the "Repository URL" to your fork, such as https://github.com/kenzanlabs/kubernetes-ci-cd.git. Save and run the job.
com: echo 'Fork the kenzanlabs repository in github and set the "Repository URL" to your fork, such as https://github.com/kenzanlabs/kubernetes-ci-cd.git. Save and run the job.'
- cap: View updated application
com: minikube service hello-kenzan
- cap: Push a change to your fork. Run job again. View changes
com: minikube service hello-kenzan
- name: Part 3
intro: This part will have us setup the various applications that will present the crossword puzzle. We will run a sample etcd cluster as a cache, a pages application containing the front-end, a crossword server using mongodb, and a monitoring and scaling server application.
steps:
- cap: Bootstrap etcd operator on the cluster
com: scripts/etcd.sh
- cap: Run job to create etcd directory
com: kubectl create -f manifests/etcd-job.yml
- cap: Check job status
com: kubectl describe jobs/etcd-job
- cap: The crossword application is a multi-tier application and its services depend on each other. For our first step we will create the 3 services ahead of time so that the deployments are already aware of them later.
com: kubectl apply -f manifests/all-services.yml
- cap: Now we're going to walk through an initial build of the monitoring and scaling service for our crosswords application.
com: docker build -t 127.0.0.1:30400/monitor-scale:`git rev-parse --short HEAD` -f applications/monitor/Dockerfile applications/monitor
- cap: Setup the proxy in order to push the monitoring docker image to our cluster's registry
com: docker stop socat-registry; docker rm socat-registry; docker run -d -e "REGIP=`minikube ip`" --name socat-registry -p 30400:5000 chadmoon/socat:latest bash -c "socat TCP4-LISTEN:5000,fork,reuseaddr TCP4:`minikube ip`:30400"
- cap: Push the image
com: docker push 127.0.0.1:30400/monitor-scale:`git rev-parse --short HEAD`
- cap: Stop the registry proxy
com: docker stop socat-registry
- cap: Verify that the image is in our local registry using the registry-ui
com: minikube service registry-ui
- cap: Create the deployment and service for the monitoring and scaling server and wait for it to be deployed
com: sed 's#127.0.0.1:30400/monitor-scale:latest#127.0.0.1:30400/monitor-scale:'`git rev-parse --short HEAD`'#' applications/monitor/k8s/monitor-scale.yaml | kubectl apply -f -
- cap: Wait for the deployment to run
com: kubectl rollout status deployment/monitor-scale
- cap: See the montior-scale-* pod running using kubectl.
com: kubectl get pods
- cap: See the montior-scale-* service is setup using kubectl.
com: kubectl get services
- cap: See the montior-scale-* ingress is configured using kubectl.
com: kubectl get ingress
- cap: See the monitor-scale deployment is setup using kubectl
com: kubectl get deployments
- cap: Now we will bootstrap the crossword/mongodb services, creating a docker image and storing it in the local registry. This script runs the same steps as before for a different service application.
com: scripts/server.sh
- cap: Check to see if services has been deployed
com: kubectl rollout status deployment/services
- cap: Bootstrap the frontend web application. This script follows the same steps as before but
com: scripts/pages.sh
- cap: Check to see if the front end has been deployed
com: kubectl rollout status deployment/kr8sswordz
- cap: See all the pods running using kubectl.
com: kubectl get pods
- cap: Start the web application in your default browser
com: minikube service kr8sswordz
- name: Part 4
intro: In this part we will return to our Jenkins instance and setup jobs for each component of the kr8sswordz application.
steps:
- cap: Open the Jenkins service running in our cluster.
com: minikube service jenkins
- cap: Login as admin, if necessary.
com: echo 'Login as admin, if necessary.'
- cap: Click "New Item" and create an item with a name like "Monitor Scale Service Pipeline", choosing the type "Pipeline". Click OK.
com: echo 'Click "New Item" and create an item with a name like "Monitor Scale Service Pipeline", choosing the type "Pipeline". Click OK.'
- cap: From pipeline configuration, scroll down to Pipeline and change the Definition selection from "Pipeline script" to "Pipeline script from SCM".
com: echo 'From pipeline configuration, scroll down to Pipeline and change the Definition selection from "Pipeline script" to "Pipeline script from SCM".'
- cap: Set the SCM property to GIT.
com: echo 'Set the SCM property to GIT.'
- cap: Set the "Repository URL" to your fork (created in Part 2), such as https://github.com/kenzanlabs/kubernetes-ci-cd.git.
com: echo 'Set the "Repository URL" to your fork (created in Part 2), such as https://github.com/kenzanlabs/kubernetes-ci-cd.git.'
- cap: Set the "Script Path" to applications/monitor/Jenkinsfile
com: echo 'Set the "Script Path" to applications/monitor/Jenkinsfile'
- cap: Save and run the job using the "Build Now" button.
com: echo 'Save and run the job using the "Build Now" button.'
- cap: Click "New Item" and create an item with a name like "Puzzle Service Pipeline", choosing the type "Pipeline". Click OK.
com: echo 'Click "New Item" and create an item with a name like "Puzzle Service Pipeline", choosing the type "Pipeline". Click OK.'
- cap: From pipeline configuration, scroll down to Pipeline and change the Definition selection from "Pipeline script" to "Pipeline script from SCM".
com: echo 'From pipeline configuration, scroll down to Pipeline and change the Definition selection from "Pipeline script" to "Pipeline script from SCM".'
- cap: Set the SCM property to GIT.
com: echo 'Set the SCM property to GIT.'
- cap: Set the "Repository URL" to your fork (created in Part 2), such as https://github.com/kenzanlabs/kubernetes-ci-cd.git.
com: echo 'Set the "Repository URL" to your fork (created in Part 2), such as https://github.com/kenzanlabs/kubernetes-ci-cd.git.'
- cap: Set the "Script Path" to applications/crossword/Jenkinsfile
com: echo 'Set the "Script Path" to applications/crossword/Jenkinsfile'
- cap: Save and run the job using the "Build Now" button.
com: echo 'Save and run the job using the "Build Now" button.'
- cap: Click "New Item" and create an item with a name like "kr8sswordz FrontEnd Pipeline", choosing the type "Pipeline". Click OK.
com: echo 'Click "New Item" and create an item with a name like "kr8sswordz FrontEnd Pipeline", choosing the type "Pipeline". Click OK.'
- cap: From pipeline configuration, scroll down to Pipeline and change the Definition selection from "Pipeline script" to "Pipeline script from SCM".
com: echo 'From pipeline configuration, scroll down to Pipeline and change the Definition selection from "Pipeline script" to "Pipeline script from SCM".'
- cap: Set the SCM property to GIT.
com: echo 'Set the SCM property to GIT.'
- cap: Set the "Repository URL" to your fork (created in Part 2), such as https://github.com/kenzanlabs/kubernetes-ci-cd.git.
com: echo 'Set the "Repository URL" to your fork (created in Part 2), such as https://github.com/kenzanlabs/kubernetes-ci-cd.git.'
- cap: Set the "Script Path" to applications/kr8sswordz-pages/Jenkinsfile
com: echo 'Set the "Script Path" to applications/kr8sswordz-pages/Jenkinsfile'
- cap: Save and run the job using the "Build Now" button.
com: echo 'Save and run the job using the "Build Now" button.'
- cap: View updated application
com: minikube service kr8sswordz
# - name: Part 5
# intro: Spinnaker
# steps:
# - cap: Initialize Helm
# com: helm init; sleep 10; kubectl --namespace kube-system rollout status deployment/tiller-deploy
# - cap: Install Chart
# com: helm install --name spinnaker applications/spinnaker-helm/spinnaker-chart
# - cap: Launch Deck
# com: minikube service deck