How to uninstall Kubernetes deployment

Deploying Kubernetes starts multiple replicas of your application and automatically replaces any instances that are down or stop responding.

As you practice Kubernetes, you often need to delete Kubernetes deployments.

Removing deployments is easy thanks to the kubectl delete deployments command:

kubectl delete deployment deployment_name

We’ll go into this a little more detail with the steps to get the deployment name. We’ll also show you another way to delete deployments in Kubernetes.

Use kubectl delete deployment command to delete Kubernetes deployments

Although the tab is usually complete, you’d better provide the name of the deployment you want to delete.

[email protected]:~# kubectl get deployments
NAME     READY   UP-TO-DATE   AVAILABLE   AGE
my-dep   2/2     2            2           4m22s

When you have a deployment name, just use it like this:

kubectl delete deployments my-dep

It should show output telling you that your deployment has been deleted:

[email protected]:~/pod-create# kubectl delete deployments my-dep
deployment.apps "my-dep" deleted

You can verify this by checking the available deployments:

[email protected]:~/pod-create# kubectl get deployments
No resources found in default namespace.

You can also use deployment or deployments (with s) instead of deployment in the kubectl delete deployment command. All the same.

Removing multiple deployments

You can remove more than one Kubernetes deployment as follows:

[email protected]:~/pod-create# kubectl delete deployment my-dep my-dep-2

Removing Kubernetes deployments using a YAML configuration file

Let me show you this step by step.

We create a new deployment using the deployment-definition.yml file:

[email protected]:~/pod-create# kubectl apply -f deployment-definition.yml
deployment.apps/my-dep created

You can now see the deployment:

[email protected]:~/pod-create# kubectl get deployments
NAME     READY   UP-TO-DATE   AVAILABLE   AGE
my-dep   2/2     2            2           49s

Now if you refer to the same YAML file for deletion, it will delete the resources (deployments here) associated with that file.

[email protected]:~/pod-create# kubectl delete -f deployment-definition.yml
deployment.apps "my-dep" deleted

You can verify this by listing all deployments:

[email protected]:~/pod-create# kubectl get deployments
No resources found in default namespace.

I hope you enjoy this quick tip on Kubernetes.

Sidebar