Skip to content

Kubernetes: Delete & force delete

6 Kubernetes commands: Delete & force delete. Click a command to see what each part does.

Index
6 items
Click a command to see what each part does.

Delete & force delete6

  • kubectl delete po <pod> -n <namespace>Delete a pod (its controller recreates it)Caution

    What each part does

    1. delete po <pod>graceful delete; a Deployment/StatefulSet makes a new one
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
  • kubectl delete po <pod> -n <namespace> --grace-period=0 --forceForce delete a stuck podDestructive

    What each part does

    1. --grace-period=0 --forceremove from the API immediately without waiting for the kubelet (pod stuck in Terminating)

    Tip The container may still be running on the node; for StatefulSets this can cause two pods with the same identity.

  • kubectl delete po,svc -l app=<app> -n <namespace>Delete by labelDestructive

    What each part does

    1. po,svcseveral types at once
    2. -l app=<app>everything with that label
  • kubectl delete <type> <name> -n <namespace>Delete a resource by type and nameDestructive

    What each part does

    1. <type> <name>e.g. deploy api, svc api, cm app-config, rs api-7d9f
  • kubectl delete all --all -n <namespace>Delete everything in a namespace (keep the namespace)Destructive

    What each part does

    1. allpods, services, deployments, replicasets, statefulsets, jobs (not configmaps, secrets, PVCs)
    2. --allevery object of those types
  • kubectl delete ns <namespace>Delete a namespace and everything in itDestructive

    What each part does

    1. delete nsremoves the namespace and all objects in it, including PVCs and secrets

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…