简体   繁体   English

如何将 kubernetes daemonset 扩展到 0?

[英]how to scale kubernetes daemonset to 0?

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.当 pod 被 daemonset 控制时,pod 出现一些错误,状态会是CrashLoopBackOff ,我想删除这些 pod 但不删除 DaemonSet。

So I want to scale daemonset to 0, as far as I known, DaemonSet Spec do not support the replica of the pod.所以我想把daemonset缩放到0,据我所知,DaemonSet Spec不支持pod的replica。

How can I get there?我要怎么去那儿?

DaemonSet ensures that every node run a copy of a Pod. DaemonSet确保每个节点都运行Pod的副本。 So you can't scale down it as Deployment. 因此,您不能将其缩减为“部署”。 DaemonSet use DaemonSet Controller and Deployment use Replication Controller for replications. DaemonSet使用DaemonSet控制器,而Deployment使用Replication Controller进行复制。 So You can simply delete the DaemonSet. 因此,您只需删除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. 如果要备份准确的Daemonset部署,则可以使用以下命令并将其保存在某处,然后再次使用它进行以后的部署。

kubectl get daemonset <name-of-daemon-set> -n <namespace> -o yaml

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: 如果您不想删除该守护程序集,一种可能的解决方法是对任何不存在的标签使用临时的nodeSelector ,例如:

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 : 这是删除临时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. 这将再次扩展守护程序。

only as addition to Alex Vorona's answer for scaling to more than 0 nodes:仅作为 Alex Vorona 扩展到 0 个以上节点的答案的补充:

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"}}}}}'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM