从昨天开始,我在使用GKE的K8上遇到一个奇怪的错误
我有一个正在运行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
答案 0 :(得分:-3)
如果您只想简单删除,请尝试使用
kubectl delete -f dummy_deployment.yaml
kubectl 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来说,删除它会花费太多时间。