apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: echo-rs
spec:
  replicas: 1
  selector:
    matchLabels:
      app: echo
      tier: app
  template:
    metadata:
      labels:
        app: echo
        tier: app
    spec:
      containers:
        - name: echo
          image: nginx:latest

ReplicaSet 형태

image.png

ReplicaSet은 label을 체크해서 원하는 수의 Pod이 없으면 새로운 Pod을 생성합니다. 이를 설정으로 표현하면 다음과 같습니다.

정의 설명
spec.selector label 체크 조건
spec.replicas 원하는 Pod의 개수
spec.template 생성할 Pod의 명세
metadata:
  labels:
    app: echo
    tier: app
spec:
  containers:
    - name: echo
      image: nginx:latest
kubectl get pod --show-labels
kubectl label pod/echo-rs-<random> app-

# 다시 Pod 확인
kubectl get pod --show-labels
NAME            READY   STATUS    RESTARTS   AGE   LABELS
echo-rs-tcdwj   1/1     Running   0          3m    tier=app
echo-rs-kv4mh   1/1     Running   0          5s    app=echo,tier=app
kubectl label pod/echo-rs-<random> app=echo

# 다시 Pod 확인
kubectl get pod --show-labels