apiVersion: v1
kind: Pod
metadata:
  name: busybox-env
spec:
  containers:
  - name: busybox-container
    image: busybox
    command:
      - sleep
      - "3600"
    env:
    - name: MY_NODE_NAME # 获取node名称
      valueFrom:
        fieldRef:
          fieldPath: spec.nodeName
    - name: MY_POD_NAME # 获取pod名称
      valueFrom:
        fieldRef:
          fieldPath: metadata.name
    - name: MY_POD_NAMESPACE # 获取pod的namespace
      valueFrom:
        fieldRef:
          fieldPath: metadata.namespace
    - name: MY_POD_IP # 获取pod IP
      valueFrom:
        fieldRef:
          fieldPath: status.podIP
    volumeMounts:
    - name: podname-volume
      mountPath: /var/run/secrets/kubernetes.io/podname
      readOnly: true
  volumes:
    - name: podname-volume
      downwardAPI:
        items:
          - path: "podname"
            fieldRef:
              fieldPath: metadata.name
