Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete deployment and associated pods? #148

Open
de1m opened this issue Sep 28, 2017 · 3 comments
Open

Delete deployment and associated pods? #148

de1m opened this issue Sep 28, 2017 · 3 comments
Labels
help wanted request for example kubernetes-client user is requesting an example implementation

Comments

@de1m
Copy link

de1m commented Sep 28, 2017

Hi,

const Api = require('kubernetes-client');

const deploy = new Api.Extensions({
    url: 'https://SERVER:6443',
    version: 'v1beta1',  // Defaults to 'v1beta1'
    insecureSkipTlsVerify: true,
    auth: {
        user: 'root',
        pass: 'pass'
    }
});

function print(err, result) {
    console.log(JSON.stringify(err || result, null, 2));
}

// deploy.ns('fortesting').deploy('echoserver').get(print);
deploy.ns('fortesting').deploy({name: 'echoserver', qs: { PropagationPolicy: false }}).delete(print);

Output:

{
  "code": 404
}

I can delete the deploy with 'deploy.ns('fortesting').deploy('echoserver').delete(print);` but this command cannot delete the pods, which I've created through deploy.

I've found the issue #62 , the option orphanDependents is depricated ([https://kubernetes.io/docs/api-reference/v1.6/#deployment-v1beta1-extensions](doc api)) it's now PropagationPolicy.

@silasbw
Copy link
Contributor

silasbw commented Nov 8, 2017

Sorry for the delay .. did you resolve this? Did you try:

deploy.ns('fortesting').deploy('echoserver').delete({ qs: { PropagationPolicy: false }}, print);

or

deploy.ns('fortesting').deploy.delete({ name: 'echoserver' qs: { PropagationPolicy: false }}, print);

@gempesaw
Copy link
Contributor

gempesaw commented Dec 18, 2017

Somewhat confusingly, the Concepts docs say you can send a body in to the DELETE endpoint as well: https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/#setting-the-cascading-deletion-policy

$ kubectl proxy --port=8080 &
$ curl -X DELETE localhost:8080/apis/extensions/v1beta1/namespaces/default/replicasets/my-repset \
-d '{"kind":"DeleteOptions","apiVersion":"v1","propagationPolicy":"Foreground"}' \
-H "Content-Type: application/json"

which IIRC you can do with this library something like

// warning: untested code
deploy.ns('foresting').deploy('echoserver').delete({ body: { kind: 'DeleteOptions', apiVersion: 'v1', propagationPolicy: 'Foreground' } })

although I'm not 100% sure on that, since we don't do that method anymore. With our version of Kubernetes (1.8), the propagationPolicy: 'Foreground' was deleting the deployment and the pods, but it was orphaning replica sets, which recreated the pods on their own.

Our solution was to trace kubectl delete deployment echoserver -v9 to see how they did it, and then we tried to replicate that logic in our code:

  1. get the deployment (to make sure it exists, i guess)
  2. pause the deployment and set replicas to 0. (you can use the body from 1 to PUT the whole thing along with the pause and replicas: 0. or we ended up doing a PATCH with body { spec: { replicas: 0, revisionHistoryLimit: 0, paused: true } }.
  3. get all the matching replica sets for the paused deployment
  4. for each replica set, PUT or PATCH set its desired replicas to 0 to delete the pods via spec.replicas
  5. loop on a GET of the replica sets until the status.replicas is 0
  6. delete the now-empty replica sets
  7. delete the now-empty paused deployment

@silasbw silasbw added help wanted request for example kubernetes-client user is requesting an example implementation labels Mar 17, 2018
@RobertDiebels
Copy link

Has someone tried this out yet? I've made an attempt though it was unsuccessful. Also, the fact that kubectl does it like described above is kind of disturbing. I'd assume a delete request would be sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted request for example kubernetes-client user is requesting an example implementation
Projects
None yet
Development

No branches or pull requests

4 participants