Core-Concepts/29/Replicas

y001·2025년 2월 9일
post-thumbnail

Replica Set

Replication Controller는 예전 방식이며, 현재는 Replica Set을 사용하는 것이 일반적이다.
Replica Set은 라벨을 이용해 기존 Pod을 관리할 수도 있고, 새로운 Pod을 생성할 수도 있다.
✔ YAML 파일을 이용해 생성 및 관리하는 것이 일반적이며, kubectl scale을 사용하여 동적으로 Pod 개수를 조절할 수 있다.

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: my-app-rs
  labels:
    app: my-app
spec:
  replicas: 3  # 실행할 Pod 개수
  selector:
    matchLabels:
      app: my-app  # 이 라벨을 가진 Pod을 관리
  template:  # 새롭게 생성될 Pod의 정의
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app-container
          image: nginx

주요 kubectl 명령어 정리

  • kubectl get rs : Replica Set 목록 조회
  • kubectl delete rs my-app-rs : 특정 Replica Set 삭제
  • kubectl scale --replicas=6 -f replicaset.yaml : Replica Set을 통해 Pod 개수 변경

0개의 댓글