Open In App

Kubernetes – Kubectl Delete

Last Updated : 30 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Pre-requisite: Kubernetes

Kubernetes is an open-source Container Management tool that automates container deployment, container scaling, descaling, and container load balancing (also called a container orchestration tool). It is written in Golang and has a huge community because it was first developed by Google and later donated to CNCF (Cloud Native Computing Foundation). kubectl delete is used to delete resources by using a configuration file or by using the type of resource and the resource name.

kubectl delete ([-f FILENAME] | TYPE [(NAME | --all)])

Example: Suppose we are having Nginx web server deployment and Service running.

nginx file

 

nginx service file

 

kubectl get all

 

Deleting  Deployment:

$ kubectl delete deployment deployment_name

Alternatively, you can also point your terminal to the file containing the deployment config file and use the command

$ kubectl delete -f your_config_file.yaml
kubectl delete command

 

Deleting  Service:

$ kubectl delete service service_name

Alternatively, you can also point your terminal to the file containing the deployment config file and use the command

$ kubectl delete -f your_config_file.yaml
kubectl delete command

 

Deleting All Resources:

$ kubectl delete resource_type -all

Examples:

  • Deleting all deployments
$ kubectl delete deployment -all
  • Deleting all services
$ kubectl delete service --all

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads