How to delete all resources from Kubernetes one time?

后端 未结 3 1960
暗喜
暗喜 2020-12-23 16:10

Include:

  • Daemon Sets
  • Deployments
  • Jobs
  • Pods
  • Replica Sets
  • Replication Controllers
  • Stateful Sets
  • Se
3条回答
  •  悲&欢浪女
    2020-12-23 17:00

    Kubernetes Namespace would be the perfect options for you. You can easily create namespace resource.

    kubectl create -f custom-namespace.yaml

    $  apiVersion: v1
        kind: Namespace
        metadata:
          name:custom-namespace
    

    Now you can deploy all of the other resources(Deployment,ReplicaSet,Services etc) in that custom namespaces.

    If you want to delete all of these resources, you just need to delete custom namespace. by deleting custom namespace, all of the other resources would be deleted. Without it, ReplicaSet might create new pods when existing pods are deleted.

    To work with Namespace, you need to add --namespace flag to k8s commands.

    For example:

    kubectl create -f deployment.yaml --namespace=custom-namespace

    you can list all the pods in custom-namespace.

    kubectl get pods --namespace=custom-namespace

提交回复
热议问题