ReplicaSets

ํŒŒใ…ฃ

ํ•˜๋‚˜์˜ ํŒŒ๋“œ๊ฐ€ ์žฅ์•  ๋‚ฌ์„ ๋•Œ ๋ณต์ œ ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ๋ณต๊ตฌ๋„ ํ•  ์ˆ˜ ์žˆ๋‹ค.

  • LB & ์Šค์ผ€์ผ๋ง ์šฉ๋„

Replication Controller & Replica Set

Replication Controller : ๊ตฌํ˜•

Replica Set : ์‹ ํ˜• (๊ถŒ์žฅ)

replication Controller ์ƒ์„ฑ ๋ฐฉ๋ฒ•

pod ํƒฌํ”Œ๋ฆฟ์„ ์ง€์ •ํ•ด์„œ ์ƒ์„ฑํ•œ๋‹ค.

# ์—์ œ
apiVersion: v1
kind: ReplicationController
metadata:
  name: myapp-rc
  label:
    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

Replica Sets ์ƒ์„ฑ ๋ฐฉ๋ฒ•

replicaset-sefinition.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  

selector ํ•„์ˆ˜

# ReplicaSet ์ƒ์„ฑ
kubectl create -f replicaset-sefinition.yaml

# ReplicaSet ํ™•์ธ
kubectl get replicaset

# ReplicaSet๋กœ ๋งŒ๋“  pod ํ™•์ธ
kubectl get pods

Labels and Selectors

์‹คํ–‰ ์ค‘์ธ pod์— ๋ผ๋ฒจ์„ ๋ถ€์—ฌํ•˜์—ฌ ReplicaSet์ด ๋ชจ๋‹ˆํ„ฐ๋ง ํ•  ์ˆ˜ ์žˆ๋‹ค.

์‹คํ–‰์ค‘์ธ pod๊ฐ€ ๊ต‰์žฅํžˆ ๋งŽ์€ ๊ฒฝ์šฐ ์œ ์šฉํ•˜๋‹ค

Scale

replicas ๋ฅผ ๋Š˜๋ฆฌ๋Š” ๋ฐฉ๋ฒ•

replicaset-sefinition.yaml
...
replicas: 6
...
kubectl replace -f replicaset-sefinition.yaml

ํŒŒ์ผ ๋‚ด์šฉ ๊ธฐ๋ฐ˜์œผ๋กœ Replicaset์„ ๊ต์ฒดํ•œ๋‹ค. ๊ธฐ์กด์˜ replicaset์ด ์ œ๊ฑฐ๋˜๊ณ  ์ƒˆ๋กญ๊ฒŒ ์ƒ์„ฑ๋˜์–ด ์„œ๋น„์Šค ์ค‘๋‹จ์ด ๋ฐœ์ƒ ํ•  ์ˆ˜์žˆ๋‹ค.

kubectl scale --replicas=6 -f replicaset-sefinition.yaml

ํ•ด๋‹น ํŒŒ์ผ์„ ์ฐพ์•„ replicas ์ˆ˜๋ฅผ 6์œผ๋กœ ์กฐ์ •ํ•˜๋‚˜ ํŒŒ์ผ์— ์ •์˜๋œ replicas๋Š” ์ˆ˜์ •๋˜์ง€ ์•Š์Œ

kubectl scale --replicas=6 replicaset myapp-replicaset

์ด๋ฆ„์ด myapp-replicaset์ธ ํŠน์ • replicaset์˜ replicas ์ˆ˜๋ฅผ 6์œผ๋กœ ์กฐ์ •ํ•œ๋‹ค.

command

kubectl create -f replicaset-definition.yaml

kubectl get replicaset

kubectl delete replicaset [name]

kubectl replace -f replicaset-definition.yml

kubectl scale --replicas=6 -f replicaset-definition.yaml

Last updated