k8s删除不了pod和service
# 原因
由于k8s的自愈能力,当我们删除一个pod,k8s会自动恢复一个pod 那么我们如何真正的删掉它呢
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-5d59d67564-6k5t5 1/1 Running 0 30m
nginx-deployment-5d59d67564-b65tc 1/1 Running 0 30m
nginx-deployment-5d59d67564-hxqhd 1/1 Running 0 30m
[root@master ~]# kubectl delete pod nginx-deployment-5d59d67564-6k5t5
pod "nginx-deployment-5d59d67564-6k5t5" deleted
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-5d59d67564-b65tc 1/1 Running 0 32m
nginx-deployment-5d59d67564-f2t5b 1/1 Running 0 14s
nginx-deployment-5d59d67564-hxqhd 1/1 Running 0 32m
[root@master ~]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 3/3 3 3 32m
[root@master ~]# kubectl delete deployment nginx-deployment
deployment.apps "nginx-deployment" deleted
[root@master ~]# kubectl get pods
No resources found in default namespace.
[root@master ~]#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
值得注意的是这样删除相当于删除了容器,而images还存在*
[root@master ~]# kubectl create -f nginx-service.yaml
Error from server (AlreadyExists): error when creating "nginx-service.yaml": services "nginx-service" already exists
[root@master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 5d8h
nginx NodePort 10.104.146.241 <none> 80:30592/TCP 109m
nginx-service NodePort 10.102.219.158 <none> 88:32749/TCP 57m
redis-service ClusterIP None <none> 6379/TCP 6h12m
[root@master ~]# kubectl delete svc nginx
service "nginx" deleted
[root@master ~]# kubectl delete svc nginx-service
service "nginx-service" deleted
[root@master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 5d8h
redis-service ClusterIP None <none> 6379/TCP 6h12m
[root@master ~]#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17