首页 > 解决方案 > 来自服务器的错误 (NotFound): deployments.extensions "1" not found(在 Kubernetes 中删除部署时出错)

问题描述

尝试使用以下命令删除部署时出现此错误,任何想法或建议可能是什么原因以及我如何只能限制删除实际运行的部署?

kubectl delete deployments $(kubectl get deployments | awk 'match($6,/[0-9]+d/) {print $0}') 

来自服务器的错误 (NotFound): deployments.extensions "1" not found

来自服务器的错误 (NotFound): deployments.extensions "1d" not found

标签: kubernetescontainers

解决方案


我不确定,但可能 'kubectl get deployment' 命令中的列数在不同的 Kubernetes 客户端版本之间有所不同,因此为避免这种行为,最好使用 custom-columns 选项格式化输出以具有固定数量的字段'awk' 处理的更可预测的行为,例如

kubectl get deployment -o custom-columns=DEPLOYMENT:.metadata.name,READY_REPLICAS:.status.readyReplicas | awk '$2 ~ /[1-9]+/ {print $1}'

推荐阅读