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?
- How to Delete all Ingress Using the “kubectl delete” Command?
- Bonus Tip: How to Delete Ingress Controller Using the “kubectl delete” Command?
- Conclusion
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:
Step 3: Get Ingress
Next, access the Kubernetes ingresses using the given command:
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:
To check if we have deleted the Kubernetes ingress or not, again list down the ingresses:
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:
For confirmation, access Kubernetes ingresses using the “kubectl get ingress” command:
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:
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:
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:
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:
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:
For verification, list down the ingress controller deployment using below command:
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:
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:
For verification, list down all components of the Ingress controller:
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:
Now, get the Kubernetes namespaces using the given command:
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.