Kubernetes - Deployment

category DevOps/Kubernetes 2021. 11. 25. 11:03
728x90
반응형

Deployment

정의

  • ReplicaSet을 컨트롤해서 Pod수를 조절
  • Rolling Update & Rolling Back
  • RollingUpdate란?
    • 서비스 중단없이 이루어질 수 있도록 하는 업데이트

생성

root@master:~# cat > deployment-examl.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-deploy
spec:
  replicas: 3
  selector:
    matchLabels:
      app: webui
  template:
    metadata:
      labels:
        app: webui
    spec:
      containers:
      - image: nginx:1.14
        name: web
        ports:
        - containerPort: 80
root@master:~# kubectl create -f deployment-examl.yaml 
deployment.apps/app-deploy created

조회

root@master:~# kubectl get deployments -o wide
NAME         READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES       SELECTOR
app-deploy   3/3     3            3           69s   web          nginx:1.14   app=webui
root@master:~# kubectl get pods -o wide
NAME                          READY   STATUS    RESTARTS   AGE   IP          NODE                NOMINATED NODE   READINESS GATES
app-deploy-67bb978b99-4csdl   1/1     Running   0          74s   10.44.0.1   node2.example.com   <none>           <none>
app-deploy-67bb978b99-948ld   1/1     Running   0          74s   10.36.0.1   node1.example.com   <none>           <none>
app-deploy-67bb978b99-ppp2n   1/1     Running   0          74s   10.44.0.2   node2.example.com   <none>           <none>

삭제

root@master:~# kubectl delete deployments app-deploy 
deployment.apps "app-deploy" deleted

Rolling Update

nginx 이미지 버전을 1.14 → 1.15 로 업데이트

root@master:~# kubectl get pods -o wide
NAME                          READY   STATUS    RESTARTS   AGE   IP          NODE                NOMINATED NODE   READINESS GATES
app-deploy-67bb978b99-82fmt   1/1     Running   0          88s   10.44.0.1   node2.example.com   <none>           <none>
app-deploy-67bb978b99-988vb   1/1     Running   0          88s   10.36.0.1   node1.example.com   <none>           <none>
app-deploy-67bb978b99-ln7w7   1/1     Running   0          88s   10.36.0.2   node1.example.com   <none>           <none>
root@master:~# kubectl describe pod app-deploy-67bb978b99-82fmt  | grep nginx
    Image:          nginx:1.14
    Image ID:       docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
  Normal  Pulled     102s  kubelet            Container image "nginx:1.14" already present on machine
root@master:~# kubectl set image deploy app-deploy web=nginx:1.15
deployment.apps/app-deploy image updated

root@master:~# kubectl get pods -o wide
NAME                          READY   STATUS    RESTARTS   AGE     IP          NODE                NOMINATED NODE   READINESS GATES
app-deploy-86bd8f9bb4-6z6vp   1/1     Running   0          113s    10.44.0.1   node2.example.com   <none>           <none>
app-deploy-86bd8f9bb4-srjt7   1/1     Running   0          2m14s   10.36.0.1   node1.example.com   <none>           <none>
app-deploy-86bd8f9bb4-zsk5m   1/1     Running   0          2m35s   10.44.0.2   node2.example.com   <none>           <none>
root@master:~# kubectl describe pod app-deploy-86bd8f9bb4-zsk5m | grep nginx
    Image:          nginx:1.15
    Image ID:       docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
  Normal  Pulling    60s   kubelet            Pulling image "nginx:1.15"
  Normal  Pulled     45s   kubelet            Successfully pulled image "nginx:1.15" in 15.043291452s

Rolling Update History

root@master:~# kubectl rollout history deployment app-deploy
deployment.apps/app-deploy 
REVISION  CHANGE-CAUSE
1         <none>
2         kubectl set image deploy app-deploy web=nginx:1.15 --record=true

Rolling Update Undo

root@master:~# kubectl rollout undo deployment app-deploy
deployment.apps/app-deploy rolled back
root@master:~# kubectl get pods -o wide
NAME                          READY   STATUS    RESTARTS   AGE   IP          NODE                NOMINATED NODE   READINESS GATES
app-deploy-67bb978b99-75jhr   1/1     Running   0          39s   10.44.0.2   node2.example.com   <none>           <none>
app-deploy-67bb978b99-7qsqk   1/1     Running   0          41s   10.36.0.2   node1.example.com   <none>           <none>
app-deploy-67bb978b99-kvxzb   1/1     Running   0          36s   10.44.0.3   node2.example.com   <none>           <none>
root@master:~# kubectl describe pod app-deploy-67bb978b99-75jhr | grep nginx
    Image:          nginx:1.14
    Image ID:       docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
  Normal  Pulled     52s   kubelet            Container image "nginx:1.14" already present on machine
728x90
반응형

'DevOps > Kubernetes' 카테고리의 다른 글

Kubernetes - Headless Service  (0) 2021.11.30
Kubernetes - Service (서비스)  (0) 2021.11.30
Kubernetes - DaemonSet  (0) 2021.11.25
Kubernetes - CronJob  (0) 2021.11.24
Kubernetes -Job Controller  (0) 2021.11.23