오늘도 한 뼘 더

[k8s] Replica Set(레플리카셋) 본문

DevOps & Infra/K8S(Kubernetes)

[k8s] Replica Set(레플리카셋)

나른한댕댕이🐶 2022. 12. 14. 10:06
728x90
반응형

Replica Set(레플리카셋)

  • 일정 개수의 포드를 유지하는 컨트롤러 역할
  • 노드 장애 등의 이유로 포드를 사용할 수 없다면 다른 노드에서 포드를 생성할 수 있도록 한다.
  • yaml 파일에 여러 개의 리소를 만들도록 지정할 수 있으나 이는 포드 개수를 유지하는 방법은 아니다.

레플리카 셋 사용 전

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod-a
spec:
  containers:
  - name: nginx-container
    image: nginx:latest
    ports:
    - containerPort: 80
      protocol: TCP

---
apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod-b
spec:
  containers:
  - name: nginx-container
    image: nginx:latest
    ports:
    - containerPort: 80
      protocol: TCP

레플리카셋 사용하기

apiVersion: app/v1
kind: ReplicaSet
metadata:
  name: nginx-replicaset
spec:                           |
  replicas: 2                   |
  selector:                     |  //레플리카 셋 정의
    matchLabels:                |
      app: nginx-pods-label     |
  template:                     ||  // 여기서부터는 포드 정의
    metadata:                   ||  
      name: nginx-pod
      labels:
        app: nginx-pods-label
    spec:
      containers:
      - name: nginx-container
        image: nginx:latest
        ports:
        - containerPort: 80
      protocol: TCP
  • spec.replicas : replica 몇 개를 만들지
  • spec.selector.matchLabels : 레플리카셋에서 어떤 포드를 관리할지를 라벨로 정의한다.
728x90
반응형
Comments