gpt4 book ai didi

kubernetes - GKE 删除部署不会删除副本集

转载 作者:行者123 更新时间:2023-12-03 22:43:57 30 4
gpt4 key购买 nike

从昨天开始,我在 K8s 上遇到了一个奇怪的错误(使用 GKE)
我有一个运行 1 个 pod 的部署。我删除了部署,它用于终止 pod 和使用它的副本集。
但是现在,如果我删除部署,副本集不会被删除,因此 pod 会继续运行。
还有其他人有这个问题吗?或者知道解决这个问题的方法吗?
在删除之前,我是否应该将部署的副本计数降至 0?或其他一些解决方案?
我正在使用 v1.15.9-gke.24
复制的虚拟示例
dummy_deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: dummy-deployment
namespace: default
spec:
replicas: 1
selector:
matchLabels:
name: dummy
template:
metadata:
labels:
name: dummy
spec:
serviceAccountName: dummy-serviceaccount
nodeSelector:
cloud.google.com/gke-nodepool : default-pool
containers:
- name: pause
image: gcr.io/google_containers/pause
resources:
limits:
memory: 100M
requests:
cpu: 100m
memory: 100M
dummy_serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: dummy-serviceaccount
namespace: default

我运行的命令
kubectl apply -f dummy_serviceaccount.yaml
kubectl apply -f dummy_deployment.yaml
kubectl -n default get pods | grep dummy
kubectl delete deployments dummy-deployment
kubectl -n default get pods | grep dummy
kubectl -n default get replicasets | grep dummy

有趣的观察
deployment.extensions "dummy-deployment" deleted

deployment.apps/dummy-deployment created
使用 kubectl apply 创建新部署时, deployment.apps被创建。但是当使用 kubectl delete 删除部署时, deployment.extensions被删除。
没有从 kubectl get events 创建的日志使用 kubectl -n default delete deployment dummy-deployment 删除部署后立即
来自 kubectl get events 的日志创建部署后立即
2m24s       Normal   Scheduled           pod/dummy-deployment-69946b945f-txvvr          Successfully assigned default/dummy-deployment-69946b945f-txvvr to gke-XXX-default-pool-c7779722-7j9x
2m23s Normal Pulling pod/dummy-deployment-69946b945f-txvvr Pulling image "gcr.io/google_containers/pause"
2m22s Normal Pulled pod/dummy-deployment-69946b945f-txvvr Successfully pulled image "gcr.io/google_containers/pause"
2m22s Normal Created pod/dummy-deployment-69946b945f-txvvr Created container pause
2m22s Normal Started pod/dummy-deployment-69946b945f-txvvr Started container pause
2m24s Normal SuccessfulCreate replicaset/dummy-deployment-69946b945f Created pod: dummy-deployment-69946b945f-txvvr
2m24s Normal ScalingReplicaSet deployment/dummy-deployment Scaled up replica set dummy-deployment-69946b945f to 1
kubectl -n default get pods | grep dummy 之前:空
后:
kubectl -n default get pods | grep dummy 
dummy-deployment-69946b945f-txvvr 1/1 Running 0 6s
kubectl -n default get replicasets | grep dummy之前:空
后:
kubectl -n default get replicasets | grep dummy
dummy-deployment-69946b945f 1 1 1 12s
2021 年 1 月 29 日更新
这是我运行以完全删除 pod 的代码
def delete_deployment(namespace, notebook_id):
command1 = f"kubectl -n {namespace} get deployments | grep {notebook_id} | sed 's/ */ /g' | cut -d' ' -f1 | xargs kubectl -n {namespace} delete deployments"
command2 = f"kubectl -n {namespace} get replicasets | grep {notebook_id} | sed 's/ */ /g' | cut -d' ' -f1 | xargs kubectl -n {namespace} delete replicasets"
command3 = f"kubectl -n {namespace} get pods | grep {notebook_id} | sed 's/ */ /g' | cut -d' ' -f1 | xargs kubectl -n {namespace} delete pods"

command_final = f"{command1};{command2};{command3}"
#command_final = command1

try:
subprocess.run(command_final, shell=True)
except:
return False

return True

最佳答案

如果您只想简单删除,请尝试使用
kubectl delete -f dummy_deployment.yamlkubectl delete -f dummy_serviceaccount.yaml
最佳做法是使用创建它们的文件删除 Kubernetes 对象以进行完全删除。此外,尝试在命名空间内创建对象以保持进程隔离。从而你可以做一个 kubectl delete namespace test-ns省去一一删除实体的麻烦。

您始终可以获得更高级别的详细信息 (--v=6 or --v=9)--v=6 删除的内容和方式或 --v=9旗帜
kubectl delete deployment dummy-deployment --v=6
但是,行为不是预期的,集群资源删除肯定有问题。天蓝色 PVC 的情况下,删除需要太多时间。

关于kubernetes - GKE 删除部署不会删除副本集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61893359/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com