본문 바로가기
INFRA/DevOps

[K8s] Deployment

by BTC_비웃는사나이 2022. 10. 4.

Deployment란?

 

  • ReplicaSet을 제어해서 pod수를 조절하는 부모역할
  • Rolling update & Rolling back
    • pod를 점진적으로 새로운 것으로 update하여 deployment update가 서비스 중단 없이 이루어질 수 있도록 하는 것
    • Rolling update : kubectl set image deployment <deploy_name> <container_name>=<new_version_image> --record
      • --record : update 과정을 history로 기록
    • Rolling back : kubectl rollout history deployment <deploy_name>kubectl rollout undo deploy <deploy_name>
    • 롤링 업데이트 수행하기
  • definition
apiVersion: apps/v1
kind: Deployment          # kind 값만 다를 뿐 ReplicaSet과 동일
metadata:
  name: app-deploy
spec:
  selector:
    matchLabels:
      app: webui
  replicas: 3
  template:
    metadata:
      labels:
        app: webui
    spec:
      containers:
      - image: nginx:1.14
        name: web
        ports:
        - containerPort: 80

 

[ Hands-on ] - Rolling upate & Roll back

1. CLI

  • Deployment 생성
vi deployment-exam1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-deploy
spec:
  selector:
    matchLabels:
      app: webui
  replicas: 3
  template:
    metadata:
      labels:
        app: webui
    spec:
      containers:
      - image: nginx:1.14
        name: web
        ports:
        - containerPort: 80
kubectl create -f deployment-exam1.yaml  --record
  • rolling update
kubectl set image deployment app-deploy web=nginx:1.15 --record
  • rolling update 일시정지
kubectl rollout pause deployment app-deploy
  • rolling update 재시작
kubectl rollout resume deployment app-deploy
  • rolling update 상태 확인
kubectl rollout status deployment app-deploy
  • 이전 update 기록 출력
    • default 값으로 10개의 history 저장, 변경가능
kubectl rollout history deployment app-deploy
  • rollback
kubectl rollout undo deployment app-deploy --to-revision=<revison값>


2. yaml

  • Deployment 생성
vi deployment-exam2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-nginx
  annotations:
    kubernetes.io/change-cause: version 1.15
spec:
  progressDeadlineSeconds: 600
  revisionHistoryLimit: 10
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  replicas: 3
  selector:
    matchLabels:
      app: webui
  template:
    metadata:
      labels:
        app: webui
    spec:
      containers:
      - name: web
        image: nginx:1.15
        ports:
        - containerPort: 80
kubectl apply -f deployment-exam2.yaml
  • rolling update
vi deployment-exam2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-nginx
  annotations:
    kubernetes.io/change-cause: version 1.16    //version 수정
spec:
  progressDeadlineSeconds: 600
  revisionHistoryLimit: 10
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  replicas: 3
  selector:
    matchLabels:
      app: webui
  template:
    metadata:
      labels:
        app: webui
    spec:
      containers:
      - name: web
        image: nginx:1.16                 //verson 수정
        ports:
        - containerPort: 80
1kubectl apply -f deployment-exam2.yaml
  • 이전 update 기록 출력
kubectl rollout history deployment deploy-nginx

 

 

참고 :[따배쿠] 6-3. 쿠버네티스 RollingUpdate를 위한 Deployment

 

 

댓글