ReplicaSet, Replication Controller

dongbin_Shin·2022년 11월 15일
0

kubernetes

목록 보기
10/16

3요소

Template

  • Pod를 재생성할 때, 어떤 Pod를 재생성할 지에 대한 template
  • Template을 update한 후 pod를 재생성하면 업데이트 된 버전으로 재생성함
    • 기존에 연결된 Pod들은 자동으로 변경되지 않음
  • Template에 Pod의 이름을 명시해도 replicas가 2 이상이면 ReplicaSet이름-랜덤값 의 이름으로 Pod가 생성됨
apiVersion: v1
kind: ReplicationController
metadata:
  name: replication-1
spec:
  replicas: 1
  selector:
    type: web
  **template:**
    metadata:
      name: pod-1
      labels:
        type: web
    spec:
      containers:
      - name: container
        image: something
apiVersion: v1
kind: Pod
metadata:
  name: pod-1
  labels:
    type: web
spec:
  containers:
  - name: container
    image: something

Replicas

  • ReplicaSet이 유지할 Pod의 갯수
  • 명시된 replicas보다 현재 Pod의 갯수가 많거나 적으면 scale out, scale in을 하여 갯수를 유지함
  • replicas와 template을 사용하면 별도의 Pod yaml 없이 pod를 생성할 수 있음

Selector

  • ReplicaSet에서 두가지의 추가 기능을 가짐
    • matchLabels
    • matchExpressions

Replication Contoller - selector, ReplicaSet - matchLabels

  • 명시된 Selector와 Pod에 명시된 label의 key, value가 모두 일치해야 연결

ReplicaSet - matchExpression

  • expression을 이용하여 더 디테일하게 선택 가능한 기능
  • key와 value가 달라도 expression에 만족하는 Pod을 연결
    apiVersion: apps/v1
    kind: ReplicaSet
    metadata:
      name: replica-1
    spec:
      replicas: 3
      **selector:**
        **matchLabels:
          type: web
        matchExpression:
        - {key: ver, operator: Exists}**
      template:
        metadata:
          name: pod
    ...
  • 옵션 종류
    • Exists
    • DoesNotExists
    • In
    • NotIn

참고) matchExpressions 기능은 기존에 있던 Object들을 디테일하게 선택하기 위해 사용하므로
Controller에서는 잘 사용하지 않고, Pod에서 node scheduling시에 대부분 사용하는 기능이다.

profile
멋있는 백엔드 개발자

0개의 댓글