Pod을 단독으로 만들면 Pod에 어떤 문제(서버가 죽어서 Pod이 사라졌다던가)가 생겼을 때 자동으로 복구되지 않습니다.
Pod을 정해진 수만큼 복제하고 관리하는 것이 ReplicaSet입니다.
ReplicaSet Manifests
https://dev-k8sref-io.web.app/docs/workloads/replicaset-v1/
nginx-rs.yaml
apiVersion: apps/v1 kind: ReplicaSet metadata: name: nginx-rs labels: app: myapp-rs type: front-end spec: template: metadata: name: nginx labels: app: myapp type: front-end spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80 selector: matchLabels: type: front-end replicas: 3
sansae@sansaeAir15m2 ~ % k apply -f nginx-rs.yaml replicaset.apps/nginx-rs created
sansae@sansaeAir15m2 ~ % k get all NAME READY STATUS RESTARTS AGE pod/nginx-rs-6dzx9 1/1 Running 0 91s pod/nginx-rs-kbkn8 1/1 Running 0 91s pod/nginx-rs-ml42r 1/1 Running 0 91s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 6h13m NAME DESIRED CURRENT READY AGE
Scale
$k replace -f nginx-rs.yaml $k scale --replicas=6 -f nginx-rs.yaml $k scale --replicas=6 rs nginx-rs sansae@sansaeAir15m2 ~ % k scale --replicas=6 rs nginx-rs replicaset.apps/nginx-rs scaled sansae@sansaeAir15m2 ~ % k get pod NAME READY STATUS RESTARTS AGE nginx-rs-6dzx9 1/1 Running 0 15m nginx-rs-7mrz2 1/1 Running 0 9s nginx-rs-hm85w 1/1 Running 0 9s nginx-rs-kbkn8 1/1 Running 0 15m nginx-rs-ml42r 1/1 Running 0 15m nginx-rs-shljn 1/1 Running 0 9s