<p>I took the CKA exam and I needed to work with Daemonsets for quite a while there. Since it is much faster to do everything with kubectl instead of creating yaml manifests for k8s resources, I was wondering if it is possible to create Daemonset resources using <code>kubectl</code>.</p>

<p>I know that it is NOT possible to create it using regular <code>kubectl create daemonset</code> at least for now. And there is no description of it in the documentation. But maybe there is a way to do that in some different way?</p>

<p>The best thing I could do right now is to create Deployment first like <code>kubectl create deployment</code> and edit it's output manifest. Any options here?</p>

<p>The fastest hack is to create a deployment file using </p>

<pre><code>kubectl create deploy nginx --image=nginx --dry-run -o yaml &gt; nginx-ds.yaml
</code></pre>

<p>Now replace the line <code>kind: Deployment</code> with <code>kind: DaemonSet</code> in <strong>nginx-ds.yaml</strong> and remove the line <code>replicas: 1</code></p>

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

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

<p>You have your nginx DaemonSet. </p>
