Kubernetes

[Kubernetis] Managing Pod using Replicaset

트리스탄1234 2024. 4. 26. 05:14
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
반응형