Hello neighbors ^.^
Good morning to you.
Today, we will learn how to use Deployment, one of the Kubernetis controllers.
Deployment is a high-level concept workload resource for creating a pod and provides declarative updates for ReplicaSet and the Pod, as shown in the figure below. Declarative updates provide useful functions for updating versions of the Pod. There are several types of updates.
- RollingUpdate: Create/delete Pods sequentially according to established rules when updating
- Recreate: Update removes all existing Pods and creates new Pods
In addition, the following information can be used to control the process during Rolling Update. - Max Unavailable: Specifies the maximum number of pads unavailable during the update process (Default: 25%)
- Max Surge: Maximum number of pods that can be created (additional) for the number of intended pods (Default: 25%)
Now let's learn how to create, delete, and change Deployment.
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ vi test-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx-deployment
labels:
app: my-nginx
tier: frontend
spec:
replicas: 3
strategy:
type: RollingUpdate
selector:
matchLabels:
app: my-nginx
template:
metadata:
labels:
app: my-nginx
spec:
containers:
- image: nginx:1.19.3
name: my-nginx
ports:
- containerPort: 80
Above, the number of pods is maintained at 3, and the update method is set to Rolling Update.
2. I'll create it as below and look it up
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl apply -f test-deployment.yaml
deployment.apps/my-nginx-deployment created
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/my-nginx-deployment-55985c7fcf-hqsvp 1/1 Running 0 9s
pod/my-nginx-deployment-55985c7fcf-mj2vb 1/1 Running 0 10s
pod/my-nginx-deployment-55985c7fcf-pg9vl 1/1 Running 0 8s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/my-nginx-deployment 3/3 3 3 10s
NAME DESIRED CURRENT READY AGE
replicaset.apps/my-nginx-deployment-55985c7fcf 3 3 3 10s
As you can see above, when you create a deployment, the replicasets and pods set in the deployment are automatically generated as above.
3. If you look up the belts of the Pods, you can see that they are all created with the Lable set in Deployment.
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
my-nginx-deployment-55985c7fcf-hqsvp 1/1 Running 0 3m8s app=my-nginx,pod-template-hash=55985c7fcf
my-nginx-deployment-55985c7fcf-mj2vb 1/1 Running 0 3m9s app=my-nginx,pod-template-hash=55985c7fcf
my-nginx-deployment-55985c7fcf-pg9vl 1/1 Running 0 3m7s app=my-nginx,pod-template-hash=55985c7fcf
4. Delete one of the generated pods and query again.
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl get pod
NAME READY STATUS RESTARTS AGE
my-nginx-deployment-55985c7fcf-hqsvp 1/1 Running 0 8m16s
my-nginx-deployment-55985c7fcf-mj2vb 1/1 Running 0 8m17s
my-nginx-deployment-55985c7fcf-pg9vl 1/1 Running 0 8m15s
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl delete pod my-nginx-deployment-55985c7fcf-hqsvp
pod "my-nginx-deployment-55985c7fcf-hqsvp" deleted
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl get pod
NAME READY STATUS RESTARTS AGE
my-nginx-deployment-55985c7fcf-h4r2j 1/1 Running 0 3s
my-nginx-deployment-55985c7fcf-mj2vb 1/1 Running 0 8m33s
my-nginx-deployment-55985c7fcf-pg9vl 1/1 Running 0 8m31s
If you delete a Pod that has the hqsvp label, you can see that a new Pod called h4r2j is created.
In other words, it means Replicacet is working properly ^.^
5. Now let's change the quantity of replicaset with the command.
Use the command below to change to replicasset=4, which is the process of changing from 3 to 4 existing pods.
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl scale deployment my-nginx-deployment --replicas=4
deployment.apps/my-nginx-deployment scaled
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl get pod
NAME READY STATUS RESTARTS AGE
my-nginx-deployment-55985c7fcf-h4r2j 1/1 Running 0 3m2s
my-nginx-deployment-55985c7fcf-l4ctq 1/1 Running 0 5s
my-nginx-deployment-55985c7fcf-mj2vb 1/1 Running 0 11m
my-nginx-deployment-55985c7fcf-pg9vl 1/1 Running 0 11m
As you can see above, we have another new pod. This is the same process as modifying the YAML and then applying again. And you can modify it with the kubectl edit command.
If you look up all resources with the command below, you can see that the replica number has changed together.
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/my-nginx-deployment-55985c7fcf-h4r2j 1/1 Running 0 4m40s
pod/my-nginx-deployment-55985c7fcf-l4ctq 1/1 Running 0 103s
pod/my-nginx-deployment-55985c7fcf-mj2vb 1/1 Running 0 13m
pod/my-nginx-deployment-55985c7fcf-pg9vl 1/1 Running 0 13m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 22h
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/my-nginx-deployment 4/4 4 4 13m
NAME DESIRED CURRENT READY AGE
replicaset.apps/my-nginx-deployment-55985c7fcf 4 4 4 13m
replicaset.apps/nginx-replicaset 0 0 0 29m
6. Now let's delete the created Deploymen
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl delete deployments my-nginx-deployment
deployment.apps "my-nginx-deployment" deleted
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl get all
'Kubernetes' 카테고리의 다른 글
[Kubernetis] Managing Pod using Replicaset (98) | 2024.04.26 |
---|---|
[Kubernetis] Using Kubernetis service objects (99) | 2024.03.24 |
[Kubernetis] Access API with curl (95) | 2024.03.20 |
[Kubernetis] Building a MiniKube Environment on a Single Node (89) | 2024.03.16 |
[Cloud] 13. making kubernetes Helm Template (41) | 2023.02.13 |