我执行了以下命令:% kubectl get service
它返回了使用kubectl在一个时间点创建的服务列表:
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
car-example-service 10.0.0.129 <nodes> 8025:31564/TCP,1025:31764/TCP 10h
circle-example-service 10.0.0.48 <nodes> 9000:30362/TCP 9h
demo-service 10.0.0.9 <nodes> 8025:30696/TCP,1025:32047/TCP 10h
example-servic 10.0.0.168 <nodes> 8080:30231/TCP 1d
example-service 10.0.0.68 <nodes> 8080:32308/TCP 1d
example-service2 10.0.0.184 <nodes> 9000:32727/TCP 13h
example-webservice 10.0.0.35 <nodes> 9000:32256/TCP 1d
hello-node 10.0.0.224 <pending> 8080:32393/TCP 120d
kubernetes 10.0.0.1 <none> 443/TCP 120d
mouse-example-service 10.0.0.40 <nodes> 9000:30189/TCP 9h
spring-boot-web 10.0.0.171 <nodes> 8080:32311/TCP 9h
spring-boot-web-purple 10.0.0.42 <nodes> 8080:31740/TCP 9h
我不再希望列出任何这些服务,因为当我列出资源时:
% kubectl get rs
我希望我只看到列出的spring-boot-web资源。
NAME DESIRED CURRENT READY AGE
spring-boot-web-1175758536 1 1 0 18m
当资源仅显示1个资源时,请帮助澄清我看到列出的服务的原因。
答案 0 :(得分:11)
只需调用此命令即可。
1 /获取所有可用服务:
kubectl get service -o wide
2 /然后您可以删除任何类似的服务:
kubectl delete svc <YourServiceName>
答案 1 :(得分:4)
如果您要同时删除多个相关或不相关的对象
kubectl delete <objType>/objname <objType>/objname <objType>/objname
示例
kubectl delete service/myhttpd-clusterip service/myhttpd-nodeport
kubectl delete service/myhttpd-lb deployment/myhttpd
这也有效
kubectl delete deploy/httpenv svc/httpenv-np
答案 2 :(得分:2)
要删除所有名称空间中的所有服务,只需运行:
kubectl删除-所有服务-所有命名空间
干杯!
答案 3 :(得分:1)
Kubernetes对象(如Service and Deployment / ReplicaSet / Pod)是独立的,它们的删除不会相互级联(就像在Deployment / RS / Pod之间那样)。您需要独立于其他对象管理您的服务,因此您只需要删除那些仍然遗留下来的服务。
答案 4 :(得分:0)
$ kubectl get deployments;
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
spring-hello 1 1 1 1 22h
spring-world 1 1 1 1 22h
vfe-hello-wrold 1 1 1 1 14m
$kubectl get services;
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d
spring-hello NodePort 10.103.27.226 <none> 8081:30812/TCP 23h
spring-world NodePort 10.102.21.165 <none> 8082:31557/TCP 23h
vfe-hello-wrold NodePort 10.101.23.36 <none> 8083:31532/TCP 14m
$ kubectl delete deployments vfe-hello-wrold
deployment.extensions "vfe-hello-wrold" deleted
$ kubectl delete service vfe-hello-wrold
service "vfe-hello-wrold" deleted