【发布时间】:2020-05-19 14:19:16
【问题描述】:
从昨天开始,我在 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 -n default delete deployment dummy-deployment 删除部署后立即从 kubectl get events 创建没有日志
在创建部署后立即从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
【问题讨论】:
-
让我们从头开始。你能重现这个问题吗?我的意思是,删除您剩余的任何副本集,然后验证您没有运行任何 pod。现在创建部署,然后将其删除。如果此问题仍然存在,请提供部署 yaml,以及您按订单发出的 exact 命令,我将尝试在我的集群上使用相同的 k8s 版本重现此问题。
-
依赖文件太多。该部署使用服务帐户、大量 K8s 机密、永久磁盘和优先级。您很难在集群中重现确切的环境。谢谢!
-
好的,我使用更简单的部署复制了它。
-
请张贴这些命令的输出之前和之后你应用任何东西:
kubectl -n default get pods | grep dummy kubectl -n default get replicasets | grep dummy -
我尝试在新集群上重现此问题,但无法重现。在您的一个命令中,您有错字。它应该是
dummy-deployment而不是dummy_deployment。你能从 pod 中收集任何日志吗?任何特定的输出形式kubectl get events?它一直在发生吗?如果您手动删除Replicaset,您会收到任何错误吗?
标签: kubernetes deployment google-kubernetes-engine replicaset