728x90
반응형
Hello neighbors ^.^
For today's post, let's learn how to manage your Pod using Replicaset.
ReplicaSet's purpose is to keep the execution of the replica pod set (replicated copies of the pod) stable at all times. To maintain a fixed number of pods, we look at the status of the objects and if there is a difference between Spec and Status, we take action to bring them back together.
- ReplicaSet's Spec contains the following information.
- replicas : Number of Pods to be maintained
- selector : How to identify obtainable pods (how to select pods managed by ReplicaSet)
- template : the data used to generate the pod (the metadata and spec of the pod)
- Now let's create an Rplicaset.
- 1. Create the yaml file below with vi.
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ vi test-replicaset.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx-replicaset
labels: ==> Replcaset에서 관리 하는 Pod들의 Label
app: my-nginx
tier: frontend
spec:
replicas: 3 ==> 유지해야 되는 Pod 수
selector:
matchLabels:
app: my-nginx
template:
metadata:
labels:
app: my-nginx
name: my-nginx
spec:
containers:
- image: nginx:1.19.3
name: my-nginx
ports:
- containerPort: 80
2. Create Replicaset with the command below and look it up.
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl apply -f test-replicaset.yaml
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-replicaset-cfs2w 1/1 Running 0 56s 172.17.0.8 ip-172-31-31-84 <none> <none>
nginx-replicaset-rt5h2 1/1 Running 0 56s 172.17.0.9 ip-172-31-31-84 <none> <none>
nginx-replicaset-shkn6 1/1 Running 0 56s 172.17.0.10 ip-172-31-31-84 <none> <none>
3. Now let's delete the Pod and see how Replicaset works.
Delete one pod with the command below and look it up.
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-replicaset-cfs2w 1/1 Running 0 56s 172.17.0.8 ip-172-31-31-84 <none> <none>
nginx-replicaset-rt5h2 1/1 Running 0 56s 172.17.0.9 ip-172-31-31-84 <none> <none>
nginx-replicaset-shkn6 1/1 Running 0 56s 172.17.0.10 ip-172-31-31-84 <none> <none>
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl delete pod nginx-replicaset-cfs2w
pod "nginx-replicaset-cfs2w" 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 -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-replicaset-hnr24 1/1 Running 0 4s 172.17.0.3 ip-172-31-31-84 <none> <none>
nginx-replicaset-rt5h2 1/1 Running 0 2m40s 172.17.0.9 ip-172-31-31-84 <none> <none>
nginx-replicaset-shkn6 1/1 Running 0 2m40s 172.17.0.10 ip-172-31-31-84 <none> <none>
As you can see above, if you delete cfs2w, the first Pod, you create hnr24 for another new Pod and match the number of Pod set in Rplicaset.
It's working well.. so that's it for today ^.^
728x90
반응형
'Kubernetes' 카테고리의 다른 글
[Kubernetis]How to manage Deployment Controller (106) | 2024.04.06 |
---|---|
[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 |