Skip to content

Commit f2d54e4

Browse files
committed
docs: Added notes to k8s
1 parent dfc8baf commit f2d54e4

File tree

4 files changed

+112
-11
lines changed

4 files changed

+112
-11
lines changed

Kubernetes/README.md

+66-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
## Resources
99

10-
1110
- [Docker Mastery: with Kubernetes +Swarm from a Docker Captain](https://www.udemy.com/course/docker-mastery/) Udemy course.
1211
- [BretFisher/udemy-docker-mastery](https://github.com/BretFisher/udemy-docker-mastery) GitHub repo.
1312
- Kubernetes official [docs](https://kubernetes.io/docs/home/)
@@ -54,7 +53,6 @@
5453

5554
We can add namespace attribute in YAMl file to specify with one it belongs to
5655

57-
5856
```yaml
5957
apiVersion: v1
6058
kind: ConfigMap
@@ -82,10 +80,10 @@ kubectl create namespace dev
8280
Generally, A K8s YAML config file contains 4 properties
8381

8482
```YAML
85-
apiVersion:
86-
kind:
87-
metadata:
88-
spec:
83+
apiVersion: # Which version of the API you are using
84+
kind: # What kind of object you are creating
85+
metadata: # Data about the object
86+
spec: # What you want the object to look like
8987
```
9088
9189
#### Labels and selectors
@@ -239,8 +237,6 @@ TLS
239237

240238
<img width="1512" alt="Screenshot 2022-11-14 at 1 17 55 PM" src="https://user-images.githubusercontent.com/51878265/201604299-264768c3-e5b1-48fa-9bc1-3762a3052006.png">
241239

242-
243-
244240
### ConfigMap
245241

246242
Use to store external configurations like database URLs. We put it in simple text format unlike [Secrets](#secrets)
@@ -285,7 +281,6 @@ echo cHJhZHVtbmE | base64 --decode
285281

286282
- Any application that stores data to keep it state, like database. In this the name and endpoint stays same when the pods restarted.
287283

288-
289284
## Secret and ConfigMap as volume
290285

291286
We can mount Config and Secret as a volume
@@ -333,10 +328,8 @@ data:
333328
log_type all
334329
log_timestamp_format %Y-%m-%dT%H:%M:%S
335330
listener 9001
336-
337331
```
338332

339-
340333
### Volume VS using it as a ENV.
341334

342335
![Env vs Volume mount](https://user-images.githubusercontent.com/51878265/202616618-c536bbd6-e221-4df9-b57d-8969dc1504a8.png)
@@ -402,4 +395,66 @@ kubectl exec -it <pod-name> -c sidecar -- /bin/sh
402395
```bash
403396
curl localhost:80
404397
```
398+
## Updating Strategy
399+
400+
Updating means chnaging the image of the pod.
401+
402+
### Rolling Update
403+
404+
The pods are updated one by one, so the service is not down. But the new pods are created with the new image and then the old pods are deleted.
405+
406+
```yaml
407+
apiVersion: apps/v1
408+
kind: Deployment
409+
metadata:
410+
name: nginx-deployment
411+
spec:
412+
replicas: 5
413+
strategy:
414+
type: RollingUpdate
415+
rollingUpdate:
416+
maxSurge: 1 # 1 pod can be created above the desired number of pods. By default it is 25%
417+
maxUnavailable: 1 # 1 pod can be unavailable during the update. By default it is 25%
418+
selector:
419+
matchLabels:
420+
app: nginx-app
421+
template:
422+
metadata:
423+
labels:
424+
app: nginx-app
425+
spec:
426+
containers:
427+
- name: myapp
428+
image: nginx:1.23.2
429+
ports:
430+
- containerPort: 80
431+
```
432+
405433

434+
### Recreate
435+
436+
The pods are deleted and then new pods are created. So the service is down for a while.
437+
438+
```yaml
439+
apiVersion: apps/v1
440+
kind: Deployment
441+
metadata:
442+
name: nginx-deployment
443+
spec:
444+
replicas: 5
445+
strategy:
446+
type: Recreate # It will delete all the pods and then create new ones
447+
selector:
448+
matchLabels:
449+
app: nginx-app
450+
template:
451+
metadata:
452+
labels:
453+
app: nginx-app
454+
spec:
455+
containers:
456+
- name: myapp
457+
image: nginx:1.23.3
458+
ports:
459+
- containerPort: 80
460+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: nginx-deployment
5+
spec:
6+
replicas: 5
7+
strategy:
8+
type: Recreate # It will delete all the pods and then create new ones
9+
selector:
10+
matchLabels:
11+
app: nginx-app
12+
template:
13+
metadata:
14+
labels:
15+
app: nginx-app
16+
spec:
17+
containers:
18+
- name: myapp
19+
image: nginx:1.23.3
20+
ports:
21+
- containerPort: 80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: nginx-deployment
5+
spec:
6+
replicas: 5
7+
strategy:
8+
type: RollingUpdate
9+
rollingUpdate:
10+
maxSurge: 1 # 1 pod can be created above the desired number of pods
11+
maxUnavailable: 1 # 1 pod can be unavailable during the update
12+
selector:
13+
matchLabels:
14+
app: nginx-app
15+
template:
16+
metadata:
17+
labels:
18+
app: nginx-app
19+
spec:
20+
containers:
21+
- name: myapp
22+
image: nginx:1.23.2
23+
ports:
24+
- containerPort: 80

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<img align="right" src="https://user-images.githubusercontent.com/51878265/205495495-b3f0b395-3ce3-42d8-9274-220ff10334f6.png" height="120" alt="YAML">
107107

108108
- [Notes](ArgoCD/README.md)
109+
- [Manifest Files](https://github.com/Pradumnasaraf/DevOps/tree/main/ArgoCD/YAML)
109110

110111
<br>
111112
<br>

0 commit comments

Comments
 (0)