본문으로 바로가기

[CKA독학] Deployment update &Rollback

category IT/CKA 2021. 7. 5. 11:27
반응형

Deployment update &Rollback

  • deployment에 설정된 pod가 update될때 어떻게 배포할것인지에 대한 전략으로 2가지가 있음
    • Recreate : 새로운 pod가 생성되기 전에 기존 pod가 종료됨
    • RollingUpdate : 롤링 방식으로 업데이트함(한개씩 생성/종료를 반복)

Rolling update and Rollback 관련 명령어

## deployment 이미지 업데이트 하기
kubectl set image deployment/<deployment_name> <container_name>=nginx:1.9.1
kubectl set image deployment/myapp-deployment nginx=nginx:1.9.1

## rollout상태 확인
kubectl rollout status deployment/myapp-deployment

## rollout히스토리 확인 및 rollbock
kubectl rollout history deployment/myapp-deployment
kubectl rollout undo deployment/myapp-deployment

배포 전략 변경 하기

  • 기존 deployment의 strategy.type필드를 RollingUpdate → Recreate로 변경
  • rollingUpdate 필드 삭제
kubectl edit deploy <deploy_name> 
  • rollingUpdate 설정 yaml예시
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  generation: 2
  labels:
    app: nginx
  name: nginx
  namespace: k8s-test
  resourceVersion: "14406181"
  uid: 5eaf4709-dc75-4fc4-8e3f-f73d3b7cc6cc
spec:
  progressDeadlineSeconds: 600
  replicas: 2
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: nginx
  strategy:
    rollingUpdate:    # Recreate 전략 사용시 삭제
      maxSurge: 25%   # Recreate 전략 사용시 삭제
      maxUnavailable: 25%  # Recreate 전략 사용시 삭제
    type: RollingUpdate # Recreate 전략 사용시 Recreate로 설정
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
  • Recreate 전략 yaml예시
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  generation: 2
  labels:
    app: nginx
  name: nginx
  namespace: k8s-test
  resourceVersion: "14406181"
  uid: 5eaf4709-dc75-4fc4-8e3f-f73d3b7cc6cc
spec:
  progressDeadlineSeconds: 600
  replicas: 2
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: nginx
  strategy:
    type: Recreate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
반응형