본문 바로가기

Kubernetes

[Kubernetes] DaemonSet + RollingUpdate

반응형

DaemonSet 이란?

 - 전체 노드에서 Pod가 한 개씩 실행되도록 보장

 - 로그 수입기, 모니터링 에이전트와 같은 프로그램 실행 시 적용

 

daemonset-exam.yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: daemonset-nginx
spec:
  selector:
    matchLabels:
      app: webui
  template:
    metadata:
      name: nginx-pod
      labels:
        app: webui
    spec:
      containers:
      - name: nginx-container
        image: nginx:1.14

 

daemonset-exam.yaml 실행시 노드마다 pod가 하나씩 실행

# kubectl create -f daemonset-exam.yaml 
daemonset.apps/daemonset-nginx created

# kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE   IP          NODE                NOMINATED NODE   READINESS GATES
daemonset-nginx-gc96d   1/1     Running   0          13s   10.36.0.1   node1.example.com   <none>           <none>
daemonset-nginx-xmb8k   1/1     Running   0          13s   10.44.0.1   node2.example.com   <none>           <none>

 

★ 데몬셋은 노드당 1개의 Pod 보장!

 

데몬셋을 삭제하면 자동으로 컨테이너가 기동

# kubectl delete pod daemonset-nginx-gc96d 
pod "daemonset-nginx-gc96d" deleted

# kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE     IP          NODE                NOMINATED NODE   READINESS GATES
daemonset-nginx-d5g9c   1/1     Running   0          7s      10.36.0.1   node1.example.com   <none>           <none>
daemonset-nginx-xmb8k   1/1     Running   0          3m48s   10.44.0.1   node2.example.com   <none>           <none>

 

로그/모니터링 에이전트에 적합한 컨트롤러

Rolling Update 기능도 가지고 있음

 

edit 으로 image: nginx:1.14 → 1.15로 변경 하면 자동으로 Rolling Update가 됨

# kubectl edit daemonsets.apps daemonset-nginx

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: apps/v1
kind: DaemonSet
metadata:
  annotations:
    deprecated.daemonset.template.generation: "1"
  creationTimestamp: "2022-12-12T12:09:25Z"
  generation: 1
  name: daemonset-nginx
  namespace: default
  resourceVersion: "78200"
  uid: 12866e49-4cb0-4ec2-af32-c2a8ba7fcc13
spec:
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: webui
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: webui
      name: nginx-pod
    spec:
      containers:
      - image: nginx:1.15
        imagePullPolicy: IfNotPresent
        name: nginx-container
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
  updateStrategy:
    rollingUpdate:
      maxSurge: 0
      maxUnavailable: 1
    type: RollingUpdate
status:
  currentNumberScheduled: 2
  desiredNumberScheduled: 2
  numberAvailable: 2
  numberMisscheduled: 0
  numberReady: 2
  observedGeneration: 1
  updatedNumberScheduled: 2

 

nginx 1.15 버전으로 변경된 내용 확인 가능

# kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE   IP          NODE                NOMINATED NODE   READINESS GATES
daemonset-nginx-22cct   1/1     Running   0          11s   10.36.0.1   node1.example.com   <none>           <none>
daemonset-nginx-4j7cn   1/1     Running   0          14s   10.44.0.1   node2.example.com   <none>           <none>

# kubectl describe pod daemonset-nginx-4j7cn
Name:             daemonset-nginx-4j7cn
Namespace:        default
Priority:         0
Service Account:  default
Node:             node2.example.com/10.100.0.102
Start Time:       Mon, 12 Dec 2022 21:17:53 +0900
Labels:           app=webui
                  controller-revision-hash=6d7b58dbf6
                  pod-template-generation=2
Annotations:      <none>
Status:           Running
IP:               10.44.0.1
IPs:
  IP:           10.44.0.1
Controlled By:  DaemonSet/daemonset-nginx
Containers:
  nginx-container:
    Container ID:   containerd://e9c1d42043835b46a2c6f8b45df20c17e3a73fba0f42176f24db7a1cb4ca0780
    Image:          nginx:1.15
    Image ID:       docker.io/library/nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Mon, 12 Dec 2022 21:17:54 +0900
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-bbsq8 (ro)

 

롤백도 가능함

# kubectl rollout undo daemonset daemonset-nginx 
daemonset.apps/daemonset-nginx rolled back

 

 

[참고]

- https://www.youtube.com/watch?v=wJeb561CMOg

반응형