How to delete a deployment / image in kubernetes

34,272

Solution 1

Find out all deployments across all namespaces

kubectl get deploy -A

Then delete a deployment with deploymentname from namespace. deploymentname can be found from above command.

kubectl delete deploy deploymentname -n namespacename

Docs on how to configure kubectl to connect to AKS.

Solution 2

Use the below command.

kubectl delete deployment deployment-name-here

More about the command here.

Share:
34,272

Related videos on Youtube

Carlo Luther
Author by

Carlo Luther

Know languages: c, c#, c++, java, VB, asp.net, sql server, Matlab Know Microcontroller platform: PIC, BasicStamp, Arduino ASP.NET MVC Developer, Angular 2, learning EOS (Dawn) spoken languages: English, Italian, French, Russian

Updated on July 10, 2022

Comments

  • Carlo Luther
    Carlo Luther almost 2 years

    I'm running kubernetes in azure. I want to delete a specific deployment, with AZ AKS or kubectl.

    The only info I've found is how to delete pods, but this is not what I'm looking for, since pods will regenerate once deleted.

    I know I just can go to the ui and delete the deployment but i want to do it with az aks or kubectl.

    enter image description here

    I've run

    kubectl get all -A
    

    enter image description here

    Then I copy the name of the deployment that I want to delete and run:

    kubectl delete deployment zr-binanceloggercandlestick-btcusdt-2hour
    
    kubectl delete deployment deployment.apps/zr-binanceloggercandlestick-btcusdt-12hour
    

    but noting no success, i get these errors:

    Error from server (NotFound): deployments.extensions "zr-binanceloggercandlestick-btcusdt-2hour" not found
    
    
    error: there is no need to specify a resource type as a separate argument when passing arguments in resource/name form (e.g. 'C:\Users\amnesia\.azure-kubectl\kubectl.exe get resource/<resource_name>' instead of 'C:\Users\amnesia\.azure-kubectl\kubectl.exe get resource resource/<resource_name>'
    

    enter image description here

    • switchboard.op
      switchboard.op about 4 years
      Make sure you're specifying the right namespace as Agrhya suggests.
  • Praveen Sripati
    Praveen Sripati about 4 years
    Maybe the default namespace is not set properly. Use the -n option to explicitly specify the namespace.
  • Sumer
    Sumer about 3 years
    But still lot of stuff like ingress etc are not deleted automatically, you need to delete that manually
  • Gaurav
    Gaurav over 2 years
    works flawlessly!