DaemonSet Management

Last updated: 2020-02-25 10:43:33



A DaemonSet is mainly used to deploy daemons residing in the cluster, such as log collection of the node. It guarantees that the specified Pod is run on all or some nodes. When a new node is added to the cluster, a Pod will be automatically deployed; after the node is removed from the cluster, the Pod will be automatically reclaimed.

Notes on Scheduling

If the nodeSelector or affinity parameter of the Pod is configured, the Pod managed by the DaemonSet will be scheduled according to the specified scheduling rule. If the nodeSelector or affinity parameter of the Pod is not configured, the Pod will be deployed on all nodes.

Operation Guide for DaemonSet in the Console

Creating a DaemonSet

  1. Log in to the TKE console and select Clusters In the left sidebar.

  2. Click the ID of the cluster where DaemonSet needs to be created to enter the cluster management page.

  3. Select "workload" > "DaemonSet" to go to the DaemonSet information page.

  4. Click CREATE To go to Create Workload Page。
    Set the DaemonSet parameters according to the actual requirements. Key parameters are as follows:

    • Workload Name Enter a custom name.

    • Namespace : To be selected based on your requirements.

    • Type: Select "DaemonSet (run the Pod on each server)".

    • In-Pod containers: Set one or more different containers for a Pod of the DaemonSet based on actual needs.

      • Name: user-defined name.

      • Image: Select based on actual needs.

      • Image Tag Enter will be carried out according to the actual demand.

      • Image's pull strategy The following three strategies are provided, please choose as needed.
        If Image's pull strategy is not set, when Image Tag is empty or latest The Always policy is used, otherwise the IfNotPresent policy is used.

        • ALWAYS Always pull the Image remotely.
        • IfNotPresent Local Image is used by default. If there is no local Image, the Image will be pulled remotely.
        • NEVER Only use local Image. If you don't have the local Image, you will report an exception.
      • CPU/memory limits: Set the CPU and memory limit according to Kubernetes' resource limits to improve the robustness of the business.

      • Advanced settings: Parameters such as "working directory", "run commands", "run parameters", "container health check", and "privilege level" can be set.

  5. Click Create a workload to complete the creation.

Updating a DaemonSet

Updating YAML

  1. Log in to the TKE console.
  2. In the left sidebar, click Clusters to go to the cluster management page.
  3. Click the ID of the cluster where YAML needs to be updated to enter the cluster management page.
  4. Select "Workload" > "DaemonSet" to go to the DaemonSet information page. See the figure below:
  5. In the row of the DaemonSet for which to update the YAML, click Edit YAML to go to the DaemonSet updating page.
  6. On the "Update a DaemonSet" page, edit the YAML and click Finish to update the YAML.

Update Pod configuration

Rolling update of DaemonSet is only supported in Kubernetes v1.6 or higher.

  1. On the cluster management page, click the ID of the cluster for which to update the DaemonSet image to go to the management page of the cluster.
  2. In the DaemonSet line where you need to update the Pod configuration, click "Update Pod configuration".
  3. On the Roll update an image Page, modify the update method and set the parameters based on actual needs.
  4. Click "finish" to update the Pod configuration.

Using kubectl to Manipulate DaemonSet

YAML Sample

apiVersion: apps/v1
kind: DaemonSet
  name: fluentd-elasticsearch
  namespace: kube-system
    k8s-app: fluentd-logging
      name: fluentd-elasticsearch
        name: fluentd-elasticsearch
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      - name: fluentd-elasticsearch
        image: k8s.gcr.io/fluentd-elasticsearch:1.20
            memory: 200Mi
            cpu: 100m
            memory: 200Mi
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true
      terminationGracePeriodSeconds: 30
      - name: varlog
          path: /var/log
      - name: varlibdockercontainers
          path: /var/lib/docker/containers

Note: The YAML sample above comes from https://kubernetes.io/docs/concepts/workloads/controllers/daemonset. There may be cases where the container image pulling fails during creation. The sample is only used to describe the composition of DaemonSet.

  • kind: This identifies the DaemonSet resource type.
  • metadata: Basic information such as DaemonSet name and Label.
  • metadata.annotations: An additional description of the DaemonSet. You can set additional enhancements to TKE through this parameter.
  • spec.template: Detailed template configuration of the Pod managed by the DaemonSet.

For more information, see Kubernetes' official document about DaemonSet.

Using kubectl to Create a DaemonSet

  1. See the YAML sample to prepare the StatefulSet YAML file.
  2. Install kubectl and connect to a cluster.
  3. Run the following command to create the DaemonSet YAML file.
    kubectl create -f DaemonSet YAML filename
    For example, to create a StatefulSet YAML file named fluentd-elasticsearch.yaml, run the following command:
    kubectl create -f fluentd-elasticsearch.yaml
  4. Run the following command to verify whether the creation is successful.
    kubectl get DaemonSet
    If a message similar to the one below is returned, the creation is successful.
    frontend   0         0         0         0            0           app=frontend-node   16d

Using kubectl to Update a DaemonSet

Run the following command to view the update policy type of the DaemonSet.

kubectl get ds/<daemonset-name> -o go-template='{{.spec.updateStrategy.type}}{{"\n"}}'

DaemonSet has the following two update policy types:

  • OnDelete: This is the default update policy. With this policy, after the DaemonSet is updated, you have to manually delete the old DaemonSet Pod to create a new one.
  • RollingUpdate: This update policy is supported in Kubernetes v1.6 or higher. With this policy, after the DaemonSet template is updated, the old DaemonSet Pod will be terminated, and a new DaemonSet Pod will be created in a rolling update manner.

Method 1

Run the following command to update a DaemonSet.

kubectl edit DaemonSet/[name]

This method is good for testing and verification, but not production.. Also, You can update DaemonSet parameters using this method.

Method 2

Run the following command to update the image of the specified container.

kubectl set image ds/[daemonset-name][container-name]=[container-new-image]

It is recommended to keep other DaemonSet parameters unchanged and only update the container image when the business is updated.

Using kubectl to Roll back a DaemonSet

  1. Run the following command to view the update history of the DaemonSet.
    kubectl rollout history daemonset /[name]
  2. Run the following command to view the details of the specified version.
    kubectl rollout history daemonset /[name] --revision=[REVISION]
  3. Run the following command to roll back to the previous version.
    kubectl rollout undo daemonset /[name]
    To specify the version number to roll back, run the following command.
    kubectl rollout undo daemonset /[name] --to-revision=[REVISION]

Using kubectl to Delete a DaemonSet

  1. Run the following command to delete a DaemonSet.
    kubectl delete  DaemonSet [NAME]