Search code examples
kuberneteskubectl

Is delete in Kubernetes idempotent


Is calling Delete in the Kubernetes go API an idempotent operation, i.e. can it safely be called twice? If so, is there any documentation defining this property? The go code just states

Delete deletes the given obj from Kubernetes cluster.

Essentially, this statement is what one would expect anyway when looking at the code.


Solution

  • The api service is based on http, so you can check RFC 7231 about that

    A request method is considered "idempotent" if the intended effect on the server of multiple identical requests with that method is the same as the effect for a single such request. Of the request methods defined by this specification, PUT, DELETE, and safe request methods are idempotent.

    If your're using kubectl the delete command will fail on the second run, because the resource can not be found. You can prevent it from failing by using the --ignore-not-found flag.

    $ kubectl run nginx --image nginx
    pod/nginx created
    $ kubectl delete pod nginx
    pod "nginx" deleted 
    $ kubectl delete pod nginx
    Error from server (NotFound): pods "nginx" not found
    $ kubectl delete pod nginx --ignore-not-found
    

    So it's idempotent on the server but not on the client.