A DaemonSet ensures that each node runs a copy of a pod. You can use a DaemonSet to run a log collection daemon, a monitoring daemon, or a system management application on each node. This topic describes how to create a DaemonSet for a Container Service for Kubernetes (ACK) cluster.
Create a DaemonSet in the ACK console
Create a DaemonSet from an image
- Log on to the ACK console.
- In the left-side navigation pane, click Clusters.
- On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.
- In the left-side navigation pane of the details page, choose .
- In the upper-right corner of the DaemonSets page, click Create from Image.
- Set parameters for the DaemonSet.
- On the Basic Information wizard page, configure the basic settings. For more information, see Create a stateless application from an image.
- On the Container wizard page, configure one or more containers. For more information, see Use a Deployment to create a stateless application.
- On the Advanced wizard page, configure the advanced settings. A DaemonSet can schedule a pod to a node that is in the Unschedulable state. To run a pod on only a specific node, set node affinity, pod affinity, or toleration rules. For more information, see Use a Deployment to create a stateless application.
- Click Create. After the DaemonSet is created, you can view the DaemonSet on the DaemonSets page.
Create a DaemonSet from a YAML template
- In the upper-right corner of the DaemonSets page, click Create from YAML.
- On the Create page, configure the DaemonSet in the Template section.
- Click Create below the Template section. After the DaemonSet is created, you can view the DaemonSet on the DaemonSets page.
Create a DaemonSet by using kubectl
Before you use kubectl to create a DaemonSet, you must download kubectl and connect to your cluster by using kubectl. For more information, see Use kubectl to connect to an ACK cluster.
|nodeSelector||A pod is scheduled to only the node with the specified labels.|
|nodeAffinity||Node affinity. Pods are scheduled to nodes based on node labels. Node affinity allows you to set other matching rules.|
|podAffinity||Pod affinity. Pods are scheduled to nodes based on pod labels. A pod is scheduled to only the node that runs a pod that matches the affinity rules.|
To demonstrate how to create a DaemonSet by using kubectl, a DaemonSet named fluentd-elasticsearch is created in this example.
- Create a daemonset.yaml file and copy the following content into the file:
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: # this toleration is to have the daemonset runnable on master nodes # remove it if your masters can't run pods - 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
- Run the following command to create a DaemonSet:
kubectl create -f daemonset.yamlIf
daemonset.apps/fluentd-elasticsearch createdis returned, the DaemonSet is created.
What to do next
- On the DaemonSets page, find the created DaemonSet and click Details in the Actions column. On the details page, you can view basic information about the DaemonSet. The information includes pods, access method, events, and logs.
- On the DaemonSets page, find the created DaemonSet. You can choose Actions column to view the YAML file of the DaemonSet. You can also choose to delete the DaemonSet. in the