-
Notifications
You must be signed in to change notification settings - Fork 3
/
day4.txt
515 lines (455 loc) · 18.4 KB
/
day4.txt
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
MASTER + Workstation = 13.233.137.177
Worker = 65.0.105.230
====================================
Chennakeshava 35.154.79.198
Susil 15.206.90.54
Shreyash 13.234.30.28
Indhu 15.206.185.76
Pranjal 13.232.209.163
Vinay 13.233.3.8
Alwin 65.0.122.43
Banala 13.232.75.184
Ajith 15.207.19.208
WORKER
-------------------------------
Chennakeshava 15.206.173.114
Susil 13.233.31.207
Shreyash 13.127.153.68
Indhu 52.66.31.26
Pranjal 13.233.238.138
Vinay 65.0.133.90
Alwin 13.234.111.83
Banala 13.127.22.241
Ajith 13.235.50.226
#Jayaprasad
==============
13.232.176.149
65.0.124.45
==================================
13.233.137.177
============================================
How kubectl work in Workstation?
Getting Comfortable with Kubectl
--------------------------------
What is Namespace?
How to work with Namespace?
--------------------------------
What is POD
How to work with Pod?
Deep Dive into a POD?
--------------------------------
ReplicationController
=========================
How kubectl work in Workstation?
kubectl
$USER_HOME/.kube/config(yaml)
How Kubectl get AUTHORZIED and Authentication to API server
- Authentication == Certificate
- Authorization == RBAC
What is the content for config file?
---------------------------------
Clustor(S):
Clustor1: http:/ip/ofapi
Clustor2: http:/ip/ofapi
Clustor3: http:/ip/ofapi
Clustor4: http:/ip/ofapi
User(S):
user1: key+cert
user2: key+cert
user3: key+cert
Context(S)
Context1 = Clustor1 + user3
Context2 = Clustor2 + user2
Context3 = Clustor3 + user1
curr-context = Context2
==========================================================
Getting Comfortable with Kubectl
==========================================================
[centos@ip-172-31-13-37 ~]$ kubectl
kubectl controls the Kubernetes cluster manager.
Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/
Basic Commands (Beginner):
create Create a resource from a file or from stdin.
expose Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service
run Run a particular image on the cluster
set Set specific features on objects
Basic Commands (Intermediate):
explain Documentation of resources
get Display one or many resources
edit Edit a resource on the server
delete Delete resources by filenames, stdin, resources and names, or by resources and label selector
Deploy Commands:
rollout Manage the rollout of a resource
scale Set a new size for a Deployment, ReplicaSet or Replication Controller
autoscale Auto-scale a Deployment, ReplicaSet, or ReplicationController
Cluster Management Commands:
certificate Modify certificate resources.
cluster-info Display cluster info
top Display Resource (CPU/Memory/Storage) usage.
cordon Mark node as unschedulable
uncordon Mark node as schedulable
drain Drain node in preparation for maintenance
taint Update the taints on one or more nodes
Troubleshooting and Debugging Commands:
describe Show details of a specific resource or group of resources
logs Print the logs for a container in a pod
attach Attach to a running container
exec Execute a command in a container
port-forward Forward one or more local ports to a pod
proxy Run a proxy to the Kubernetes API server
cp Copy files and directories to and from containers.
auth Inspect authorization
debug Create debugging sessions for troubleshooting workloads and nodes
Advanced Commands:
diff Diff live version against would-be applied version
apply Apply a configuration to a resource by filename or stdin
patch Update field(s) of a resource
replace Replace a resource by filename or stdin
wait Experimental: Wait for a specific condition on one or many resources.
kustomize Build a kustomization target from a directory or a remote url.
Settings Commands:
label Update the labels on a resource
annotate Update the annotations on a resource
completion Output shell completion code for the specified shell (bash or zsh)
Other Commands:
api-resources Print the supported API resources on the server
api-versions Print the supported API versions on the server, in the form of "group/version"
config Modify kubeconfig files
plugin Provides utilities for interacting with plugins.
version Print the client and server version information
Usage:
kubectl [flags] [options]
Use "kubectl <command> --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all commands).
[centos@ip-172-31-13-37 ~]$ kubectl api-resources
NAME SHORTNAMES APIVERSION NAMESPACED KIND
bindings v1 true Binding
componentstatuses cs v1 false ComponentStatus
configmaps cm v1 true ConfigMap
endpoints ep v1 true Endpoints
events ev v1 true Event
limitranges limits v1 true LimitRange
namespaces ns v1 false Namespace
nodes no v1 false Node
persistentvolumeclaims pvc v1 true PersistentVolumeClaim
persistentvolumes pv v1 false PersistentVolume
pods po v1 true Pod
podtemplates v1 true PodTemplate
replicationcontrollers rc v1 true ReplicationController
resourcequotas quota v1 true ResourceQuota
secrets v1 true Secret
serviceaccounts sa v1 true ServiceAccount
services svc v1 true Service
mutatingwebhookconfigurations admissionregistration.k8s.io/v1 false MutatingWebhookConfiguration
validatingwebhookconfigurations admissionregistration.k8s.io/v1 false ValidatingWebhookConfiguration
customresourcedefinitions crd,crds apiextensions.k8s.io/v1 false CustomResourceDefinition
apiservices apiregistration.k8s.io/v1 false APIService
controllerrevisions apps/v1 true ControllerRevision
daemonsets ds apps/v1 true DaemonSet
deployments deploy apps/v1 true Deployment
replicasets rs apps/v1 true ReplicaSet
statefulsets sts apps/v1 true StatefulSet
tokenreviews authentication.k8s.io/v1 false TokenReview
localsubjectaccessreviews authorization.k8s.io/v1 true LocalSubjectAccessReview
selfsubjectaccessreviews authorization.k8s.io/v1 false SelfSubjectAccessReview
selfsubjectrulesreviews authorization.k8s.io/v1 false SelfSubjectRulesReview
subjectaccessreviews authorization.k8s.io/v1 false SubjectAccessReview
horizontalpodautoscalers hpa autoscaling/v1 true HorizontalPodAutoscaler
cronjobs cj batch/v1beta1 true CronJob
jobs batch/v1 true Job
certificatesigningrequests csr certificates.k8s.io/v1 false CertificateSigningRequest
leases coordination.k8s.io/v1 true Lease
endpointslices discovery.k8s.io/v1beta1 true EndpointSlice
events ev events.k8s.io/v1 true Event
ingresses ing extensions/v1beta1 true Ingress
flowschemas flowcontrol.apiserver.k8s.io/v1beta1 false FlowSchema
prioritylevelconfigurations flowcontrol.apiserver.k8s.io/v1beta1 false PriorityLevelConfiguration
ingressclasses networking.k8s.io/v1 false IngressClass
ingresses ing networking.k8s.io/v1 true Ingress
networkpolicies netpol networking.k8s.io/v1 true NetworkPolicy
runtimeclasses node.k8s.io/v1 false RuntimeClass
poddisruptionbudgets pdb policy/v1beta1 true PodDisruptionBudget
podsecuritypolicies psp policy/v1beta1 false PodSecurityPolicy
clusterrolebindings rbac.authorization.k8s.io/v1 false ClusterRoleBinding
clusterroles rbac.authorization.k8s.io/v1 false ClusterRole
rolebindings rbac.authorization.k8s.io/v1 true RoleBinding
roles rbac.authorization.k8s.io/v1 true Role
priorityclasses pc scheduling.k8s.io/v1 false PriorityClass
csidrivers storage.k8s.io/v1 false CSIDriver
csinodes storage.k8s.io/v1 false CSINode
storageclasses sc storage.k8s.io/v1 false StorageClass
volumeattachments storage.k8s.io/v1 false VolumeAttachment
11 kubectl get nodes
12 kubectl get pods --all-namespaces
13 clear
14 kubectl get nodes
15 clear
16 kubectl get nodes
17 sudo -s
18 more ~/.kube/config
19 clear
20 kubectl config
21 kubectl config view
22 clear
23 kubectl
24 clear
25 kubectl
26 clear
27* kubectl
28* kubectl plane is running at https://172.31.13.37:644
29 KubeDNS is running at https://
30 kubectl api-resources
31 kubectl api-resources | wc -l
32 kubectl api-resources
33 kubectl api-versions
34 kubectl api-resources
35 clear
36 kubectl get ns
37 kubectl get pods -n=kube-system
38 history
========================================================================
How to work with API???
CRUD - GET - PUT - POST - DELETE
CREATE
CMD
create
YAML
create yaml
READ
CMD
get
YAML
UPDATE
CMD
edit
YAML
apply yaml
DELETE
CMD
delete
YAML
delete yaml
=========================================================================
Namespace
Pod
ReplicationController
Deployment
Services
Storage
RBAC
==============================================
39 clear
40 kubectl
41 clear
42 kubectl -h
43 clear
44 kubectl create -h
45 kubectl create ns -h
46 history
47 kubectl create ns -h
48 clear
49 kubectl create namespace dev
50 kubectl create namespace qa
51 kubectl get -h
52 clear
53 kubectl get ns
54 kubectl edit ns dev
55 kubectl delete ns dev
56 kubectl get ns
======================================================
======================================================
------------------------
pod.yaml
-------------------
apiVersion: v1
kind: Pod
metadata:
name: hello-pod
labels:
app: webserver
spec:
containers:
- name: hello-ctr
image: nginx
ports:
- containerPort: 80
65 ls
66 mkdir rajesh
67 cd rajesh/
68 ls
69 vi pod.yaml
70 kubectl create -f pod.yaml
71 kubectl get pod
72 kubectl create -f pod.yaml
73 kubectl get ne
74 kubectl get ns
75 clear
76 kubectl create ns rajesh
77 kubectl create -f pod.yaml -n=rajesh
78 kubectl get pod
79 kubectl get pod -n=rajesh
80 kubectl get pod --all-namespaces
81 clear
82 kubectl get pod -n=rajesh
83 kubectl get pod -n=rajesh -o wide
84 kubectl get pod -h
85 clear
86 kubectl get pod -n=rajesh -o wide
87 curl http://10.44.0.2
88 clear
89 ls
90 kubectl get pod -n=rajesh -o wide
91 kubectl edit pod hello-pod -n=rajesh
92 kubectl get pod -n=rajesh -o wide --show-labels
93 ls
94 vi pod.yaml
95 kubectl apply -f pod.yaml -n=rajesh
96 kubectl get pod -n=rajesh -o wide --show-labels
97 kubectl delete pod hello-pod
98 kubectl delete -f pod.yaml -n=rajesh
99 clear
100 kubectl get pods --all-namespaces
101 history
Troubleshooting and Debugging Commands:
describe Show details of a specific resource or group of resources
logs Print the logs for a container in a pod
attach Attach to a running container
exec Execute a command in a container
port-forward Forward one or more local ports to a pod
cp Copy files and directories to and from containers.
auth Inspect authorization
debug Create debugging sessions for troubleshooting workloads and nodes
100 kubectl get pods --all-namespaces
101 history
102 clear
103 kubectl
104 clear
105 kubectl apply -f pod.yaml -n=rajesh
106 kubectl get pods -n=rajesh
107 kubectl get ns
108 kubectl get nodes
109 kubectl describe pod hello-pod -n=rajesh
110 clear
111 kubectl describe ns rajesh
112 kubectl get nodes
113 kubectl describe node ip-172-31-13-37.ap-south-1.compute.internal
114 clear
115 sl
116 kubectl get pods -n=rajesh
117 kubectl logs hello-pod -n=rajesh
118 kubectl get pods -o wide
119 kubectl get pods -o wide -n=rajesh
120 curl http://10.44.0.1
121 clear
122 kubectl logs hello-pod -n=rajesh
123 kubectl logs -h
124 clear
125 ls
126 kubectl get pods -n=rajesh
127 kubectl exec hello-pod ls
128 kubectl exec hello-pod ls -n=rajesh
129 clear
130 kubectl exec hello-pod -n=rajesh df -kh
131 kubectl exec hello-pod -n=rajesh df
132 kubectl exec -it hello-pod -n=rajesh /bin/bash
133 kubectl attach hello-pod -n=rajesh
134 history
135 clear
136 kubectl attach hello-pod -n=rajesh
137 clear
138 kubectl port-forward -h
139 clear
140 kubectl port-forward pod/hello-pod 5000 6000 -n=rajesh
141 kubectl port-forward pod/hello-pod 80:5000 80:6000 -n=rajesh
142 kubectl port-forward pod/hello-pod 80:5000 -n=rajesh
143 clear
144 kubectl port-forward pod/hello-pod 80 5000 -n=rajesh
145 kubectl port-forward pod/hello-pod 5000 80 -n=rajesh
146 kubectl port-forward -h
147 clear
148 kubectl port-forward pod/hello-pod 80:5000 -n=rajesh
149 kubectl port-forward pod/hello-pod 5000:80 -n=rajesh
150 kubectl port-forward --address 0.0.0.0 pod/hello-pod 5000:80 -n=rajesh
150 kubectl port-forward --address 0.0.0.0 pod/hello-pod 5000:80 -n=rajesh
151 history
152 clear
153 kubectl get pods -n=rajesh
154 kubectl exec hello-pod -n=rajesh ls /tmp
155 ls
156 kubectl cp pod.yaml hello-pod:/tmp -n=rajesh
157 kubectl exec hello-pod -n=rajesh ls /tmp
158 kubectl cp -h
159 clear
160 kubectl auth
161 kubectl auth can-i delete pod
162 kubectl auth can-i create deploy
163 kubectl auth can-i create services
164 kubectl auth can-i create node
===============================================================
Replication Controller
=======================================
Replication You can replicate POD to many.
Controller == Make sure the Desire# of POds === Actual Number
apiVersion: v1
kind: ReplicationController
metadata:
name: hello-rc
spec:
replicas: 2
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-ctr
image: scmgalaxy/nginx-devopsschoolv1
ports:
- containerPort: 80
165 history
166 clear
167 kubectl create -h
168 clear
169 ls
170 vi rc.yaml
171 kubectl create -f rc.yaml -n=rajesh
172 kubectl get pods
173 kubectl get pods -n=rajesh
174 kubectl describe rc hello-rc -n=rajesh
175 kubectl get pod -n=rajesh
176 kubectl describe pod hello-pod -n=rajesh
177 kubectl get pod -n=rajesh
178 kubectl describe pod hello-rc-6c2mz -n=rajesh
179 clear
180 kubectl describe rc hello-rc -n=rajesh
181 kubectl edit rc hello-rc -n=rajesh
182 kubectl get pod -n=rajesh
183 clear
184 vi rc.yaml
185 kubectl -f rc.yaml -n=rajesh
186 kubectl apply -f rc.yaml -n=rajesh
187 kubectl get pod -n=rajesh
188 clear
189 ls
190 kubectl get pods -n=rajesh
191 kubectl delete pod hello-rc-dgscx hello-rc-6c2mz -n=rajesh
192 kubectl get pods -n=rajesh
193 history
196 cleaer
197 clear
198 kubectl explain node
199 clear
200 kubectl explain node.spec
201 kubectl explain node.spec.taints
202 clear
203 kubectl explain pod
204 kubectl explain pod.spec
205 kubectl explain pod.spec.containers
206 clear
207 kubectl explain rc
208 kubectl explain rc.spec
209 kubectl explain rc.spec.template
210 kubectl explain rc.spec.template.spec
211 kubectl explain ns
212 kubectl explain ns.spec
213 history