how to delete kubectl service

Solution 1:

Simply call this command.

1/Get all available services:

kubectl get service -o wide

2/ Then you can delete any services like this:

kubectl delete svc <YourServiceName>

Solution 2:

show deployment

$ 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

show services

$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

delete deployment

$ kubectl delete deployments vfe-hello-wrold

deployment.extensions "vfe-hello-wrold" deleted

delete services

$ kubectl delete service vfe-hello-wrold

service "vfe-hello-wrold" deleted

Solution 3:

Kubernetes objects like Service and Deployment/ReplicaSet/Pod are independent and their deletions do not cascade to each other (like it does between say Deployment/RS/Pod). You need to manage your services independently from other objects, so you just need to delete the ones that are still lingering behind.

Solution 4:

If you want to delete multiple related or non related objects at the same time

 kubectl delete <objType>/objname <objType>/objname <objType>/objname

Example

 kubectl delete service/myhttpd-clusterip service/myhttpd-nodeport

 kubectl delete service/myhttpd-lb deployment/myhttpd

This also works

kubectl delete deploy/httpenv svc/httpenv-np

Solution 5:

To delete ALL services in ALL namespaces just run:

kubectl delete --all services --namespace=*here-you-enter-namespace

The other option is to delete the deployment with:

kubectl delete deployment deployment-name

That will delete the service as well!

IMPORTANT: And watch out when you run this command in production!

Cheers!