Create Daemonset using kubectl? Create Daemonset using kubectl? kubernetes kubernetes

Create Daemonset using kubectl?


The fastest hack is to create a deployment file using

kubectl create deploy nginx --image=nginx --dry-run -o yaml > nginx-ds.yaml

Now replace the line kind: Deployment with kind: DaemonSet in nginx-ds.yaml and remove the line replicas: 1

However, the following command will give a clean daemonset manifest considering that "apps/v1" is the api used for DaemonSet in your cluster

kubectl create deploy nginx --image=nginx --dry-run -o yaml | \    sed '/null\|{}\|replicas/d;/status/,$d;s/Deployment/DaemonSet/g' > nginx-ds.yaml

You have your nginx DaemonSet.


CKA allows access to K8S documentation. So, it should be possible to get a sample YAML for different resources from there. Here is the one for the Daemonset from K8S documentation.

Also, not sure if the certification environment has access to resources in the kube-system namespace. If yes, then use the below command to get a sample yaml for Daemonset.

kubectl get daemonsets kube-flannel-ds-amd64 -o yaml -n=kube-system > daemonset.yaml


It's impossible. At least for Kubernetes 1.12. The only option is to get a sample Daemonset yaml file and go from there.