5

I was wondering if there is an easier way to create daemonsets in k8s other than yaml files. For eg, for pods we have kubectl run --generator=run-pod/v1 command. I was wondering if there is something similar for DS.

Thanks in advance.

Gajanan Kulkarni
  • 697
  • 6
  • 22
Naxi
  • 1,504
  • 5
  • 33
  • 72

2 Answers2

8

There is no such quick kubectl create type command for creating daemonsets. But you can do it in some other way.

  • One way to do this is:
    $ kubectl create deploy nginx --image=nginx --dry-run=client -o yaml | \
        sed '/null\|{}\|replicas/d;/status/,$d;s/Deployment/DaemonSet/g' > nginx-ds.yaml
    $ kubectl apply -f nginx-ds.yaml
    
  • If you don't want to save the yaml data to any file, here's how you can do this:
    $ kubectl create deploy nginx --image=nginx --dry-run=client -o yaml | \
        sed '/null\|{}\|replicas/d;/status/,$d;s/Deployment/DaemonSet/g' | \
        kubectl apply -f -
    

You have your daemonset now.

What we are doing here is: at first we're creating a deployment yaml and then replacing kind: Deployment with kind: DaemonSet and remove replicas: 1 from the deployment yaml.

Thats's how we get yaml for daemonset.

bmatovu
  • 3,756
  • 1
  • 35
  • 37
Masudur Rahman
  • 1,585
  • 8
  • 16
0

You can access Kubernetes Documentation for DaemonSets. You could use the link and get examples of DaemonSet yaml files. However there is no way you could create a Daemonset by imperative way. You could create a deployment specification and change the deployment specification to DaemonSet specification. You need to change the kind to Daemonset, remove strategy, replicas and status fields. That would do.

Aditya Bhuyan
  • 328
  • 6
  • 10