Kubernetes

[Cloud] 4. Kubernetes Replicaset deployment

트리스탄1234 2023. 1. 24. 08:26
728x90
반응형

As the controllers to manage Pods in a kubernetes cluster, there are controllers named Deplotment and Replcaset. Among them, let's look at Rplicaset first.

Replicaset is an improved version of the replica controller, and its main roles are as follows.

  • Select the target Pod to manage using the Label value
  • Control the number of operating pods of the selected Pods

For example, after selecting a target pod by using the label selector value among dozens of pods in the cluster, it continuously monitors and creates a new pod when a pod fails and deletes the failed Pod while maintaining the service.

반응형

Then, create a replacset directory under the test directory, create a yaml file, enter the following content into the file, save it, and then run the distribution.

root@master-VirtualBox:~/test# mkdir replicaset
root@master-VirtualBox:~/test# cd replicaset/
root@master-VirtualBox:~/test# mkdir replicaset
root@master-VirtualBox:~/test# cd replicaset/
root@master-VirtualBox:~/test/replicaset# vi replicaset.yaml
apiVersion: apps/v1
kind: ReplicaSet ==> define deployed Object
metadata:
name: my-nginx
labels:
app: nginx ==> Label value of target Pod
spec:
replicas: 3 ==> quantity of Pod in Label
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.10

Now, let's deploy and inquire the information of the deployed replicaset, and inquire the information of the Pod.

root@master-VirtualBox:~/test/replicaset# kubectl apply -f replicaset.yaml
replicaset.apps/my-nginx created
root@master-VirtualBox:~/test/replicaset# kubectl get replicasets
NAME DESIRED CURRENT READY AGE
my-nginx 3 3 0 32s
root@master-VirtualBox:~/test/replicaset# kubectl get pods
NAME READY STATUS RESTARTS AGE
my-nginx-gblrg 1/1 Running 0 67s
my-nginx-k2thq 1/1 Running 0 67s
my-nginx-nfz4k 1/1 Running 0 67s

As shown in the information set in yaml above, you can see that 3 Pods have been deployed and all are in a normal state.

Let's take a closer look at how replicaset works. Node1's Pod is different from Replicaset's Label value. Under the assumption that Pod B has the same label, if Node 1 fails. Pod B is recreated and operational on Node 2 by replicaset, but Pod A is not failover.

The figure below shows how replcest works in flowchart format.

  • Find the Pod that has the same value as the Label and register it in the target list
  • Compare the number of replica pods in YAML file with the number of Pods in operation
  • The number of running Pods is small, creating a shortage
  • If the number of running Pods is high, delete the excess

728x90
반응형

'Kubernetes' 카테고리의 다른 글

[Cloud] 6. Kubernetes Service deploy  (24) 2023.02.01
[Cloud] 5. Kubernetes Deployment deploy  (29) 2023.01.30
[Cloud] 3.Kuberdnetes Pod deploy  (14) 2022.12.25
[Cloud] 2. Kubernetes namespace  (11) 2022.12.25
[Cloud] 1. Kubernetes Installation  (9) 2022.12.25