【问题标题】:How to use the instance ID in Daemonset config file in Kubernetes?如何在 Kubernetes 的 Daemonset 配置文件中使用实例 ID?
【发布时间】:2019-02-05 01:48:57
【问题描述】:

我想从我的 k8s 配置文件中获取我的 pod 正在运行的实例 ID(例如 AWS EC2 实例 ID,如 i-19a9fa9s8df9a8,而不是私有 dns 节点名称),但找不到任何文档关于如何做到这一点。有人知道如何使用https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#event-v1-core 中的reportingInstance 字段吗?

我收到此错误:

The DaemonSet  is invalid:
spec.template.spec.containers[0].env[8].valueFrom.fieldRef.fieldPath: 
Invalid value: "core.reportingInstance": 
error converting fieldPath: field label not supported: core.reportingInstance

这是我尝试过的:

    - name: INSTANCE_ID
      valueFrom:
        fieldRef:
          fieldPath: core.reportingInstance

我的 yaml 文件中已经有这个,但它给出了私有 dns 名称而不是实例 ID

   - name: NODE_NAME
      valueFrom:
        fieldRef:
          fieldPath: spec.nodeName

【问题讨论】:

  • 你能提供你使用的完整的yaml吗?

标签: amazon-ec2 kubernetes daemonset


【解决方案1】:

让我以我对您问题的理解来回答这个问题。我认为您希望将节点名称值设置为容器中的 env 变量。如果这是真的,你可以使用下面的代码

 - name: Node_Name
      valueFrom:
        fieldRef:
          fieldPath: spec.nodeName

如果您想了解有关 pod 或容器的其他信息,请理解您只能使用向下 api 获取容器内的有限信息,并且仅限于以下提到的字段。

 fieldRef     <Object>
 Selects a field of the pod: supports metadata.name, metadata.namespace,
 metadata.labels, metadata.annotations, spec.nodeName,
 spec.serviceAccountName, status.hostIP, status.podIP.


resourceFieldRef     <Object>
 Selects a resource of the container: only resources limits and requests
 (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu,
 requests.memory and requests.ephemeral-storage) are currently supported.

【讨论】:

  • 不,我想要实例 id,而不是节点的名称,例如对于 AWS EC2 实例,它有一个实例 id 和一个私有 dns(节点名称),我想要实例 id ,我现在用这个信息更新了问题
猜你喜欢
  • 2020-03-13
  • 1970-01-01
  • 1970-01-01
  • 2016-10-01
  • 2019-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-03
相关资源
最近更新 更多