-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathALLKubernetes-Notes
More file actions
339 lines (250 loc) · 5.64 KB
/
ALLKubernetes-Notes
File metadata and controls
339 lines (250 loc) · 5.64 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
ubernetes 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 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
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:
type: webserver
# 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
*****************************************
HPA:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
name: nginxpod
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
resources:
limits:
cpu: 10m
---
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
spec:
type: ClusterIP ## this is default if we do not type in service definition
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: nginx-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: nginx
minReplicas: 1
maxReplicas: 10
targetCPUUtilizationPercentage: 5
kubectl create -f hpa.yaml
Generate load:
kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://serviceIP:portnumber; done"
******************************************
PV:
apiVersion: v1
kind: PersistentVolume
metadata:
name: block-pv
spec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /tmp/data
kubectl create -f pv.yml
PVC
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
POD:
apiVersion: v1
kind: Pod
metadata:
name: pod-pvc
spec:
containers:
- image: nginx
name: c1
volumeMounts:
- mountPath: "/data"
name: my-volume
volumes:
- name: my-volume
persistentVolumeClaim:
claimName: pvc
refer: https://github.com/Sonal0409/DevOps_ClassNotes/tree/master/Kubernetese/PersistentVolume
********************************************
HELM
Helm install
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
# Use GKE
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install my-release bitnami/jenkins
helm list
#Wait for 2 mins to see Jenkins UP
kubectl get deploy
kubectl get pods
kubectl get svc
#check the NodePort and access the app with Node IP
**************************
# vim dev.properties
app.env:dev
app.mem=2048m
app.properties=dev.env.url
:wq!
# kubectl create configmap dev-config1 --from-file=dev.properties
# kubectl get configmap
# kubectl get configmap dev-config1 -o yaml
Use configmap for a pod
vim pod-configmap.yml
kind: Pod
apiVersion: v1
metadata:
name: pod-configmap
spec:
containers:
- image: nginx
name: c1
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
name: dev-config1
restartPolicy: Never
:wq!
# kubectl apply -f pod-configmap.yml
# kubectl exec -it pod-configmap bash
# cd /etc/config
you will find the dev.properties file and configurations
Edit the configMAP
kubectl edit configmap -n <namespace> <configMapName> -o yaml
This opens up a vim editor with the configmap in yaml format. Now simply edit it and save it.
Refer the repo for more kubernetes concepts: https://github.com/Sonal0409/DevOps_ClassNotes/tree/master/Kubernetese