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?
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.
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