Recap-ReplicaSets

2023. 4. 10. 20:23Kubernetes

Replication Controller 는 하나의 pod에서 여러개의 인스턴스를 실행하도록 도와준다. 

 

pod가 하나일때도, pod가 고장나면 Replication Controller는 자동으로 새 pod를 불러올수있다.

 

Replication Controller

1. 여러 pod로 로드를 나눌 수있다.

2. 여러 노드에 걸쳐 pod 의 부하를 분산할 수있다. (Load balancing)

3. App scale 도 조정할 수있다.(Scaling)

 

Replication Controller , Replica Set 

둘을 구분해야 하는데, 

Replication Controller 는 구식 기술로 Replica Set 으로 대체 되고 있다.

Replication Controller 를 생성하는 방법은 

yml 로 만들수 있다.

#rc-defintion.yml
apiVersion:v1
kind:ReplicationController #대소문자 구분 중요!
metadata: 
  name: myapp-rc
  labels:
    	app: myapp
        type: frontend
        
spec:
  template:
  # 이 밑은 pod-definition.yml 에서 metadata 아래부분을 긁어온다.
    metadata: 
	  name: myapp-pod
      labels:
        app: myapp
        type: front-end
        
    spec:
      container:
        -name: nginx-container # - 가 들어가는 이유는 list의 첫번째 item이기 때문이다.
         image: nginx
  replicas: 3
#pod-definition.yml
apiVersion:v1
kind:Pod #대소문자 구분 중요!
metadata: 
	name: myapp-pod
    labels:
    	app: myapp
        type: front-end
        
spec:
	container:
    	-name: nginx-container # - 가 들어가는 이유는 list의 첫번째 item이기 때문이다.
         image: nginx

아래 명령어로 RC 생성 가능 

#rc생성법
kubectl create -f rc-defintion.yml

#rc 보는법
kubectl get replicationcontroller

 

Replica Set 

apiVersion:apps/v1
kind:ReplicaSet
metadata:
  name: myapp-replicaset
  labels:
    app: myapp
    type: front-end
spec:
  template:
    metadata: 
	name: myapp-pod
    labels:
    	app: myapp
        type: front-end
        
    spec:
      container:
        -name: nginx-container # - 가 들어가는 이유는 list의 첫번째 item이기 때문이다.
         image: nginx
  replicas: 3
  selector: # 그 밑에 어떤 pod 가 있을지 결정함. replicaset 으로 만들지 않은 pod도 관리가능하기 때문
    matchLabels:
      type: front-end

selector 가 RC 와 RS 의 큰 차이점이다. 

RC(ReplicationController) 는 selector 이용이 가능하나, 필수는 아니다.

RS (ReplicaSet)는 selector가 필수이며, 많은 옵션을 제공한다. 

# 생성법
kubectl create -f replicaset-defintion.yml

# 보는법
kubectl get replicaset

ReplicaSet 은 Selector 로 수많은 pod들 중 특정 pod만 모니터링 할수있다. 

 

replicaSet 에서 replicas 갯수 늘리는법 2가지

1.

1) yml 파일에 replicas 수 변경 

2) kubectl replace -f replicaset-defintion.yml 실행 

 

2. kubectl scale --replicas=6 -f replicaset-defintion.yml

 

3. kubectl scale --replicas=6 <kind> <name>

ex) kubectl scale --replicas=6 replicaset myapp-replicaset

 

replicaset 에 이미지명 busybox로 바꾸기 

kubectl set image rs/new-replica-set busybox-container=busybox

 

특정 label selector 를 가진 pod들 삭제하기 (label selector정보는 replicaset에 있음)

kubectl delete pod -l name=busybox-pod

'Kubernetes' 카테고리의 다른 글

Cluster IP  (0) 2023.04.17
Test-replicaSet  (0) 2023.04.12
Pods with YAML  (0) 2023.04.09
Recap -Pods  (0) 2023.04.09
Kube-Proxy  (0) 2023.04.08