| by Arround The Web | No comments

How to Delete Ingress Using “kubectl delete” Command?

Management of application traffic is one of the essential parts of application deployment. When applications are deployed in the Kubernetes cluster, traffic management can be a challenge. For this purpose, the Kubernetes Ingress is used. The Ingress is an API object that is used to manage and control the incoming traffic of an application. It exposes the service outside the Kubernetes cluster and manages the host and path-based routing with the help of ingress resource (yaml file). It also implements load balancing and distributes the traffic among various pods.

Sometimes, the user may be required to change the routing rules or may want to remove the application or Kubernetes cluster. Before removing the cluster, the user must delete the ingress and service resources otherwise these resources will be orphaned. Additionally, these resources take much of the system resources to load balance the incoming traffic.

This blog will demonstrate:

How to Delete Ingress Using the “kubectl delete” Command?

When the user no longer needs the ingress to manage external resources or traffic, they are required to turn down or delete the ingress. To delete the ingress using the “kubectl delete” command, follow the listed instructions.

Step 1: Launch PowerShell

Launch and run the PowerShell as an administrator:

Step 2: Start minikube Cluster

Start the minikube Kubernetes cluster using “minikube start” command:

minikube start

Step 3: Get Ingress

Next, access the Kubernetes ingresses using the given command:

kubectl get ingress

Here, you can see currently we have three ingresses:

Step 4: Delete Ingress

To delete any ingress from the Kubernetes cluster, use the “kubectl delete ingress <ingress-name>” command:

kubectl delete ingress demo-ingress

To check if we have deleted the Kubernetes ingress or not, again list down the ingresses:

kubectl get ingress

Here, you can see we have effectively deleted the ingress from the Kubernetes cluster:

How to Delete all Ingress Using the “kubectl delete” Command?

Sometimes, users want to declutter the Kubernetes cluster by removing all unused resources. In order to remove all the ingress from the cluster, use the “kubectl delete –all ingress” command:

kubectl delete --all ingress

For confirmation, access Kubernetes ingresses using the “kubectl get ingress” command:

kubectl get ingress

The output indicates that we have successfully removed all the ingresses from the Kubernetes cluster:

Bonus Tip: How to Delete Ingress Controller Using kubectl delete Command?

The Ingress controller is responsible for managing the application traffic according to the Kubernetes ingress. To process and use ingress, the ingress controller is necessary. When the ingress control is installed and deployed in Kubernetes, it creates and runs ingress controller deployment and service. If the user does not want to use ingress anymore, running these kubernetes resources is not good.

To remove the Ingress controller resources, or to completely delete the ingress controller, follow the below step.

Step 1: Delete Ingress Controller Pods

First, access the Kubernetes namespaces:

kubectl get namespace

Here, you can see we are currently running the “ingress-nginx” controller:

To view all the resources of the currently executing ingress controller, use the “kubectl get all -n <controller-name>” command:

kubectl get all -n ingress-nginx

Here, you can see current ingress controller is using ingress deployments, pods, and ingress controller services:

To remove all the ingress controller pods, use the “kubectl delete –all pods -n <controller-name>” command:

kubectl delete --all pods -n ingress-nginx

Note: At that point when the user deletes the pods, the ingress controller pod will automatically restart, and the user may think about why this pod still exists and how to remove it from the Kubernetes cluster.

For confirmation, access the ingress controller pods using the given command:

kubectl get pods -n ingress-nginx

Here, you can see one pod is still running. This is due to this pod is running within an ingress controller deployment. To remove the ingress controller pod, the user needs to completely delete the ingress controller deployment:

Step 2: Delete Ingress Controller Deployment

When the ingress controller is deployed, it will first create the deployment that runs the ingress controller in the ingress controller pod. To remove the deployments of the ingress controller, use the “kubectl delete –all deployment -n <controller-name>” command:

kubectl delete --all deployment -n ingress-nginx

For verification, list down the ingress controller deployment using below command:

kubectl get deployment -n ingress-nginx

Here, you can see we have removed the deployments successfully:

This will also remove the ingress controller deployment pod. To check the pods, use the given command:

kubectl get pods -n ingress-nginx

Now, you can see the ingress controller pod is also removed with the removal of deployment:

Step 3: Delete Ingress Controller Services

To remove the ingress controller service which enables the controller to interact with external entities, use the given command:

kubectl delete --all services -n ingress-nginx

For verification, list down all components of the Ingress controller:

kubectl get all -n ingress-nginx

Here, you can see we have successfully removed the ingress controller pods, deployments, and services:

Step 4: Delete Ingress Controller Namespace

To completely remove the ingress controller from the Kubernetes cluster, remove its namespace. For this purpose, use the “kubectl delete namespace <controller-name>” command:

kubectl delete namespace ingress-nginx

Now, get the Kubernetes namespaces using the given command:

kubectl get namespace

The output shows that we have completely removed the Ingress controller from the Kubernetes cluster:

That is all about deleting ingress using the “kubectl delete ingress” command.

Conclusion

To remove the ingress from Kubernetes, use the “kubectl delete ingress <ingress-name>” command. To remove all the Kubernetes ingresses, use the “kubectl delete –all ingress” command. To remove the Ingress controller from Kubernetes, the user can simply remove the ingress controller namespace using the “kubectl delete namespace <controller-name>” command. This post has demonstrated how to delete the ingress using the “kubectl delete ingress” command.

Share Button

Source: linuxhint.com

Leave a Reply