728x90
반응형
ReplicationController
정의
- 요구하는 Pod의 개수를 보장하며 파드 집합의 실행을 항상 안정적으로 유지하는 것을 목표
- 요구하는 Pod의 개수가 부족하면 template 이용해 Pod를 추가
- 요구하는 Pod 수 보다 많으면 최근에 생성된 Pod를 삭제
- 기본 구조
- selector
- replicas
- template
실행방법
생성
replicas를 3으로 설정하고 3개의 pod를 생성
root@master:~# cat > rc-nginx.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: rc-nginx
spec:
replicas: 3
selector:
app: webui
template:
metadata:
name: nginx-pod
labels:
app: webui
spec:
containers:
- name: nginx-container
image: nginx:1.14
root@master:~# kubectl get pods -o wide
No resources found in default namespace.
root@master:~# kubectl create -f rc-nginx.yaml
replicationcontroller/rc-nginx created
root@master:~# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
rc-nginx-cdlxb 0/1 ContainerCreating 0 3s <none> node1.example.com <none> <none>
rc-nginx-cgsgj 0/1 ContainerCreating 0 3s <none> node1.example.com <none> <none>
rc-nginx-v5mbf 0/1 ContainerCreating 0 3s <none> node2.example.com <none> <none>
조회
root@master:~# kubectl get rc -o wide
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
rc-nginx 3 3 3 3m52s nginx-container nginx:1.14 app=webui
replicas 개수 수정 (edit 명령어)
3개에서 2개로 수정하고 나서 조회해보자
root@master:~# kubectl edit rc rc-nginx
########################################################################################
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: ReplicationController
metadata:
creationTimestamp: "2021-11-19T11:50:11Z"
generation: 1
labels:
app: webui
name: rc-nginx
namespace: default
resourceVersion: "75124"
uid: 6f7dcbd8-9a8f-435a-a1fa-3f9308a6f55d
spec:
replicas: 2
selector:
app: webui
template:
metadata:
creationTimestamp: null
labels:
app: webui
name: nginx-pod
spec:
containers:
- image: nginx:1.14
imagePullPolicy: IfNotPresent
name: nginx-container
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 3
fullyLabeledReplicas: 3
observedGeneration: 1
readyReplicas: 3
replicas: 3
########################################################################################
root@master:~# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
rc-nginx-cgsgj 1/1 Running 0 5m26s 10.36.0.1 node1.example.com <none> <none>
rc-nginx-v5mbf 1/1 Running 0 5m26s 10.44.0.1 node2.example.com <none> <none>
root@master:~# kubectl get rc -o wide
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
rc-nginx 2 2 2 5m29s nginx-container nginx:1.14 app=webui
replicas 개수 수정 (scale 명령어)
root@master:~# kubectl scale rc rc-nginx --replicas=5
replicationcontroller/rc-nginx scaled
root@master:~# kubectl get rc -o wide
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
rc-nginx 5 5 5 6m43s nginx-container nginx:1.14 app=webui
root@master:~# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
rc-nginx-8wnzt 1/1 Running 0 8s 10.44.0.2 node2.example.com <none> <none>
rc-nginx-cgsgj 1/1 Running 0 6m46s 10.36.0.1 node1.example.com <none> <none>
rc-nginx-h2n5l 1/1 Running 0 8s 10.44.0.3 node2.example.com <none> <none>
rc-nginx-ps97l 1/1 Running 0 8s 10.36.0.2 node1.example.com <none> <none>
rc-nginx-v5mbf 1/1 Running 0 6m46s 10.44.0.1 node2.example.com <none> <none>
파드 개수 보장 확인
생성된 rc-nginx에서 임의의 pod 한개를 삭제하였을 때 설정된 개수만큼 다시 재생성되는지 확인
root@master:~# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
rc-nginx-8wnzt 1/1 Running 0 37s 10.44.0.2 node2.example.com <none> <none>
rc-nginx-cgsgj 1/1 Running 0 7m15s 10.36.0.1 node1.example.com <none> <none>
rc-nginx-h2n5l 1/1 Running 0 37s 10.44.0.3 node2.example.com <none> <none>
rc-nginx-ps97l 1/1 Running 0 37s 10.36.0.2 node1.example.com <none> <none>
rc-nginx-v5mbf 1/1 Running 0 7m15s 10.44.0.1 node2.example.com <none> <none>
root@master:~# kubectl get replicationcontrollers
NAME DESIRED CURRENT READY AGE
rc-nginx 5 5 5 7m39s
root@master:~# kubectl delete pod rc-nginx-v5mbf
pod "rc-nginx-v5mbf" deleted
root@master:~# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
rc-nginx-8wnzt 1/1 Running 0 2m26s 10.44.0.2 node2.example.com <none> <none>
rc-nginx-9p8jc 1/1 Running 0 5s 10.36.0.3 node1.example.com <none> <none>
rc-nginx-cgsgj 1/1 Running 0 9m4s 10.36.0.1 node1.example.com <none> <none>
rc-nginx-h2n5l 1/1 Running 0 2m26s 10.44.0.3 node2.example.com <none> <none>
rc-nginx-ps97l 1/1 Running 0 2m26s 10.36.0.2 node1.example.com <none> <none>
rc-nginx-v5mbf 라는 임의의 파드를 삭제하였지만 다시 rc-nginx-9p8jc 라는 파드가 재생성되었음을 확인할 수 있다.
728x90
반응형
'DevOps > Kubernetes' 카테고리의 다른 글
Kubernetes - StatefulSet (0) | 2021.11.22 |
---|---|
Kubernetes - ReplicaSet (0) | 2021.11.21 |
Kubernetes - pod resource 요청 및 제한 (0) | 2021.11.18 |
Kubernetes - static Pod (정적 파드) (0) | 2021.11.18 |
Kubernetes - namespace (네임스페이스) (0) | 2021.11.15 |