본문 바로가기
K8S

ReplicaSet (ReplicationController와 차이점)

by ohrohi 2025. 2. 7.
반응형
  • ReplicaSet은 ReplicationController와 똑같은 역할(Pod의 갯수 보장)
    • selector
      • matchLabels:
        • 형식: component: redis
      • matchExpressions:
          • {key: tier, operator: In, values: [cache]}
          • {key: environment, operator: NotIn, values: [dev]}
      • matchExpressions 연산자
        • In: key와 values를 지정하여 key, value가 일치하는 pod만 연결
        • NotIn: key는 일치하고 value는 일치하지 않는 Pod에 연결
        • Exists: key에 맞는 label의 Pod를 연결
        • DoseNotExist: key와 다른 label의 Pod를 연결
In Exists
spec:
replicas: 3

selector:
matchExpressions:
- {key: version, operator: In, value: [”1.14”]}

template:
spec:
replicas: 3

selector:
matchExpressions:
- {key: version, operator: Exists}

template:

 

  • 정의
ReplicationContorller-definition (정의) Replicaset definition (정의)
apiVersion: v1
kind: ReplicationController
metadata:
name: rc-nginx

spec:
  replicas: 3
  selector:
    app: webui
  template:
    metadata:
      name: nginx-pod
      labels:
        app: webui

spec:
containers:
- name: nginx-container
image: nginx:1.14
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: rs-nginx
spec:
  replicas: 3
  selector:
    matchLabels:
    app: webui
  template:
    metadata:
      name: nginx-pod
      labels:
        app: webui
  spec:
    containers:
      - name: nginx-container
        image: nginx:1.14
  • 컨트롤러만 삭제 하고 Pod는 삭제 안하는 방법
# kubectl delete rs [rs 명] **--cascade=false
--cascade=false : 연쇄 삭제 기능을 비활성화 (default=true)**
반응형