Kubernetes - DaemonSet

# 前言

本文為閱讀 Kubernetes DaemonSet 官方文件, 並將重點摘取整理為 Q&A 方式



Kubernetes DaemonSet, Pod 會在什麼時候被 schedule 到 Node 上?

所有, 或指定的 Node 被建立時

Kubernetes DaemonSet, Pod 會在什麼時候從 Node 上被移除?

當 Node 從 cluster 被移除時, 或刪除 DaemonSet

Kubernetes DaemonSet, 有哪三種普遍的應用?
  • 執行一個 cluster storage daemon
  • 在每一個 Node 上執行 logs collection
  • 在每一個 Node 上執行 monitoring
以下的 Kubernetes example code 代表什麼意思?
  • Example:
    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
    name: fluentd-elasticsearch
    namespace: kube-system
    labels:
    k8s-app: fluentd-logging
    spec:
    selector:
    matchLabels:
    name: fluentd-elasticsearch
    template:
    metadata:
    labels:
    name: fluentd-elasticsearch
    spec:
    tolerations:
    - key: node-role.kubernetes.io/master
    effect: NoSchedule
    containers:
    - name: fluentd-elasticsearch
    image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
    resources:
    limits:
    memory: 200Mi
    requests:
    cpu: 100m
    memory: 200Mi
    volumeMounts:
    - name: varlog
    mountPath: /var/log
    - name: varlibdockercontainers
    mountPath: /var/lib/docker/containers
    readOnly: true
    terminationGracePeriodSeconds: 30
    volumes:
    - name: varlog
    hostPath:
    path: /var/log
    - name: varlibdockercontainers
    hostPath:
    path: /var/lib/docker/containers
  • Answer:
    # 結構上跟 Deployment 十分類似
    # 總結一下, 該 DaemonSet 會在每一個 Node 包含 Master Node
    # 上部署 fluentd-elasticsearch 做 Log 處理
    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
    name: fluentd-elasticsearch
    namespace: kube-system
    labels:
    k8s-app: fluentd-logging
    spec:
    selector:
    matchLabels:
    name: fluentd-elasticsearch
    template:
    metadata:
    labels:
    name: fluentd-elasticsearch
    spec:
    tolerations:
    # DaemonSet 預設不會執行在 Master Node 上, 使用 tolerations 可以允許
    # Master Node 運行 DaemonSet pod
    - key: node-role.kubernetes.io/master
    effect: NoSchedule
    containers:
    - name: fluentd-elasticsearch
    image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
    resources:
    limits:
    memory: 200Mi
    requests:
    cpu: 100m
    memory: 200Mi
    volumeMounts:
    - name: varlog
    mountPath: /var/log
    - name: varlibdockercontainers
    mountPath: /var/lib/docker/containers
    readOnly: true
    # 當 Pod 要被關閉時, 會有 30 秒的優雅退出
    terminationGracePeriodSeconds: 30
    volumes:
    - name: varlog
    hostPath:
    path: /var/log
    - name: varlibdockercontainers
    hostPath:
    path: /var/lib/docker/containers

# Required Fields

何謂 valid DNS subdomain name?
  • 不可超過 253 characters
  • alphanumeric character 開頭
  • alphanumeric character 結尾
  • 只可含有 lowercase alphanumeric, -.
Kubernetes DaemonSet 的 name 必須合乎哪種規範?

valid DNS subdomain name


# Pod Template

Kubernetes DaemonSet 中, RestartPolicy 必須為?

Always

Kubernetes - 建立一個 DaemonSet Kubernetes - 部署 WordPress 應用

留言

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×