34

当 daemonset 控制的 Pod 时,Pod 出现错误,状态为CrashLoopBackOff,我想删除这些 Pod 但不删除 DaemonSet。

所以我想将daemonset缩放到0,据我所知,DaemonSet Spec不支持pod的replica。

我如何到那里?

4

3 回答 3

86

如果您不想删除守护程序集,一种可能的解决方法是使用带有任何不存在标签的临时nodeSelector,例如:

kubectl -n <namespace> patch daemonset <name-of-daemon-set> -p '{"spec": {"template": {"spec": {"nodeSelector": {"non-existing": "true"}}}}}'

这将缩小守护程序集。

这是删除临时的补丁nodeSelector

kubectl -n <namespace> patch daemonset <name-of-daemon-set> --type json -p='[{"op": "remove", "path": "/spec/template/spec/nodeSelector/non-existing"}]'

这将再次扩展守护程序集。

于 2019-08-17T04:45:28.323 回答
7

DaemonSet 确保每个节点都运行一个 Pod 的副本。因此,您不能将其缩小为部署。DaemonSet 使用 DaemonSet Controller 和 Deployment 使用 Replication Controller 进行复制。所以你可以简单地删除 DaemonSet。

如果要备份确切的 Daemonset 部署,可以使用以下命令并将其保存在某处并再次使用它以供以后部署。

kubectl get daemonset <name-of-daemon-set> -n <namespace> -o yaml
于 2018-12-26T09:23:42.723 回答
4

仅作为 Alex Vorona 对扩展到超过 0 个节点的回答的补充:

扩展到单个节点:

kubectl -n <namespace> patch daemonset <name-of-daemon-set> -p '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "<hostname>"}}}}}'

扩展到带有一些标签的任意数量的节点:

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"}}}}}'
于 2021-09-20T12:21:49.103 回答