1

I am using jsonnet to describe deployment configuration for Kubernetes.

{
  apiVersion: 'apps/v1',
  kind: 'Deployment',
  metadata: {
    name: 'dapi-test-pod',
  },
  spec: {
    selector: {
      matchLabels: {
        app: 'dapi-test-pod',
      },
    },
    template: {
      metadata: {
        labels: {
          app: 'dapi-test-pod',
        },
      },
      spec: {
        containers: [
          {
            name: 'test-container',
            image: 'library/nginx',
          },
        ]
      },
    },
  },
}

Create deployment using kubecfg:

kubecfg show k8s/deployment.jsonnet | kubectl apply -f -

Everything is going well, but is there any great way to delete deployment using kubecfg and jsonnet file.

Uladzislau Kaminski
  • 2,113
  • 2
  • 14
  • 33

1 Answers1

1

I reproduced your scenario on my cluster and basically the same logic will works for deleting it.

kubecfg show k8s/deployment.jsonnet | kubectl delete -f -

This command will delete everything described in the manifest.

Or you can just delete using bare kubectl:

kubectl delete deployment dapi-test-pod
Mark Watney
  • 5,268
  • 2
  • 11
  • 33
  • I am using the first way to delete the deployment, since the deployment name differs from the file name. But if I use `apply` after `delete` I receive this warning. As I understand warning is about mixing declarative and imperative ways. `Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply` – Uladzislau Kaminski Mar 31 '20 at 19:26
  • What you mean by using `apply` after `delete`? Please, can you update your question including the commands and outputs? – Mark Watney Mar 31 '20 at 19:28
  • 1
    I found the article where everything is explained https://kubernetes.io/docs/concepts/overview/working-with-objects/object-management/#imperative-object-configuration – Uladzislau Kaminski Apr 01 '20 at 11:41