DaemonSet Management
Overview
A DaemonSet ensures that exactly one Daemon Pod runs on each eligible node in the cluster. The DaemonSet is suitable for system-level applications such as log collection and resource monitoring, which ensures the availability of basic services in the cluster. For more information about DaemonSets, please refer to Official Documentation. Users can create a daemon based on images via forms, or create and modify the daemon using YAML file templates provided by Baidu AI Cloud to control and manage Pods, events, etc. associated with the daemon.
Introduction to DaemonSet
A DaemonSet ensures that one replica of a container runs on each node. It's typically used for deploying cluster-wide applications like logging, monitoring, or other system management tools. Examples of tasks well-suited for DaemonSet use include:
- Run cluster storage daemons, like glusterd and ceph, on each node.
- Run log collection daemons on each node, such as fluentd or logstash.
- Run monitoring daemons on each node, like Prometheus Node Exporter, collectd, Datadog agent, New Relic agent, or Ganglia gmond.
A basic use case is to start one DaemonSet for each type of daemon on all nodes. For more advanced use, you can deploy multiple DaemonSets of the same type, each with specific flags and memory/CPU requirements tailored to different hardware types.
Prerequisites
- A K8S Cluster CCE has been created successfully. For specific operations, refer to Create a K8S Cluster CCE.
Create a DaemonSet
Users can easily create a new DaemonSet through the CCE console using forms, YAML, or kubectl commands.
Create via console form
- Sign in to Cloud Container Engine Console (CCE).
- From the left navigation bar, go to Cluster Management -> Cluster List to access the cluster list page. Click on the Cluster Name to navigate to the Cluster Management page.
- In the left navigation bar of the Cluster Management page, click Workload > DaemonSet.
- Click Create DaemonSet in the upper left corner of the stateless workload list to enter the Workload Creation page.
- Complete the configuration in the basic information module and click Next to proceed to container configuration.
| Parameters | Description |
|---|---|
| Workload name | Name the workload as prompted by the system. Ensure the name is unique within the same namespace. |
| Namespace | Select the namespace for workload deployment (default: default). Custom namespaces are supported; for details, refer to Namespace Operations. |
| Workload type | Choose a DaemonSet. |
| Desired Pod count | Specify the number of Pod instances for the workload. |
| K8S label | Specify labels for the workload (corresponding to labels in Kubernetes) to identify the key-value pairs of workloads, and help Kubernetes quickly filter target workloads combined with selectors. For details, refer to K8S Label Description. |
| Annotation | Specify annotation information for the workload (corresponding to annotations in Kubernetes) to mainly record additional information for application deployment, security policies and scheduling policies, and fail to identify or distinguish resources. For details, refer to K8S Annotation Description. |
-
In the container configuration section, input the container name and image address. Then, click Select the Image to choose the image address in CCR from the pop-up window. Click Next to proceed to the advanced configuration section.
Description
- Multiple containers can be added to a Pod. Click Add Container on the right to configure additional containers for the Pod.
- If using a private image from CCR, set up repository access credentials in the advanced settings on this page.
| Parameters | Description |
|---|---|
| Container name | Name the container following the system's rules. Each container name must be unique within the same workload. |
| Image address | Click Select Image to pick the image for the container. Two types of images are supported. |
| Image version | Choose the image version to deploy. |
| Image pull policy | Select an image pull policy. CCE provides three pull policies (imagePullPolicy): |
| Container resources | Configure resources.limits and resources.requests for container resources. If the request value and limit value are not filled in, the quota is not limited. For instructions and recommendations for configuration of request value and limit value, please refer to Requests and Limits.
|
| Container ports | Define the port name, protocol, and port number for the container. |
| Environment variables | Click Add Environment Variable to set up environment variables. Kubernetes automatically injects these variables into containers when creating Pods. Supported types include: |
| Container startup item | Add startup parameters to the container, and currently support the following container startup parameters: kubectl exec -i -t command (configured during Pod startup). |
| Privileged container | Default: Disabled. When enabled, the container gains elevated privileges similar to the host OS of the worker node, such as accessing hardware devices or mounting file systems. |
| Init container | Default: disable. Select whether the container is used as an Init container. Init containers do not support health checks. The Init container is a special container that can run before other application containers in the Pod start. Each Pod can contain multiple containers, and there can also be one or more Init containers in the Pod that start before the application container. The application container in the Pod will only start and run when all Init containers have completed running. For details, refer to Init Container. |
| Health check | Support configuring Liveness Check Readiness Check and Startup Check. Detect whether the load in the container is normal based on HTTP request check, TCP port check, command execution check and GRCP check. Taking the configuration liveness check as an example, the following introduces configuration parameters.
|
| Lifecycle | Set operations to be performed at specific stages of the container's lifecycle, such as startup commands, tasks after starting up, and procedures before shutdown. For details, see Set the Container Lifecycle. |
| Volume | Support mounting various types of volumes for containers for data persistence, including subpath mounting via subPath and extended path mounting via subPathExpr: cm1:path1;cm2:path2.sc1:path1;sc2:path2. |
| Repository access credentials | If a container uses a private image, be sure to add the corresponding access credentials for the image repository. Support creating credentials or selecting existing ones. For details, refer to Configure Access Credentials. |
- In the advanced settings section, set the scheduling policies and click Finish to create the workload.
| Parameters | Description |
|---|---|
| Scheduling policies | Enable flexible workload scheduling by defining affinity and anti-affinity rules, which support both load and node affinity.
|
| Pod labels | Add labels to each Pod belonging to the workload (corresponding to labels in Kubernetes), to identify key-value pairs of Pods, and use selectors to help Kubernetes quickly filter target Pods. For details, refer to K8S Label Description. |
| Pod annotations | Add annotations to each Pod belonging to this workload (corresponding to annotations in Kubernetes) to mainly record additional information for application deployment, security policies and scheduling policies, and fail to identify or distinguish resources. For details, refer to K8S Annotation Description. |
Method II: Create via YAML
- Click "Create via YAML" in the top-left corner of the deployment list to open the Workload Creation page.
-
From the drop-down menu, select a namespace, complete the YAML file, and click OK.
Description:
- Template type: Create using either the example template or "My Template."
- Replication: Duplicate the content of the current YAML file.
- Save as: Save the current file template under the name "My Template."
- Cancel: Return to the list page.
- Confirm: Proceed to create a daemon.
Workload YAML Example
1apiVersion: apps/v1
2kind: DaemonSet
3metadata:
4 name: daemonset-example
5spec:
6 minReadySeconds: 0
7 selector:
8 matchLabels:
9 app: daemonset-example
10 revisionHistoryLimit: 10
11 template:
12 metadata:
13 labels:
14 app: daemonset-example
15 spec:
16 containers:
17 - name: daemonset-example
18 image: registry.baidubce.com/cce/busybox:latest
19 command:
20 - sleep
21 - "3600"
22 updateStrategy:
23 type: RollingUpdate
Method III: Create via kubectl
- Prepare a YAML file for the DaemonSet.
- Install kubectl and connect to the cluster. For details, refer to Connect to a Cluster via Kubectl.
-
Copy the YAML file below and save it as "daemonset.yaml."
Note:
- Ensure that kubectl is connected to the cluster before creating the workload. For specific operations, please refer to Connect to the Cluster via Kubectl.
1apiVersion: apps/v1
2kind: DaemonSet
3metadata:
4 name: daemonset-example
5spec:
6 minReadySeconds: 0
7 selector:
8 matchLabels:
9 app: daemonset-example
10 revisionHistoryLimit: 10
11 template:
12 metadata:
13 labels:
14 app: daemonset-example
15 spec:
16 containers:
17 - name: daemonset-example
18 image: registry.baidubce.com/cce/busybox:latest
19 command:
20 - sleep
21 - "3600"
22 updateStrategy:
23 type: RollingUpdate
- Run the following command to create the DaemonSet.
1kubectl apply -f daemonset.yaml
Expected output
1daemonset.apps/daemonset-example created
- Run the following command to display detailed information about DaemonSet Pods.
1kubectl get pods --all-namespaces -o wide | grep daemonset-example
View DaemonSet details
Click the name of any workload in the list to enter its details page, which includes: workload details, associated Pods, auto scaling, updates/upgrades, scheduling policies, monitoring and events.
Update a DaemonSet
You can edit the created DaemonSet using either the console interface or the YAML file.
-
Log in to the DaemonSet Workload Management page.
a. Sign in to Cloud Container Engine Console (CCE).
b. In the left navigation bar, click Cluster Management -> Cluster List to enter the Cluster List page. Click the Cluster Name to enter the Cluster Management page.
c. In the left navigation bar of the Cluster Management page, click Workload > DaemonSet. -
In the operation column of the target DaemonSet, click Update and Upgrade or Edit YAML.
Description:
Neither console interface updates nor YAML file editing support updating the DaemonSet name or namespace.a. Update: Update configuration information on the console. For detailed parameter descriptions, please refer to Create via Console.
b. Edit YAML: Update configuration information by editing the YAML file. For detailed YAML configuration descriptions, please refer to Create via YAML. - Click Update after completing the update.
Label and annotation management
Labels are key-value pairs attached to DaemonSet workloads. Once labels are added, they allow you to manage and select DaemonSet workloads. Labels can be applied to multiple workloads or an individual workload.
Description:
Label format requirements: Labels must start and end with letters or numbers, contain letters, numbers, hyphens (-), underscores (_) or dots (.), and be within 63 characters. For details, refer to K8S Label Description.
-
Log in to the DaemonSet Management page.
a. Sign in to Cloud Container Engine Console (CCE).
b. In the left navigation bar, click Cluster Management -> Cluster List to enter the Cluster List page. Click the Cluster Name to enter the Cluster Management page.
c. In the left navigation bar of the Cluster Management page, click Workload > DaemonSet. - Select the DaemonSets tab, and click More > Labels and Annotations next to the workload.
- Click Add Label, enter the key and value, and then click Update.
View monitor
Check the CPU and memory usage of workloads and Pods in the CCE console to assess the required resource specifications.
Description:
Viewing workload monitoring information depends on the cluster being connected to the Cloud Managed Service for Prometheus. If the cluster is not connected to Cloud Managed Service for Prometheus, please follow the prompts on the interface to connect. For details, refer to Monitor Clusters with Prometheus.
-
Log in to the DaemonSet Workload Management page.
a. Sign in to Cloud Container Engine Console (CCE).
b. In the left navigation bar, click Cluster Management -> Cluster List to enter the Cluster List page. Click the Cluster Name to enter the Cluster Management page.
c. In the left navigation bar of the Cluster Management page, click Workload > DaemonSet. - In the target DaemonSet workload list, click Monitor in the DaemonSet to be adjusted.
- View monitor data on the monitoring page. For descriptions of container-related monitor metrics, please refer to Monitor Metrics Description.
View logs
Access log details of DaemonSet workloads through the "Log" function.
Description:
Currently displayed logs are container standard output logs, which do not support persistence or advanced operation and maintenance capabilities. For more comprehensive logging, enable the Log Center Function.
-
Log in to the DaemonSet Workload Management page.
a. Sign in to Cloud Container Engine Console (CCE).
b. In the left navigation bar, click Cluster Management -> Cluster List to enter the Cluster List page. Click the Cluster Name to enter the Cluster Management page.
c. In the left navigation bar of the Cluster Management page, click Workload > DaemonSet. - In the target DaemonSet workload list, click More > Log next to the workload.
- Examine container log data on the log page.
Delete a DaemonSet
If a workload is no longer required, you can remove it.
Description:
Deleting a DaemonSet workload may cause service unavailability; please proceed with caution.
-
Log in to the DaemonSet Workload Management page.
a. Sign in to Cloud Container Engine Console (CCE).
b. In the left navigation bar, click Cluster Management -> Cluster List to enter the Cluster List page. Click the Cluster Name to enter the Cluster Management page.
c. In the left navigation bar of the Cluster Management page, click Workload > DaemonSet. - In the target DaemonSet workload list, click More > Delete next to the workload.
- In the secondary confirmation dialog box that pops up in the system, confirm the information and click OK.

