목차

Deployment 개요

Deployment는 쿠버네티스에서 가장 널리 사용되는 오브젝트입니다. ReplicaSet을 이용하여 Pod을 업데이트하고 이력을 관리하여 롤백Rollback하거나 특정 버전revision으로 돌아갈 수 있습니다.

http://wiki.ciscolinux.co.uk/index.php/Kubernetes/Deployment,_ReplicaSet_and_Pod

Deployment Manifest

https://dev-k8sref-io.web.app/docs/workloads/deployment-v1/

  • apiVersion: apps/v1    #쿠버네티스 API버전을 가리킴

  • kind: Deployment    #리소스 유형

  • metadata (ObjectMeta): 포드와 관련된 이름, 네임스페이스, 라벨, 그밖의 정보

    • namespace
    • name
    • labels
  • spec (DeploymentSpec): PodTemplate

    • template (PodTemplateSpec# Pods 명세

      • metadata
        • name
        • labels
      • spec
        • containers
        • volumes
    • selector                # Pods 선택자
    • replicas                 # 복제본수
    • strategy               # RollingUpdate(default)   #배포 전략
  • status(DeploymentStatus) : 포드의 상태, 각 컨테이너의 설명 및 상태, 포드 내부의 IP 및 그밖의 기본 정보 등
nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deploy
  labels:
    app: myapp-deploy
    type: front-end
spec:
  template:
    metadata:
      name: nginx
      labels:
        app: myapp
        type: front-end
    spec:
      containers:
        - name: nginx
          image: nginx:1.14.2
          ports:
            - containerPort: 80
  selector:
    matchLabels:
      type: front-end
  replicas: 3

Deployment Strategy


  • 무중단 배포를 위해서는 Pod에 대하여 StartupProbe, livenessProbe, readinessProbe, terminationGracePeriodSeconds 설정등이 요구 됩니다.



Deployment 실습

sansae@sansaeAir15m2 ~ % k apply -f nginx-deploy.yaml
deployment.apps/nginx-deploy created

sansae@sansaeAir15m2 ~ % k get all
NAME                               READY   STATUS    RESTARTS   AGE
pod/nginx-deploy-d4d6c7dd8-4zx7v   1/1     Running   0          3s
pod/nginx-deploy-d4d6c7dd8-m6p7j   1/1     Running   0          3s
pod/nginx-deploy-d4d6c7dd8-rm5hj   1/1     Running   0          3s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP   8h

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx-deploy   3/3     3            3           3s

NAME                                     DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-deploy-d4d6c7dd8   3         3         3       3s
sansae@sansaeAir15m2 ~ % k get pod
NAME                           READY   STATUS    RESTARTS   AGE
nginx-deploy-d4d6c7dd8-67vfc   1/1     Running   0          15s
nginx-deploy-d4d6c7dd8-d6zrj   1/1     Running   0          17s
nginx-deploy-d4d6c7dd8-zhq6g   1/1     Running   0          16s


sansae@sansaeAir15m2 ~ % k set image deploy/nginx-deploy nginx=nginx:1.15.12
deployment.apps/nginx-deploy image updated

sansae@sansaeAir15m2 k8s-lab-workspace % k rollout status deploy/nginx-deploy              
deployment "nginx-deploy" successfully rolled out

sansae@sansaeAir15m2 ~ % k describe deploy nginx-deploy
Name:                   nginx-deploy
Namespace:              default
CreationTimestamp:      Fri, 08 Mar 2024 23:17:39 +0900
Labels:                 app=myapp-deploy
                        type=front-end
Annotations:            deployment.kubernetes.io/revision: 2
Selector:               type=front-end
Replicas:               3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=myapp
           type=front-end
  Containers:
   nginx:
    Image:        nginx:1.15.12
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  nginx-deploy-d4d6c7dd8 (0/0 replicas created)
NewReplicaSet:   nginx-deploy-77978cf89b (3/3 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  38s   deployment-controller  Scaled up replica set nginx-deploy-d4d6c7dd8 to 3
  Normal  ScalingReplicaSet  15s   deployment-controller  Scaled up replica set nginx-deploy-77978cf89b to 1
  Normal  ScalingReplicaSet  14s   deployment-controller  Scaled down replica set nginx-deploy-d4d6c7dd8 to 2 from 3
  Normal  ScalingReplicaSet  14s   deployment-controller  Scaled up replica set nginx-deploy-77978cf89b to 2 from 1
  Normal  ScalingReplicaSet  13s   deployment-controller  Scaled down replica set nginx-deploy-d4d6c7dd8 to 1 from 2
  Normal  ScalingReplicaSet  13s   deployment-controller  Scaled up replica set nginx-deploy-77978cf89b to 3 from 2
  Normal  ScalingReplicaSet  12s   deployment-controller  Scaled down replica set nginx-deploy-d4d6c7dd8 to 0 from 1


sansae@sansaeAir15m2 k8s-lab-workspace % k rollout history deploy/nginx-deploy              
deployment.apps/nginx-deploy 
REVISION  CHANGE-CAUSE
1         <none>
2         <none>

sansae@sansaeAir15m2 k8s-lab-workspace % k rollout undo deploy/nginx-deploy                 
deployment.apps/nginx-deploy rolled back
sansae@sansaeAir15m2 k8s-lab-workspace % k get pod
NAME                           READY   STATUS    RESTARTS      AGE
nginx-deploy-d4d6c7dd8-g6chm   1/1     Running   0             2s
nginx-deploy-d4d6c7dd8-hs9xx   1/1     Running   0             3s
nginx-deploy-d4d6c7dd8-vsgbf   1/1     Running   0             5s
util                           1/1     Running   2 (21m ago)   142m


  • 실제 운영에서는 rollout기능을 사용하지 않고, CI/CD를 구축하여 Container Image버전을 컨트롤 하여 배포 합니다.



  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.