[Kubernetes] Controller 소개

2024. 3. 7. 20:56·🔹Kubernetes
728x90
SMALL
  • 정의
    • Pod 개수 보장
    • 실행 안정적 유지

ReplicationController

 

  • 생성 명령어
kubectl create rc-exam --image=nginx --replicas=3 --selector=app-webui

 

  • 갯수를 살펴봐서 많으면 pod 를 죽이고, 부족하면 새로 생성해준다
kubectl edit rc rc-nginx 
# 'replicas: '부분을 변경, 실행 중인 pod 개수 변경 (3->4)
# 다른 부분 (예시, image: nginx:1.15) 변경은 적용되지 않는다
# # 변경 사항을 적용하려면, kubectl delete 로 삭제하라.
# # 다시 생성될 것이다
kubectl scale rc rc-nginx —replicas=2
# 4개가 강제적으로 2개로 줄어듬
kubectl delete rc rc-nginx
# pod 만 삭제하는 것은 의미 없으므로, Replication Controller 자체를 삭제

 


ReplicationSet

  • 풍부한 Selector 지원
selector:
  matchLabels:
    component: redis
  matchExpressions:
    - {key: version, operator: Exists}
  • 예시 yaml file
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
  • 삭제 시 relicaset 만 삭제하려 할 경우
kubectl delete rs rs-nginx --cascade=false

Deployment

  • ReplicaSet 을 컨트롤 해서 Pod 수 조절

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-deploy
spec:
  selector:
    matchLabels:
      app: webui
  replicas: 3
  template:
    metadata:
      labels:
        app: webui
    spec:
      containers:
      - name: web
        image: nginx:1.14
        ports:
        - containerPort: 80
  • deploy
#파일 생성 뒤 
kubectl create -f
#파일 수정 뒤 
kubectl apply -f
  • Rolling Update
kubectl set image deployment <deploy_name> <container_name>=<new_version_image>

kubectl set image deployment app-deploy web=nginx:1.15 --record
#version update 시킴
#record 작성 중요
  • RollBack
kubectl rollout history deployment <deploy_name>
kubectl rollout history deployment app-deploy
# ...
# deployment.apps/app-deploy
# REVISION  CHANGE-CAUSE
# 1         <none>

# Revision Rollback
kubectl rollout undo deploy <deploy_name>
kubectl rollout undo deployment app-deploy --to-revision=3

# Status Check
kubectl rollout status deployment app-deploy

# 정지 및 재시작
kubectl rollout pause deployment app-deploy
kubectl rollout resume deployment app-deploy

DaemonSet

  • 전체 노드에서 Pod 가 한 개씩 실행되도록 보장
  • 로그 수집기, 모니터링 에이전트와 같은 프로그램 실행 시 적용
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: daemonset-nginx
spec:
  selector:
    matchLabels:
      app: webui
  template:
    metadata:
      name: nginx-pod
      labels:
        app: webui
    spec:
      containers:
      - name: nginx-container
        image: nginx:1.14

 


StatefulSet

  • Pod 상태를 유지해주는 Controller
    • pod 의 이름, pod 의 볼륨(스토리지)
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: sf-nginx
spec:
  replicas: 3
  serviceName: sf-service
  podManagementPolicy: Parallel
  selector:
    matchLabels:
      app: webui
  template:
    metadata:
      name: nginx-pod
      labels:
        app: webui
    spec:
      containers:
      - name: nginx-container
        image: nginx:1.14

 

  • scale up, scale down
 kubectl scale statefulset sf-nginx --replicas=4
 kubectl scale statefulset sf-nginx --replicas=2

 


Job

  • Kubernetes 는 Pod 를 Running 중인 상태로 유지시키려 한다
  • Batch 처리하는 Pod 는 작업이 완료되면 종료됨
  • Batch 처리에 적합한 컨트롤러로, Pod 의 성공적 완료 보장
    • 비정상 종료 시 다시 실행
    • 정상 종료 시 완료
apiVersion: apps/v1
kind: Job
metadata:
  name: job-example
spec:
  template:
    spec:
      containers:
      - name: centos-container
        image: centos:7
        command: ["bash"]
        args:
        - "-c"
        - "echo 'Hello World'; sleep 50; echo 'Bye'"
    restartPolicy: Never
LIST

'🔹Kubernetes' 카테고리의 다른 글

Kubernetes 설정 파일 제거  (0) 2025.02.01
Service 정의  (0) 2025.01.27
Pod 정의  (0) 2025.01.27
kubectl 명령어 분석 (매개변수)  (0) 2024.07.31
[Kubernetes] CentOS 7 Master-Worker 설치 방법  (0) 2024.07.25
'🔹Kubernetes' 카테고리의 다른 글
  • Service 정의
  • Pod 정의
  • kubectl 명령어 분석 (매개변수)
  • [Kubernetes] CentOS 7 Master-Worker 설치 방법
terranbin
terranbin
Studying Computer Science
  • terranbin
    Engineer
    terranbin
  • 전체
    오늘
    어제
    • 분류 전체보기 (129)
      • ☁️Cloud (42)
        • AWS (38)
        • MS Azure (4)
      • 🐳 Infra (1)
        • System (12)
        • DRBD (3)
      • 🔌Network (8)
      • 🔹Storage (8)
      • 🔹Kubernetes (15)
      • 🔹 DevOps (8)
      • 🔹Study (4)
      • 🔹Install (6)
      • 🔹ETC (2)
      • 🔹PostMan (6)
      • 🔹Openstack (3)
      • 🔹RcloneView (6)
      • 🔹Test (0)
      • 🔹Debug (2)
      • 🔹DBMS (2)
  • 블로그 메뉴

    • 홈
  • 링크

    • sungbin
    • Github
  • 공지사항

  • 인기 글

  • 태그

    postman
    rocky8
    rocky9
    terraform
    EC2
    rcloneview
    설치
    network
    kubernetes
    EBS
    Google Drive
    OpenStack
    centos7
    kubectl
    SAA
    aws dlt
    distributed load testing
    AWS
    S3
    ceph
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
terranbin
[Kubernetes] Controller 소개
상단으로

티스토리툴바