Reputation: 1637
When the pod controlled by daemonset,Some error occur in the pod and it's state will be CrashLoopBackOff
, I want to delete these pods but not delete the DaemonSet.
So I want to scale daemonset to 0, as far as I known, DaemonSet Spec do not support the replica of the pod.
How can I get there?
Upvotes: 64
Views: 84334
Reputation: 101
only as addition to Alex Vorona's answer for scaling to more than 0 nodes:
scale to a single node:
kubectl -n <namespace> patch daemonset <name-of-daemon-set> -p '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "<hostname>"}}}}}'
scale to any number of nodes with some label:
kubectl -n <namespace> label nodes <name-of-node> someLabel=true
kubectl -n <namespace> patch daemonset <name-of-daemon-set> -p '{"spec": {"template": {"spec": {"nodeSelector": {"someLabel": "true"}}}}}'
Upvotes: 10
Reputation: 2285
In case you don't wanna delete the daemonset, one possible work-around is to use temporary nodeSelector with any non-existing label, for example:
kubectl -n <namespace> patch daemonset <name-of-daemon-set> -p '{"spec": {"template": {"spec": {"nodeSelector": {"non-existing": "true"}}}}}'
This will scale the daemonset down.
And here is the patch to remove temporary nodeSelector
:
kubectl -n <namespace> patch daemonset <name-of-daemon-set> --type json -p='[{"op": "remove", "path": "/spec/template/spec/nodeSelector/non-existing"}]'
This will scale the daemonset up again.
Upvotes: 175
Reputation: 3374
DaemonSet ensures that every node run a copy of a Pod. So you can't scale down it as Deployment. DaemonSet use DaemonSet Controller and Deployment use Replication Controller for replications. So You can simply delete the DaemonSet.
If you want to backup the exact Daemonset deployment you can use following command and save it somewhere and use it again for later deployement.
kubectl get daemonset <name-of-daemon-set> -n <namespace> -o yaml
Upvotes: 11