>_ IzzyLab

Hands-on task

This task is step 9 of the course “Kubernetes: first steps”

Clean up the cluster

easy~6 min

The promo campaign is over, time to clean up. Delete everything left of it from the cluster — Deployment promo and Service promo. While you're at it, remove pod debug: someone started it for debugging and forgot about it.

Leave the shop store — its Deployment and Service — alone: it has to keep running.

What you'll practise:
  • kubernetes
  • kubectl delete
  • kubectl get all

Topic breakdown

Objects in a cluster live until they're deleted: an unneeded Deployment keeps holding its pods, and a Service keeps its name taken. You delete them with kubectl delete:

kubectl delete pod test                        # one pod
kubectl delete pod test1 test2                 # several objects of one type
kubectl delete deployment/api service/api      # objects of different types — in type/name form

Deleting a Deployment also deletes all its pods. But deleting a Deployment's pods one by one is pointless — it immediately creates replacements.

kubectl get all shows the main objects of a namespace at once: pods, services, Deployments, ReplicaSets. Handy for looking around before and after a cleanup.

Be careful with bulk deletion: kubectl delete pods --all or kubectl delete all --all delete everything in the namespace, including what you need.

What's checked

  1. Deployment and Service promo are deleted
  2. Pod debug is deleted and the shop store works as before

What it looks like