Skip to content

antony@notes:~/kubernetes$ cat "K8S-DaemonSet-應用.md"

K8S DaemonSet 應用

2023-07-24· kubernetes ·系統工程

透過 DaemonSet 在 K8S 的 每一台 Host 主機上安裝套件或是執行腳本

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: myapp
  labels:
    app: myapp
  annotations:
    command: &cmd sudo podman load < image.tar.gz
spec:
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      hostNetwork: true
      hostPID: true
      initContainers:
      - name: myapp-installation
        command:
          - nsenter
          - --mount=/proc/1/ns/mnt
          - --
          - bash
          - -c
          - *cmd
        image: quay.io/cloudwalker/alpine
        securityContext:
          privileged: true
      containers:
      - name: sleep
        image: registry.k8s.io/pause:3.1
  updateStrategy:
    type: RollingUpdate