-
Notifications
You must be signed in to change notification settings - Fork 2
/
kubernetes.html
962 lines (936 loc) · 59.8 KB
/
kubernetes.html
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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
<!DOCTYPE html>
<html lang="en">
<head>
<title>CNC Cheet Sheet theme for developers</title>
<!-- Meta -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="favicon.ico">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<!-- FontAwesome JS -->
<script defer src="https://use.fontawesome.com/releases/v5.8.2/js/all.js" integrity="sha384-DJ25uNYET2XCl5ZF++U8eNxPWqcKohUUBUpKGlNLMchM7q4Wjg2CUpjHLaL8yYPH" crossorigin="anonymous"></script>
<!-- Global CSS -->
<link rel="stylesheet" href="assets/plugins/bootstrap/css/bootstrap.min.css">
<!-- Plugins CSS -->
<link rel="stylesheet" href="assets/plugins/prism/prism.css">
<link rel="stylesheet" href="assets/plugins/elegant_font/css/style.css">
<!-- Theme CSS -->
<link id="theme-style" rel="stylesheet" href="assets/css/styles.css">
</head>
<body class="body-green">
<div class="page-wrapper">
<!-- ******Header****** -->
<header id="header" class="header">
<div class="container">
<div class="branding">
<h1 class="logo">
<a href="index.html">
<span aria-hidden="true" class="icon_documents_alt icon"></span>
<span class="text-highlight">CNC</span><span class="text-bold">Cheet Sheet</span>
</a>
</h1>
</div><!--//branding-->
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.html">Home</a></li>
<li class="breadcrumb-item active">Kubernetes</li>
</ol>
<div class="top-search-box">
<form id="srch" class="form-inline search-form justify-content-center" action="" method="get">
<input id="data" type="text" placeholder="Enter search terms..." value="" class="form-control search-input">
<button type="submit" class="btn search-btn" value="Search"><i class="fas fa-search"></i></button>
</form>
</div>
</div><!--//container-->
</header><!--//header-->
<div class="doc-wrapper">
<div class="container">
<div id="doc-header" class="doc-header text-center">
<h1 class="doc-title"><img alt="kubernetes-icon" src="kbn.png"/></i> Kubernetes Quick Start</h1>
</div><!--//doc-header-->
<div class="doc-body row">
<div class="doc-content col-md-9 col-12 order-1">
<div class="content-inner">
<section id="download-section" class="doc-section">
<h2 class="section-title">Installation & Setup</h2>
<div class="section-block">
<p>
When working with a tool like kubernetes it is very important to make a good friendship with its <b>documentation</b> <a href="https://kubernetes.io/docs/home/">link</a> <br>
to setup kubernetes we will need two main components
<ul>
<li>kubectl</li>
<li>minikube</li>
<li>virtual box(optional)</li>
</ul>
if you have any problem or error during the setup you can refer to google.....
</p>
<a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-linux" class="btn btn-green" target="_blank"><i class="fas fa-download"></i> Setup guide for kubernetes</a>
</div>
</section><!--//doc-section-->
<section id="installation-section" class="doc-section">
<h2 class="section-title">Installation</h2>
<div id="step1" class="section-block">
<h3 class="block-title">Step One</h3>
<p>
First we need to install kubectl through which we will manage kubernetes.<br>
if you are using linux just copy and paste these commands one by one.
</p>
<div class="code-block">
<h6>Commands:</h6>
<p><code>sudo apt-get install curl</code></p>
<p><code>curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl</code></p>
<p><code>chmod +x ./kubectl</code></p>
<p><code>sudo mv ./kubectl /usr/local/bin/kubectl</code></p>
<p>To test run below command</p>
<p><code>kubectl version --client</code></p>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="step2" class="section-block">
<h3 class="block-title">Step Two</h3>
<p>
Now we will install minikube, when using minikube 8Gb RAM is recommended.<br>
if you are using linux then just copy and paste these commands one by one.
</p>
<div class="code-block">
<h6>Commands:</h6>
<p><code>curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64</code></p>
<p><code>chmod +x minikube</code></p>
<p><code>sudo mkdir -p /usr/local/bin/</code></p>
<p><code>sudo install minikube /usr/local/bin/</code></p>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="step3" class="section-block">
<h3 class="block-title">Step Three</h3>
<p>
In this step we will install virtual box which is <b>optional</b>, if you want to use virtual box then make sure your machine supports virtualization <br>
To check that your system supports virtualization or not run the command below <br>
<p><code>grep -E --color 'vmx|svm' /proc/cpuinfo</code></p>
if this command returns some output then you are good to go else continue without install virtual box.
</p>
<div class="code-block">
<h6>Commands:</h6>
<p><code>sudo apt-get update</code></p>
<p><code>sudo apt-get upgrade</code></p>
<p><code>wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -</code></p>
<p><code>wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -</code></p>
<p><code>sudo add-apt-repository "deb http://download.virtualbox.org/virtualbox/debian xenial contrib"</code></p>
<p><code>sudo apt-get update</code></p>
<p><code>sudo apt-get install virtualbox</code></p>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="step4" class="section-block">
<h3 class="block-title">Step Four</h3>
<p>
Lets check that we installed all 3 or 2 main tools correctly or not.<br>
Run the commands that is based on your criteria. <br>
if one fails because of any error use the command below and then try next command.
<p><code>minikube delete</code></p>
</p>
<div class="code-block">
<h6>Commands:</h6>
<p><code>minikube start</code></p>
<p>above command will start minikube using virtual box</p>
<p><code>minikube start --driver=none</code></p>
<p>if you have not installed virtual box then use the above command, if it also not works the try the below command.</p>
<p><code>minikube start --driver=docker</code></p>
<p>above command will start minikube using docker</p>
<p>
If none of the above command worked for you then try adding <b>--force</b> flag to command <br>
example : <p><code>minikube start --driver=docker --force</code></p>
</p>
</div><!--//code-block-->
<h3>If minikube Starts</h3>
<p>If minikube starts then you can type the below command to get its status</p>
<p><code>minikube status</code></p>
<p>
this command will return result similler to <br>
host: Running
kubelet: Running
apiserver: Running
</p>
<p>Now its all set to us kubernetes :-)</p>
</div><!--//section-block-->
</section><!--//doc-section-->
<section id="Pod" class="doc-section">
<h2 class="section-title">Pod</h2>
<div class="section-block">
<p>
it is a resource of Kubernetes that isolates container or group of containers, every pod has its own ip address and each container in it has different port number.
</p>
</div><!--//section-block-->
<div id="Pod-basic-template" class="section-block">
<div class="code-block">
<h6>Pod basic template</h6>
<pre><code class="language-markup">
kind: Pod
apiVersion: v1
metadata:
name: <pod-name>
spec:
containers:
- name: <container-name>
image: <image>
ports:
- containerPort: 80 </code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="Pod-using-cmd" class="section-block">
<div class="code-block">
<h6>Simple pod using command line</h6>
<pre><code class="language-git">kubectl run <name of pod> --image=<name of the image from registry></code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="Port-forward-pod" class="section-block">
<div class="code-block">
<h6>Port forward pod</h6>
<pre><code class="language-git">kubectl port-forward <pod-name> <desired-port>:<pod-exposed-port></code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="List-pods" class="section-block">
<div class="code-block">
<h6>List pods</h6>
<pre><code class="language-git">
kubectl get pods --show-labels // display all pods with their labels
kubectl get pods -L <label key> // display pods with the spicfied label key as heading
kubectl get pods -l <label key>=<value> // display pods with the spicfied label key & value
kubectl get pods -l '<label key>in<(val1,val2)>' --show-labels // display pods with the spicfied label key & value could be either of them
</code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
</section><!--//doc-section-->
<section id="ReplicaSet" class="doc-section">
<h2 class="section-title">ReplicaSet</h2>
<div class="section-block">
<p>
it is a resource of kubernetes that maintain the number of currently running copies of a pod.
</p>
</div><!--//section-block-->
<div id="RSet-basic-template" class="section-block">
<div class="code-block">
<h6>ReplicaSet basic template</h6>
<pre><code class="language-markup">
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
labels:
app: guestbook
spec:
# modify replicas according to your case
replicas: 3
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: <container-name>
image: <image>
ports:
- containerPort: 80</code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="handlebars" class="section-block">
<div class="code-block">
<h6>Ceate ReplicaSet</h6>
<pre><code class="language-git">kubectl create -f <name of yaml file></code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="List-ReplicaSet" class="section-block">
<div class="code-block">
<h6>List ReplicaSet</h6>
<pre><code class="language-git">kubectl get rs</code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="Scale-ReplicaSet" class="section-block">
<div class="code-block">
<h6>Scale ReplicaSet</h6>
<p>it will increase or decrease the number of pods that are managed by a ReplicaSet</p>
<pre><code class="language-git">kubectl scale rs <ReplicaSet-name> --replicas=<desired-number></code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="Delete-ReplicaSet" class="section-block">
<div class="code-block">
<h6>Delete ReplicaSet</h6>
<p>This command will <b>delete replicaset without deleting pods</b> generated by that replica set</p>
<pre><code class="language-git">kubectl delete rs <Replicaset-name> --cascade=false</code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
</section><!--//doc-section-->
<section id="Job" class="doc-section">
<h2 class="section-title">Job</h2>
<div class="section-block">
<p>
it is a resource of kubernetes that creates a pod that does a specific task and gets terminated.
</p>
</div><!--//section-block-->
<div id="html" class="section-block">
<div class="code-block">
<h6>Job basic template</h6>
<pre><code class="language-markup">
apiVersion: batch/v1
kind: Job
metadata:
name: <job-name>
spec:
template:
spec:
containers:
- name: <container-name>
image: <image>
command: ["echo", "Hello world"]
restartPolicy: Never
backoffLimit: 4</code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
</section><!--//doc-section-->
<section id="Cron-Job" class="doc-section">
<h2 class="section-title">Cron Job</h2>
<div class="section-block">
<p>
it is a resource of kubernetes that creates a job that can repeat after certain time.
<br> first it creats a job then a pod that does the specified work.
</p>
</div><!--//section-block-->
<div id="html" class="section-block">
<div class="code-block">
<h6>Cron job basic template</h6>
<pre><code class="language-markup">
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: <cron job name>
spec:
schedule: "*/1 * * * *"
jobTemplate: # job
spec:
template: # pod template
spec:
containers:
- name: <container-name>
image: <image>
command: ["echo", "Hello world"]
restartPolicy: OnFailure
</code></pre>
<p><b>Note :</b> here ***** reprisents minute | hour | day | month | year</p>
</div><!--//code-block-->
</div><!--//section-block-->
</section><!--//doc-section-->
<section id="Service" class="doc-section">
<h2 class="section-title">Service</h2>
<div class="section-block">
<p>
it is a resource of kubernetes that allows us to manage routing.<br>
There are mainly 2 type of services
<ol>
<li>External-ip</li>
<li>LoadBalancer</li>
</ol>
</p>
</div><!--//section-block-->
<div id="Service-basic-template" class="section-block">
<div class="code-block">
<h6>Service basic template</h6>
<pre><code class="language-markup">
apiVersion: v1
kind: Service
metadata:
name: <service-name>
spec:
selector:
<label-key>: <label-value>
ports:
- port: <Pod-port>
targetPort: <container-exposed-port>
type: LoadBalancer</code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="Service-using-cmd" class="section-block">
<div class="code-block">
<h6>Service using command line</h6>
<p>For this you should have a <b>ReplicaSet</b> managing one or more pods.</p>
<pre><code class="language-git">kubectl expose rs <ReplicaSet-name> --name=<Service-name> --selector=<label-key>=<label-value> --port=<Pod-port> --target-port=<container-exposed-port> --type=LoadBalancer</code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
</section><!--//doc-section-->
<section id="Probes" class="doc-section">
<h2 class="section-title">Probes</h2>
<div class="section-block">
<p>
Probe means to inspect,probe checks our application again and again after specific period of time to check if it is working correctly.
<br>link to official documentation of probes <a target="_blank" href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/">link</a>
<br> There are <b>2 types</b> of Probes
<ol>
<li>Liveness probe (re-starts the container if fails)</li>
<li>Readiness probe (restricts access to container if fails)</li>
</ol>
</p>
</div><!--//section-block-->
<ol>
<li>
<div id="Liveness-probe" class="section-block">
<div class="code-block">
<h4>Liveness probe</h4>
<p>
liveness probe checks our application again and again after a spicific period of time to check if it is working correctly
<br>If it fails it restarts the container.
<br>There are <b>3 types of liveness</b> probe
<ol>
<li>http get => sends a http request and checks for response</li>
<li>tcp socket => tries to make connection on container port</li>
<li>exec => executes a command in the application container to check if it is hanged</li>
</ol>
</p>
<h6>HTTP GET basic template</h6>
<pre><code class="language-markup">
apiVersion: v1
kind: Pod
metadata:
labels:
<key>: <value>
name: <Pod-name>
spec:
containers:
- name: <container-name>
image: <container-image>
livenessProbe:
httpGet:
path: / #root
port: <Pod-port or container-port>
initialDelaySeconds: <delay before first check>
periodSeconds: <time to wait after each check>
</code></pre>
<h6>TCP socket basic template</h6>
<pre><code class="language-markup">
apiVersion: v1
kind: Pod
metadata:
name: <pod-name>
spec:
containers:
- name: <container-name>
image: <container-image>
ports:
- containerPort: 8080
livenessProbe:
tcpSocket:
port: <container-port>
initialDelaySeconds: <delay before first check>
periodSeconds: <time to wait after each check>
</code></pre>
<h6>EXEC basic template</h6>
<pre><code class="language-markup">
apiVersion: v1
kind: Pod
metadata:
name: <pod-name>
spec:
containers:
- name: <container-name>
image: <container-image>
livenessProbe:
exec:
command:
- <command eg: ls>
initialDelaySeconds: <delay before first check>
periodSeconds: <time to wait after each check>
</code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
</li>
<li>
<div id="Readiness-probe" class="section-block">
<div class="code-block">
<h4>Readiness probe</h4>
<p>
Readiness checks our application again and again after a spicific period of time to check if its is working correctly
<br>If it fails it restricts access to container.
<br>There are <b>3 types of readiness</b> probe
<ol>
<li>http get => sends a http request and checks for response</li>
<li>tcp socket => tries to make connection on container port</li>
<li>exec => executes a command in the application container to check if it is hanged</li>
</ol>
</p>
<div class="callout-block callout-info">
<div class="icon-holder">
<i class="fas fa-bullhorn"></i>
</div><!--//icon-holder-->
<div class="content">
<h4 class="callout-title">Note:</h4>
<p>All 3 templates are same as the liveness probe <b>except:</b>
<br>use <code>readinessProbe:</code> instead of <code>livenessProbe:</code></p>
</div><!--//content-->
</div><!--//callout-->
</div><!--//code-block-->
</div><!--//section-block-->
</li>
</ol>
</section><!--//doc-section-->
<section id="Volumes" class="doc-section">
<h2 class="section-title">Volumes</h2>
<div class="section-block">
<p>
actually it is <b>not a resource</b> of kubernetes it is mostly written or defined in the <b>spec:</b> of Pods.<br>
it actually helps us to share data between containers or whole cluster, not only that but also allow us to retain data if the pod or the container is deleted. you can say that it store & share data on the <b>pod level</b><br>
there are many types of volumes.
<ul>
<li>empty dir</li>
<li>configmam, secret, downward API</li>
<li>presistant vloumes</li>
<li>git repo</li>
<li>gce presistant disk</li>
<li>aws Elastic block storage</li>
<li>Azure disk</li>
</ul>
</p>
</div><!--//section-block-->
<div id="html" class="section-block">
<div class="code-block">
<h6>emptyDir volume basic template</h6>
<p>it is usually used to share data b/w two or more containers in a single pod, as it makes a directory shared b/w containers.</p>
<pre><code class="language-markup">
apiVersion: v1
kind: Pod
metadata:
name: <pod-name>
spec:
volumes:
- name: <volume-name>
emptyDir: {}
containers:
- image: <container-image>
name: <container-name>
volumeMounts:
- mountPath: <path> #path of dir to share
name: <volume-name> #that is mentioned above
- image: <container-image>
name: <container-name>
volumeMounts:
- mountPath: <path> #path of dir to share
name: <volume-name> #that is mentioned above</code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
</section><!--//doc-section-->
<section id="persistent-Volumes" class="doc-section">
<h2 class="section-title">persistent Volumes</h2>
<div class="section-block">
<p>
presistant volumes are a little different than other volumes as the store & share data on the <b>cluster level</b><br>
it also works a little differently. Below are the steps to use and work with persistent volume (pv).
<ol>
<li>Make a persistent volume (pv)</li>
<li>Make a persistent volume claim (pvc)</li>
<li>Mount it in a pod as volume using (pvc)</li>
</ol>
</p>
</div><!--//section-block-->
<div id="PV-basic-template" class="section-block">
<div class="code-block">
<h6>persistent Volume basic template</h6>
<p>you can access host file system by <code>minikube ssh</code> command</p>
<pre><code class="language-markup">
apiVersion: v1
kind: PersistentVolume
metadata:
name: <pv-name>
spec:
capacity:
storage: <storage size eg: 5Gi>
hostPath:
path: <path> #pth where to store data on cluster
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: <Recycle or Retain or Delete></code></pre>
</div><!--//code-block-->
<div id="PVC-basic-template" class="code-block">
<h6>persistent Volume claim basic template</h6>
<pre><code class="language-markup">
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: <pvc-name>
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: <storage size eg: 100M>
storageClassName: ""</code></pre>
</div><!--//code-block-->
<div id="Pod-mounting-pv-basic-template" class="code-block">
<h6>Pod mounting persistent Volume basic template</h6>
<pre><code class="language-markup">
apiVersion: v1
kind: Pod
metadata:
name: <pod-name>
spec:
volumes:
- name: <volume-name>
persistentVolumeClaim:
claimName: <pvc-name> #use pvc name that you have created
containers:
- name: <container-name>
image: <container-image>
volumeMounts:
- mountPath: <path> #path of dir to share
name: <volume-name> #that is mentioned above</code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
</section><!--//doc-section-->
<section id="conf-deployment" class="doc-section">
<h2 class="section-title">Configuration</h2>
<div class="section-block">
<p>
In this section we will see tools for configuration and deployments provided by kubernetes.
</p>
</div><!--//section-block-->
<div id="ConfigMap" class="section-block">
<div class="code-block">
<h4>ConfigMap</h4>
<p>
It is a resource that can hold some configurations of your application so that you don't have to mess with application code to make some configuration changes<br>
There are two types of config map.
<ol>
<li>One that can be made as text file and can be mounted on a pod as volume</li>
<li>One that can be made as env file and can be attached to a pod</li>
</ol>
</p>
<h6>Config map using cmd</h6>
<pre><code class="language-git">kubectl create configmap <resource-name> --from-literal=<key1>=<val1> --from-literal=<key2>=<val2></code></pre>
<h6>Config map using txt file</h6>
<p>
<ol>
<li>create a text file abc.txt</li>
<li>write : <br>ke1=value1<br>ke2=value2</li>
<li>save the file.</li>
<li>use command <pre><code class="language-git">kubectl create cm <resource-name> from-file=<file-name.txt></code></pre></li>
<li>
now mount it on pod as volume<br>
<b>Template</b><br>
<pre><code class=" language-markup">
kind: Pod
apiVersion: v1
metadata:
name: <pod-name>
spec:
volumes:
- name: <volume-name>
configMap:
name: <confifMap-name>
containers:
- name: <container-name>
image: <image>
ports:
- containerPort: 80
volumeMounts:
- name: <volume-name>
mountPath: /path/to/mount
</code></pre>
</li>
<li>create this pod any you are done.</li>
</ol>
</p>
<h6>Config map using env file</h6>
<p>
<ol>
<li>create a text file abc.env</li>
<li>write : <br>ke1=value1<br>ke2=value2</li>
<li>save the file.</li>
<li>use command <pre><code class="language-git">kubectl create cm <resource-name> from-env-file=<file-name.env></code></pre></li>
<li>
link a pod with configMap<br>
<b>Template</b><br>
<pre><code class=" language-markup">
kind: Pod
apiVersion: v1
metadata:
name: <pod-name>
spec:
containers:
- name: <container-name>
image: <image>
ports:
- containerPort: 80
envFrom:
- configMapRef:
name: <configMap-name>
</code></pre>
</li>
<li>create this pod any you are done.</li>
</ol>
</p>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="Secret" class="section-block">
<div class="code-block">
<h4>Secret</h4>
<p>
It is a resource that can hold some <b>secret</b> configurations that your app needs to run such as api keys, passwords, access tokens etc<br>
There are two types of secets.
<ol>
<li>One that can be made as text file and can be mounted on a pod as volume</li>
<li>One that can be made as env file and can be attached to a pod</li>
</ol>
</p>
<h6>Secret using cmd</h6>
<pre><code class="language-git">kubectl create secret generic <resource-name> --from-literal=<key1>=<val1> --from-literal=<key2>=<val2></code></pre>
<div class="callout-block callout-info">
<div class="icon-holder">
<i class="fas fa-bullhorn"></i>
</div><!--//icon-holder-->
<div class="content">
<h4 class="callout-title">Note:</h4>
<p>Method to write and create secreat env or txt file are same as configMap.<br><b>except:</b>
<h5 class="callout-title">when using env file:</h5>
<ul>
<li>use <code>secretRef:</code> instead of <code>configMapRef:</code> when creating Pod through <b>env</b> file.</li>
<li>use <code>kubectl create secret generic <resource-name> from-env-file=<file-name.env></code> command when creating through <b>env</b> file.</li>
</ul>
<br>
<h5 class="callout-title">when using txt file:</h5>
<ul>
<li>use <code>secret:</code> instead of <code>configMap:</code> & <code>secretName:</code> instead of <code>name:</code> when creating Pod through <b>txt</b> file.</li>
<li>use <code>kubectl create secret generic <resource-name> from-file=<file-name.txt></code> command when creating through <b>txt</b> file.</li>
</ul></p>
</div><!--//content-->
</div><!--//callout-->
</div><!--//code-block-->
</div><!--//section-block-->
</section><!--//doc-section-->
<section id="deployment" class="doc-section">
<h2 class="section-title">Deployment</h2>
<div class="section-block">
<p>
It is a resource of kuberenetes that helps us to deploy <b>update</b> application very easily by providing some strategies.
<br>basically it makes a replica-set and manages that. it does not interact with any pod directly. <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/">link to documentation</a>
</p>
</div><!--//section-block-->
<div id="deploy-template" class="section-block">
<div class="code-block">
<h6>Deployment basic template</h6>
<pre><code class="language-markup">
apiVersion: apps/v1
kind: Deployment
metadata:
name: <deployment-name>
labels: #optional
<key>: <value>
spec:
replicas: <number-of-pods>
selector: #optional
matchLabels:
<key>: <value>
template:
metadata:
labels: #optional
<key>: <value>
spec:
containers:
- name: <container-name>
image: <image>
ports:
- containerPort: 80
strategy:
type: <Recreate> or <RollingUpdate>
</code></pre>
<h5 id="Stratergies">Stratergies</h5>
<ul>
<li>
<h6>RollingUpdate</h6>
<p>
It is the default stratergy of kubernetes deployment, according to it when we update any thing one old pod is deleted and one updated pod is created this
process is repeated until all pods are replaced by newer version.
<br>we need to define some properties when using it. Those properties are listed below.
<ul>
<li>maxSurge ==> how many pods we can add at a time</li>
<li>maxUnavailable ==> maxUnavailable define how many pods can be unavailable during the rolling update</li>
</ul>
In the last it should look like:
<pre><code class=" language-markup">
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: <any-number>
maxUnavailable: <any-number>
</code></pre>
</p>
</li>
<li>
<h6>Recreate</h6>
<p>
In this strategy all pods all deleted at once and then newwer pods are created.<br>
in short your application have to face some down-time.
<br>In the last it should look like:
<pre><code class=" language-markup">
strategy:
type: Recreate
</code></pre>
</p>
</li>
</ul>
Other info about deployment can be found on the officilal <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/">link</a>.
</div><!--//code-block-->
</div><!--//section-block-->
</section><!--//doc-section-->
<section id="Others" class="doc-section">
<h2 class="section-title">Others</h2>
<div class="section-block">
<p>
Properties of kubernetes resources that can be added to any resource.
</p>
</div>
<div id="Labels" class="section-block">
<div class="code-block">
<h4>Labels</h4>
<p>
labels are key:value pair that help us to group different resources, we can perform different opperations on those resources using labels.<br>
labels are defined under metadata of a resource. There can be one or more labels of a resource.<br>
e.g type: frontend
</p>
<h6>Add label to running resource</h6>
<pre><code class="language-git">kubectl label <resource-type> <resource-name> <key>=<value></code></pre>
<h6>Remove label from a resource</h6>
<pre><code class="language-git">kubectl label <resource-type> <resource-name> <key>-</code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="Annotations" class="section-block">
<div class="code-block">
<h4>Annotations</h4>
<p>
Annotations are also key:value pair but it is used to give a describe a resource or give any information about the resource.<br>
annotations are also defined under metadata of a resource. There can be one or more labels of a resource.<br>
e.g purpose: "this resource can do _____ work"
</p>
<h6>Add annotation to running resource</h6>
<pre><code class="language-git">kubectl annotate <resource-type> <resource-name> <key>="<value>"</code></pre>
<h6>Remove annotation from a resource</h6>
<pre><code class="language-git">kubectl annotate <resource-type> <resource-name> <key>-</code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="Description-about-a-resource" class="section-block">
<div class="code-block">
<h4>Output | Info | Description about a resource</h4>
<p>
This command helps to get information about any resource in kubernetes in json or yaml format.
<br>it is mostly used to debug a resource.
</p>
<h6>output of a resource</h6>
<pre><code class="language-git">kubectl get <resource-type> <resource-name> -o <formet json or yaml></code></pre>
<h6>short useful description</h6>
<pre><code class="language-git">kubectl describe <resource-type> <resource-name></code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="Edit-a-resource-during-runtime" class="section-block">
<div class="code-block">
<h4>Edit a resource during runtime</h4>
<p>
This command helps to change or edit configuration or properties of a resource while it is running.
</p>
<h6>Edit a resource</h6>
<pre><code class="language-git">kubectl edit <resource-type> <resource-name></code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
<div id="Delete-a-resource" class="section-block">
<div class="code-block">
<h4>Delete a resource</h4>
<p>
This command deletes a resource.
</p>
<h6>Delete a resource</h6>
<pre><code class="language-git">kubectl delete <resource-type> <resource-name></code></pre>
</div><!--//code-block-->
</div><!--//section-block-->
</section><!--//doc-section-->
</div><!--//content-inner-->
</div><!--//doc-content-->
<div class="doc-sidebar col-md-3 col-12 order-0 d-none d-md-flex">
<div id="doc-nav" class="doc-nav">
<nav id="doc-menu" class="nav doc-menu flex-column sticky">
<a class="nav-link scrollto" href="#download-section">Download</a>
<a class="nav-link scrollto" href="#installation-section">Installation</a>
<nav class="doc-sub-menu nav flex-column">
<a class="nav-link scrollto" href="#step1">Step One</a>
<a class="nav-link scrollto" href="#step2">Step Two</a>
<a class="nav-link scrollto" href="#step3">Step Three</a>
<a class="nav-link scrollto" href="#step4">Step Four</a>
</nav><!--//nav-->
<a class="nav-link scrollto" href="#Pod">Pod</a>
<nav class="doc-sub-menu nav flex-column">
<a class="nav-link scrollto" href="#Pod-basic-template">Pod basic template</a>
<a class="nav-link scrollto" href="#Pod-using-cmd">Pod using cmd</a>
<a class="nav-link scrollto" href="#Port-forward-pod">Port forward pod</a>
<a class="nav-link scrollto" href="#List-pods">List pods</a>
</nav><!--//nav-->
<a class="nav-link scrollto" href="#ReplicaSet">ReplicaSet</a>
<nav class="doc-sub-menu nav flex-column">
<a class="nav-link scrollto" href="#RSet-basic-template">RSet basic template</a>
<a class="nav-link scrollto" href="#List-ReplicaSet">List ReplicaSet</a>
<a class="nav-link scrollto" href="#Scale-ReplicaSet">Scale ReplicaSet</a>
<a class="nav-link scrollto" href="#Delete-ReplicaSet">Delete ReplicaSet</a>
</nav>
<a class="nav-link scrollto" href="#Job">Job</a>
<a class="nav-link scrollto" href="#Cron-Job">Cron Job</a>
<a class="nav-link scrollto" href="#Service">Service</a>
<nav class="doc-sub-menu nav flex-column">
<a class="nav-link scrollto" href="#Service-basic-template">Service basic template</a>
<a class="nav-link scrollto" href="#Service-using-cmd">Service using cmd</a>
</nav>
<a class="nav-link scrollto" href="#Probes">Probes</a>
<nav class="doc-sub-menu nav flex-column">
<a class="nav-link scrollto" href="#Liveness-probe">Liveness probe</a>
<a class="nav-link scrollto" href="#Readiness-probe">Readiness probe</a>
</nav>
<a class="nav-link scrollto" href="#Volumes">Volumes</a>
<a class="nav-link scrollto" href="#persistent-Volumes">persistent Volumes</a>
<nav class="doc-sub-menu nav flex-column">
<a class="nav-link scrollto" href="#PV-basic-template">PV basic template</a>
<a class="nav-link scrollto" href="#PVC-basic-template">PVC basic template</a>
<a class="nav-link scrollto" href="#Pod-mounting-pv-basic-template">Pod mounting pv basic template</a>
</nav>
<a class="nav-link scrollto" href="#conf-deployment">Configuration</a>
<nav class="doc-sub-menu nav flex-column">
<a class="nav-link scrollto" href="#ConfigMap">ConfigMap</a>
<a class="nav-link scrollto" href="#Secret">Secret</a>
</nav>
<a class="nav-link scrollto" href="#deployment">Deployment</a>
<nav class="doc-sub-menu nav flex-column">
<a class="nav-link scrollto" href="#deploy-template">Deployment basic template</a>
<a class="nav-link scrollto" href="#Stratergies">Stratergies</a>
</nav>
<a class="nav-link scrollto" href="#Others">Others</a>
<nav class="doc-sub-menu nav flex-column">
<a class="nav-link scrollto" href="#Labels">Labels</a>
<a class="nav-link scrollto" href="#Annotations">Annotations</a>
<a class="nav-link scrollto" href="#Description-about-a-resource">Description about a resource</a>
<a class="nav-link scrollto" href="#Edit-a-resource-during-runtime">Edit a resource during runtime</a>
<a class="nav-link scrollto" href="#Delete-a-resource">Delete a resource</a>
</nav>
</nav><!--//doc-menu-->
</div>
</div><!--//doc-sidebar-->
</div><!--//doc-body-->
</div><!--//container-->
</div><!--//doc-wrapper-->
</div><!--//page-wrapper-->
<footer id="footer" class="footer text-center">
<div class="container">
<!--/* This template is released under the Creative Commons Attribution 3.0 License. Please keep the attribution link below when using for your own project. Thank you for your support. :) If you'd like to use the template without the attribution, you can buy the commercial license via our website: themes.3rdwavemedia.com */-->
<small class="copyright">Designed with <i class="fas fa-heart"></i> by <a href="https://github.com/umer2001" target="_blank">Umer Farooq</a> for developers</small>
</div><!--//container-->
</footer><!--//footer-->
<!-- Main Javascript -->
<script type="text/javascript" src="assets/plugins/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/plugins/prism/prism.js"></script>
<script type="text/javascript" src="assets/plugins/jquery-scrollTo/jquery.scrollTo.min.js"></script>
<script type="text/javascript" src="assets/plugins/stickyfill/dist/stickyfill.min.js"></script>
<script type="text/javascript" src="assets/js/main.js"></script>
</body>
</html>