如何删除kubernetes service服务

识趣 发表于: 2022-01-04   最后更新时间: 2022-01-05 00:05:34   688 游览

我执行了以下命令:

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

请问我该如何清理删除这些服务?或者只显示一个。

发表于 2022-01-04

非常简单

1、获取所有可用的服务。

kubectl get service -o wide

2、然后你可以像这样删除任何服务。

kubectl delete svc <YourServiceName>

也可以批量删除

kubectl delete svc <YourServiceName> <YourServiceName>
识趣 -> 半兽人 2年前

感谢大佬

你的答案

查看kubernetes相关的其他问题或提一个您自己的问题