如何识别创建 Kubernetes 资源的原因?

如何识别创建 Kubernetes 资源的原因?

我正在调试创建以下资源的原因:

$ kubectl get deploy -o=name | grep datadog
deployment.apps/datadog-cluster-agent
deployment.apps/datadog-kube-state-metrics

每次我删除它们,几秒钟内它们就会再次创建。

只需查看标签,我就能知道它是由 Helm 管理的:

$ kubectl describe deploy/datadog-cluster-agent
Name:                   datadog-cluster-agent
Namespace:              default
CreationTimestamp:      Tue, 26 Jan 2021 18:56:51 -0800
Labels:                 app.kubernetes.io/instance=datadog
                        app.kubernetes.io/managed-by=Helm
                        app.kubernetes.io/name=datadog
                        app.kubernetes.io/version=7
                        contra.com/app-name=datadog
                        helm.sh/chart=datadog-2.7.0

但是,我非常确信 Helm 甚至没有安装在集群上:

$ kubectl get all -A | grep helm
$ kubectl get all -A | grep tiller

deployment每次删除它时,我如何识别是什么创建了此数据狗?

进一步的调试信息:

尝试列出所有相关资源得到:

$ kubectl get all -l app.kubernetes.io/instance=datadog
NAME                                              READY   STATUS    RESTARTS   AGE
pod/datadog-kube-state-metrics-55d9f8659f-5tqsl   1/1     Running   0          4m43s

NAME                                 TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
service/datadog-cluster-agent        ClusterIP   10.0.14.155   <none>        5005/TCP   6h16m
service/datadog-kube-state-metrics   ClusterIP   10.0.2.87     <none>        8080/TCP   20d

NAME                     DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
daemonset.apps/datadog   5         5         4       1            4           kubernetes.io/os=linux   3m45s

NAME                                         READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/datadog-cluster-agent        1/1     1            1           4m37s
deployment.apps/datadog-kube-state-metrics   1/1     1            1           4m43s

NAME                                                    DESIRED   CURRENT   READY   AGE
replicaset.apps/datadog-kube-state-metrics-55d9f8659f   1         1         1       4m43s

如果我使用删除所有资源kubectl delete all -l app.kubernetes.io/instance=datadog,它们会在几秒钟内重新创建。

答案1

您应该检查部署 JSON 或 YAML 定义。在元数据中,应该有一个所有者引用,例如:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: "2021-01-12T08:34:06Z"
  generation: 1
  name: eventlistener
  namespace: ci
  ownerReferences:
  - apiVersion: triggers.tekton.dev/v1alpha1
    blockOwnerDeletion: true
    controller: true
    kind: EventListener
    name: github-listener
    uid: 54a7115e-565d-4239-b8fc-66e94c6c221b
spec:
...

当一个对象由另一个对象创建时,您应该找到该所有者引用,它会告诉您谁应该受到指责。

相关内容