|
7 | 7 |
|
8 | 8 | ## Resources
|
9 | 9 |
|
10 |
| - |
11 | 10 | - [Docker Mastery: with Kubernetes +Swarm from a Docker Captain](https://www.udemy.com/course/docker-mastery/) Udemy course.
|
12 | 11 | - [BretFisher/udemy-docker-mastery](https://github.com/BretFisher/udemy-docker-mastery) GitHub repo.
|
13 | 12 | - Kubernetes official [docs](https://kubernetes.io/docs/home/)
|
|
54 | 53 |
|
55 | 54 | We can add namespace attribute in YAMl file to specify with one it belongs to
|
56 | 55 |
|
57 |
| - |
58 | 56 | ```yaml
|
59 | 57 | apiVersion: v1
|
60 | 58 | kind: ConfigMap
|
@@ -82,10 +80,10 @@ kubectl create namespace dev
|
82 | 80 | Generally, A K8s YAML config file contains 4 properties
|
83 | 81 |
|
84 | 82 | ```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 |
89 | 87 | ```
|
90 | 88 |
|
91 | 89 | #### Labels and selectors
|
|
239 | 237 |
|
240 | 238 | <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">
|
241 | 239 |
|
242 |
| - |
243 |
| - |
244 | 240 | ### ConfigMap
|
245 | 241 |
|
246 | 242 | 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
|
285 | 281 |
|
286 | 282 | - Any application that stores data to keep it state, like database. In this the name and endpoint stays same when the pods restarted.
|
287 | 283 |
|
288 |
| - |
289 | 284 | ## Secret and ConfigMap as volume
|
290 | 285 |
|
291 | 286 | We can mount Config and Secret as a volume
|
@@ -333,10 +328,8 @@ data:
|
333 | 328 | log_type all
|
334 | 329 | log_timestamp_format %Y-%m-%dT%H:%M:%S
|
335 | 330 | listener 9001
|
336 |
| -
|
337 | 331 | ```
|
338 | 332 |
|
339 |
| - |
340 | 333 | ### Volume VS using it as a ENV.
|
341 | 334 |
|
342 | 335 | 
|
@@ -402,4 +395,66 @@ kubectl exec -it <pod-name> -c sidecar -- /bin/sh
|
402 | 395 | ```bash
|
403 | 396 | curl localhost:80
|
404 | 397 | ```
|
| 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 | + |
405 | 433 |
|
| 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 | +``` |
0 commit comments