지니데비 기록 자세히보기

데브옵스/Orchestration

[Kubernetes] 7. ReplicationController, ReplicaSet

지니데비 2024. 11. 5. 10:18
728x90

Pod yaml 파일형식
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels: 
    app: myapp
    type: front-end
spec:
  containers:
    - name: nginx-container
      image: nginx

기본 yaml  파일의 형식은 apiVersion, kind, metadata, spec 노드로 구성된다.

ReplicationController yaml 파일형식
apiVersion: v1
kind: ReplicationController
metadata
  name: myapp-rc
  labels:
    app: myapp
    type: front-end
spec:
  template:
    metadata:
      name: myapp-pod
      labels:
        app: myapp
        type: front-end
    spec:
      containers:
      - name: nginx-container
        image: nginx
  replicas: 3

※ spec 노드 하위에 template 노드에서 복제 대상 pod의 metadata 하위 부분이 그대로 들어가고, replicas 노드에 복제본 수를 명시한다.

 

Replicaset yaml 파일형식
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:
      containers:
      - name: nginx-container
        image: nginx
  replicas: 3
  selector:
    matchLabels:
      type: front-end

spec 노드 하위에 추가로 selector 노드가 추가된다.

 

command
kubectl create -f replicaset-definition.yaml
kubectl get replicaset
kubectl delete replicaset myapp-replicaset #복제된 pod도 함께 삭제됨

kubectl edit rs [replicaset name] #복제된 pod 삭제해야 새로 만들어짐

## Scale (1)
vi replicaset-definition.yaml
kubectl replace -f replicaset-definition.yaml


## Scale (2)
kubectl scale --replicas=6 -f replicaset-definition.yaml


## Scale (3)
kubectl scale --replicas=6 [type] [name]
kubectl scale --replicas=6 replicaset myapp-replicaset

 

728x90
반응형