Workloads: Deployment, StatefulSet und DaemonSet

Konfigurieren Sie Deployment, StatefulSet und DaemonSet im ohMyHelm Chart-Modus inklusive Flag-Logik, Update-Strategien, Volumes und Headless Services.

Workloads: Deployment, StatefulSet und DaemonSet

Im Chart-Modus (chart.enabled: true) erzeugt ohMyHelm wahlweise ein Deployment, ein StatefulSet oder ein DaemonSet. Jeder Workload-Typ besitzt einen eigenen Volume-Block und passende Rollout-Optionen.

Exakte Flag-Logik im Chart

Die drei booleschen Schalter chart.deployment (Standard: true), chart.statefulset (Standard: false) und chart.daemonset (Standard: false) bestimmen, welches Template gerendert wird:

deployment statefulset daemonset Erzeugter Workload
true (Standard) false false Deployment
false (oder true) true false StatefulSet
false (oder true) false true DaemonSet
beliebig true true Kein Workload (0 Ressourcen!)
false false false Kein Workload (0 Ressourcen!)

1. Deployment (Standard)

Verwenden Sie Deployment für zustandslose Anwendungen wie Webserver, APIs oder Queue-Worker. Volumes werden unter chart.deploymentVolume konfiguriert, die Rollout-Strategie unter chart.strategy.

chart:
  enabled: true
  deployment: true
  statefulset: false
  daemonset: false
  fullnameOverride: "acme-api"
  replicaCount: 3
  minReadySeconds: 10
  revisionHistoryLimit: 5
  progressDeadlineSeconds: 300

  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0

  container:
    image: registry.acme.corp/api:1.3.0
    ports:
      - name: http
        containerPort: 8080
        protocol: TCP
    resources:
      requests:
        cpu: 100m
        memory: 128Mi
      limits:
        cpu: 500m
        memory: 512Mi

  deploymentVolume:
    volumeMounts:
      - name: config
        mountPath: /etc/acme/config.yaml
        subPath: config.yaml
        readOnly: true
      - name: tmp
        mountPath: /tmp
    volumes:
      - name: config
        configMap:
          name: acme-api-config
      - name: tmp
        emptyDir: {}

2. StatefulSet

Verwenden Sie StatefulSet für zustandsbehaftete Dienste (Datenbanken, Broker, Caches mit Persistenz), die stabile Pod-Namen und eigene Persistent Volume Claims (PVCs) pro Pod benötigen.

  • Das Template setzt automatisch spec.serviceName: <ohmyhelm.fullname> — passend zum von ohMyHelm erzeugten Service.
  • Für echtes Pod-DNS (<pod-0>.<service>.<ns>.svc.cluster.local) setzen Sie chart.service.clusterIP: "None" (Headless Service).
  • Volumes, Mounts und volumeClaimTemplates gehören unter chart.statefulsetVolume.
  • Die Update-Strategie konfigurieren Sie unter chart.updateStrategy (nicht chart.strategy).
chart:
  enabled: true
  deployment: false
  statefulset: true
  daemonset: false
  fullnameOverride: "acme-db"
  replicaCount: 1
  minReadySeconds: 10
  revisionHistoryLimit: 5

  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      partition: 0

  container:
    image: postgres:16-alpine
    ports:
      - name: postgres
        containerPort: 5432
        protocol: TCP
    resources:
      requests:
        cpu: 250m
        memory: 512Mi
      limits:
        cpu: 1000m
        memory: 1Gi

  service:
    type: ClusterIP
    clusterIP: None
    ports:
      - name: postgres
        port: 5432
        targetPort: postgres
        protocol: TCP

  statefulsetVolume:
    volumeMounts:
      - name: data
        mountPath: /var/lib/postgresql/data
      - name: init-config
        mountPath: /etc/postgresql/conf.d
        readOnly: true
    volumes:
      - name: init-config
        configMap:
          name: acme-db-config
    volumeClaimTemplates:
      - metadata:
          name: data
        spec:
          accessModes:
            - ReadWriteOnce
          resources:
            requests:
              storage: 20Gi

3. DaemonSet

Verwenden Sie DaemonSet, wenn auf jedem (oder jedem passenden) Kubernetes-Node genau eine Pod-Instanz laufen soll — etwa für Node-Monitoring, Log-Sammlung oder Netzwerk-Agenten.

  • chart.replicaCount wird bei einem DaemonSet ignoriert.
  • Optional aktivieren Sie chart.hostNetwork: true (wirkt auf alle drei Workload-Typen).
  • Volumes und Mounts konfigurieren Sie unter chart.daemonsetVolume.
  • Die Update-Strategie setzen Sie unter chart.updateStrategy.
chart:
  enabled: true
  deployment: false
  statefulset: false
  daemonset: true
  hostNetwork: false
  fullnameOverride: "acme-node-agent"
  minReadySeconds: 5
  revisionHistoryLimit: 5

  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1

  tolerations:
    - operator: Exists

  container:
    image: registry.acme.corp/node-agent:1.0.0
    ports:
      - name: metrics
        containerPort: 9100
        protocol: TCP
    resources:
      requests:
        cpu: 50m
        memory: 64Mi
      limits:
        cpu: 200m
        memory: 256Mi

  daemonsetVolume:
    volumeMounts:
      - name: varlog
        mountPath: /var/log
        readOnly: true
    volumes:
      - name: varlog
        hostPath:
          path: /var/log
          type: Directory

  service:
    type: ClusterIP
    ports:
      - name: metrics
        port: 9100
        targetPort: metrics
        protocol: TCP

Vergleich der Volume- und Strategie-Schlüssel

Option Deployment StatefulSet DaemonSet
Volume-Block chart.deploymentVolume chart.statefulsetVolume chart.daemonsetVolume
volumeClaimTemplates Nein Ja Nein
Rollout-Strategie chart.strategy chart.updateStrategy chart.updateStrategy
replicaCount Ja Ja Nein
progressDeadlineSeconds Ja Nein Nein
minReadySeconds / revisionHistoryLimit Ja Ja Ja

Scheduling-Optionen für alle Workloads

Alle drei Workload-Typen unterstützen zusätzlich chart.nodeSelector, chart.tolerations und chart.affinity nach Standard-Kubernetes-Spezifikation:

chart:
  enabled: true
  nodeSelector:
    workload: general
  tolerations:
    - key: "dedicated"
      operator: "Equal"
      value: "apps"
      effect: "NoSchedule"
  affinity:
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 100
          podAffinityTerm:
            labelSelector:
              matchExpressions:
                - key: app
                  operator: In
                  values:
                    - acme-api
            topologyKey: kubernetes.io/hostname

Weiterführende Seiten