【发布时间】:2021-11-03 18:22:25
【问题描述】:
我希望能够从 pod 中了解创建 pod 的 Deployment 的 Kubernetes uid。
这样做的原因是 Pod 可以生成另一个 Deployment,并将该 Deployment 的 OwnerReference 设置为原始 Deployment(因此当原始 Deployment 被删除时它会被垃圾收集)。
从here获得灵感,我试过了*:
- 将字段引用用作环境变量:
containers:
- name: test-operator
env:
- name: DEPLOYMENT_UID
valueFrom:
fieldRef: {fieldPath: metadata.uid}
- 使用
downwardAPI并通过卷上的文件公开:
containers:
volumeMounts:
- mountPath: /etc/deployment-info
name: deployment-info
volumes:
- name: deployment-info
downwardAPI:
items:
- path: "uid"
fieldRef: {fieldPath: metadata.uid}
*这两个都在spec.template.spec 的一种资源下:部署。
但是,对于这两者来说,uid 是 Pod 的,而不是 Deployment 的。我正在尝试做的事情可能吗?
【问题讨论】:
-
您使用的是哪个 Kubernetes 版本以及在哪里:云端还是裸机?
-
云 Kubernetes,1.20 版