forked from Sonal0409/DevOps_ClassNotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKube_NOTES_LMS.txt
More file actions
427 lines (264 loc) · 6.4 KB
/
Kube_NOTES_LMS.txt
File metadata and controls
427 lines (264 loc) · 6.4 KB
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
Kubernetes Notes:
# kubectl get nodes
Scenario1: Creation of Pod definition file
# mkdir mynewfiles
#cd mynewfiles
# ls
# vim pod-definition1.yml
i
---
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
type: reverse-proxy
author: edureka
spec:
containers:
- name: mynginx
image: nginx
# kubectl get pods
// pod will be ready and running
# kubectl get pods -o wide
// will give more information about pods with name of slave on which pod is available.
# kubectl get nodes -o wide
****************************************************
Create another Jenkins pod:
# vim pod-definition2.yml
i
---
apiVersion: v1
kind: Pod
metadata:
name: jenkins-pod
labels:
author: edureka
type: CI-CD
spec:
containers:
- name: myjenkins
image: jenkins
# kubectl get pods
#kubectl get pods -o wide
# kubectl get nodes - o wide
******************************************************
Create replica Set
*******************************************
kubectl delete -f pod-definition1.yml
kubectl delete -f pod-definition2.yml
kubectl get pods
# vim rc-definition.yml
i
---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: tomcat-rc
labels:
author: edureka
type: webserver
spec:
replicas: 3
selector:
matchLabels:
type: webserver
template:
metadata:
name: tomcat-pod
labels:
type: webserver
spec:
containers:
- name: mytomcat
image: tomcat
ports:
- containerPort: 8080
hostPort: 9090
# kubectl get pods
# kubectl get pods -o wide
# kubectl get all
*************************************************
Scaling of Pods using replica set
Method1:
Open the replica set and change replicas to 5
save the file
execute this command:
# kubectl replace -f rc-definition.yml
# kubectl get pods
now desired replicas of tomcat will be running
Method2: direct command
increase or decrese the replica count by using this command
# kubectl scale --replicas=2 -f rc-definition.yml
# kubectl get pods
//only 2 pods will be running now
For opening desired ports:
gcloud compute firewall-rules create rule1 --allow tcp:8080
gcloud compute firewall-rules create rule1 --allow tcp:9090
gcloud compute firewall-rules create rule1 --allow tcp:30008
*************************************************************
Deployment: ROLLING UPDATE
******************************
Highlevel kubernetes object called Deployment:
For this we use an object called Deployment Object
Create a new yaml file
# vim deployment.yml
i
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
author: edureka
type: proxyserver
spec:
replicas: 2
selector:
matchLabels:
type: proxyserver
template:
metadata:
name: nginx-pod
labels:
type: proxyserver
spec:
containers:
- name: mynginx
image: nginx:1.7.9
ports:
- containerPort: 80
hostPort: 8888
# kubectl get all
//will show deployment created.
# kubectl get pods
// will show all 3 pods created
# kubectl get deployment
// will show deployment which we just created information
Lets do rolling update now:
# kubectl get all
# kubectl --record deployment.apps/nginx-deployment set image deployment.v1.apps/nginx-deployment mynginx=nginx:1.9.1
# kubectl get pods
will give all pods, here you will see a duplicate rpelica is created for which evrsion is being updated and after which it will delete the earlier version replica. so users will not face any downtime
here copy the name of pod only begining : nginx-deployment
# kubectl describe pods nginx-deployment | less
Clean Up
# kubectl delete -f deployment.yml
*******************************************************
Creation of SERVICE OBJECTS
NODEPORT:
Create a jenkins pod definition file
# vim pod-definition3.yml
---
apiVersion: v1
kind: Pod
metadata:
name: jenkins-pod1
labels:
author: edureka
type: CI
spec:
containers:
- name: myjenkins1
image: jenkins
:wq!
# kubcectl create -f pod-definition3.yml
# kubectl get pods
# kubectl get pods -o wide
**********************************************
Create nodeport service object
# vim myservice.yml
i
---
apiVersion: v1
kind: Service
metadata:
name: jenkins-service
spec:
type: NodePort
ports:
- targetPort: 8080
port: 8080
nodePort: 30008
selector:
author: edureka
type: CI-CD
# kubectl create -f myservice.yml
# kubcectl get pods
# kubectl get pods -o wide
# kubectl get nodes -o wide
# kubectl get all // will give port information
go to browser with an ip:30008
# kubectl delete -f myservice.yml
# kubectl delete -f pod-definition3.yml
************************************************************
Service Object: LoadBalancer
*************************************************
Create a new deployment definition file for nginx pod
# vim deployment.yml
i
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
author: edureka
type: proxyserver
spec:
replicas: 2
selector:
matchLabels:
type: proxyserver
template:
metadata:
name: nginx-pod
labels:
type: proxyserver
spec:
containers:
- name: mynginx
image: nginx:1.7.9
ports:
- containerPort: 80
hostPort: 8888
# kubectl get pods
# kubectl get pods -o wide
# kubectl get nodes -o wide
We will create a new definition file of kind Service object and type as LoadBalancer,
here take the label same as that of pod given in above deployment under template:
metadata:
name: nginx-pod
labels:
type: proxyserver -- take this label information
# vim myservice2.yml
i
---
apiVersion: v1
kind: Service
metadata:
name: nginx-myservice
labels:
type: proxy1
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
selector:
type: proxyserver
# kubectl create -f myservice2.yml
# kubectl get all
// you will see a service with name as service/nginx-myservice
and external ip address as pending
re execute the command to see if external ip is generated
OR
# kubectl describe service/nginx-myservice | less
OR
# kubectl describe service nginx-myservice | less
These all commands will give complete information about service and we can find the load balancer ingress ip
Clean up
# kubectl delete -f myservice2.yml
# kubectl get all
# kubectl delete -f deployment2.yml
# kubectl get pods
*************************************************************************