정의

  • 앱 배포할 때 사용하는 기본 컨트롤러
  • 리플리카셋 처럼 파드 개수 유지 기능 기본 제공
  • 롤링 업데이트, 배포 중단 및 재시도 및 롤백 가능까지 앱 배포를 세분화 가능
  • 디플로이먼트 예제는 minikube에서 진행

minikube 기동

minikube start --driver=virtualbox

생성

apiVersion: apps/v1
kind: Deployment
metadata:
  name: whms-deployment
  labels:
    app: whms-deployment
spec:
  replicas: 3 #-------- 파드 개수 
  selector:
    matchLabels:
      app: whms-deployment  #------ .metadata.labels.app 과 같은 설정 
  template:
    metadata:
      labels:
        app: whms-deployment
    spec:
      containers:
      - name: whms-deploy-con
        image: sftth/whms:latest
        ports:
        - containerPort: 8080

적용

[summit@gcp-minikube-vm deployment]$kubectl apply -f deployment.yaml
[summit@gcp-minikube-vm deployment]$ kubectl get deploy,rs,rc,pods
NAME                              READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/whms-deployment   3/3     3            3           14m

NAME                                         DESIRED   CURRENT   READY   AGE
replicaset.apps/whms-deployment-5d545b8597   3         3         3       14m

NAME                                   READY   STATUS    RESTARTS   AGE
pod/whms-deployment-5d545b8597-cxqdh   1/1     Running   0          14m
pod/whms-deployment-5d545b8597-ddmhd   1/1     Running   0          14m
pod/whms-deployment-5d545b8597-hbgf5   1/1     Running   0          14m

업데이트

[summit@gcp-minikube-vm deployment]$ kubectl edit deploy whms-deployment
deployment.apps/whms-deployment edited
[summit@gcp-minikube-vm deployment]$ kubectl get deploy whms-deployment -o=jsonpath="{.spec.template.spec.containers[0].image}{'\n'}"
sftth/whms:1.0

롤백

[summit@gcp-minikube-vm deployment]$ kubectl rollout history deploy whms-deployment
deployment.apps/whms-deployment 
REVISION  CHANGE-CAUSE
1         <none>
2         <none>

[summit@gcp-minikube-vm deployment]$ kubectl rollout history deploy whms-deployment --revision=1
deployment.apps/whms-deployment with revision #1
Pod Template:
  Labels:       app=whms-deployment
        pod-template-hash=5d545b8597
  Containers:
   whms-deploy-con:
    Image:      sftth/whms:latest
    Port:       8080/TCP
    Host Port:  0/TCP
    Environment:        <none>
    Mounts:     <none>
  Volumes:      <none>

[summit@gcp-minikube-vm deployment]$ kubectl rollout history deploy whms-deployment --revision=2
deployment.apps/whms-deployment with revision #2
Pod Template:
  Labels:       app=whms-deployment
        pod-template-hash=644968c7c
  Containers:
   whms-deploy-con:
    Image:      sftth/whms:1.0
    Port:       8080/TCP
    Host Port:  0/TCP
    Environment:        <none>
    Mounts:     <none>
  Volumes:      <none>

[summit@gcp-minikube-vm deployment]$ kubectl rollout undo deploy whms-deployment --to-revision=1
deployment.apps/whms-deployment rolled back
[summit@gcp-minikube-vm deployment]$ kubectl get deploy,rs,rc,pods
NAME                              READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/whms-deployment   3/3     2            3           18m

NAME                                         DESIRED   CURRENT   READY   AGE
replicaset.apps/whms-deployment-5d545b8597   2         2         1       18m
replicaset.apps/whms-deployment-644968c7c    2         2         2       2m33s

NAME                                   READY   STATUS              RESTARTS   AGE
pod/whms-deployment-5d545b8597-hbgf5   1/1     Terminating         0          18m
pod/whms-deployment-5d545b8597-hfn44   1/1     Running             0          9s
pod/whms-deployment-5d545b8597-ktc2s   0/1     ContainerCreating   0          4s
pod/whms-deployment-644968c7c-dgl5m    1/1     Running             1          2m33s
pod/whms-deployment-644968c7c-k8c6f    1/1     Running             1          17s
pod/whms-deployment-644968c7c-p2qs4    0/1     Terminating         0          11s

댓글남기기