A DaemonSet ensures that only one replicated pod runs on each node. If a new node is added to a cluster, a pod is scheduled to the node. You can use a DaemonSet to run a log collection daemon, a monitoring daemon, or a system management daemon on each node. This topic describes how to create a DaemonSet for a Container Service for Kubernetes (ACK) cluster.
Prerequisites
An ACK cluster is created. For more information, see Create an ACK managed cluster.
A kubectl client is connected to the ACK cluster. For more information, see Use kubectl to connect to an ACK cluster.
Procedure
You can use the ACK console or kubectl to create a DaemonSet.
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, click the name of the cluster that you want to manage and choose in the left-side navigation pane.
In the upper-right corner of the DaemonSets page, click Create from Image.
Configure parameters for the DaemonSet.
In the Basic Information step, configure the basic settings of the application. For more information about the parameters, see Create a Deployment from an image.
In the Container step, configure one or more containers. For more information about the parameters, see Create a Deployment from an image.
In the Advanced step, configure the advanced settings of the DaemonSet.
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 about the parameters, see Create a Deployment from an image.
Click Create.
After the DaemonSet is created, you can view the DaemonSet on the DaemonSets page.
NoteOn the DaemonSets page, select Batch Redeploy to redeploy multiple DaemonSets.
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.
In the lower part of the Template section, click Create.
After the DaemonSet is created, you can view the DaemonSet on the DaemonSets page.
Create a DaemonSet by using kubectl
A DaemonSet can schedule a pod to a node that is in the Unschedulable state. To run a pod on only the specified node, set the following parameters.
Parameter | Description |
nodeSelector | A pod is scheduled only to 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 only to 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 file named daemonset.yaml and copy the following content to 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 the DaemonSet:
kubectl create -f daemonset.yaml
If
daemonset.apps/fluentd-elasticsearch created
is returned, the DaemonSet is created.
What to do next
After you create a DaemonSet, you can perform the following operations:
On the DaemonSets page, click the Label field, enter the key and
value
that you specified for the application, and then click OK to filter the applications.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 and choose
in the Actions column to view the YAML file of the DaemonSet. You can also choose to delete the DaemonSet.