K8s – Question11

Use context: kubectl config use-context k8s-c1-H

Use Namespace project-tiger for the following. Create a DaemonSet named ds-important with image httpd:2.4-alpine and labels id=ds-important and uuid=18426a0b-5f59-4e10-923f-c0e078e82462. The Pods it creates should request 10 millicore cpu and 10 mebibyte memory. The Pods of that DaemonSet should run on all nodes, also controlplanes.

Creating a DaemonSet in Kubernetes from a Deployment

DaemonSets are a critical feature in Kubernetes, allowing you to ensure that a copy of a Pod runs on every node in your cluster. However, if you’re working with a situation where you cannot directly create a DaemonSet using kubectl, you can start by creating a Deployment and then converting it into a DaemonSet. In this guide, we’ll walk through how to do just that.

Step 1: Create a Deployment

Since we aren’t able to create a DaemonSet directly, we’ll start by creating a Deployment and then modify it. First, generate a Deployment YAML file:

This command will create a Deployment YAML file named 11.yaml. Now, let’s edit this file to convert the Deployment into a DaemonSet.

Step 2: Modify the YAML to Create a DaemonSet

Open the 11.yaml file in your preferred text editor (e.g., vim) and make the following changes:

In this YAML file, we changed the kind from Deployment to DaemonSet, removed unnecessary fields like replicas and strategy, and added resource requests and tolerations to ensure the DaemonSet runs on all nodes, including control-plane nodes.

Step 3: Apply the DaemonSet Configuration

Now that the YAML file is properly configured, apply it to your Kubernetes cluster:

After applying, verify that the DaemonSet is running on all nodes:

You should see output similar to the following, confirming that the DaemonSet is running on all nodes:

Conclusion

In this guide, we’ve demonstrated how to create a DaemonSet in Kubernetes by first generating a Deployment and then modifying it. This method is useful when direct creation of a DaemonSet is not possible via kubectl. By understanding the YAML structure and the required changes, you can easily ensure that your application runs across all nodes in your cluster.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *