Prerequisites:

  • The virtual-kubelet node is deployed in the target Kubernetes cluster. Note that a serverless Kubernetes cluster is embedded with the virtual-kubelet node.

Elastic Container Instance (ECI) provides native support for the Downward API. You can use the Downward API in an ECI in the same way as that in native Kubernetes. Currently, you can use the Downward API to expose the following information about an ECI to containers in the ECI:

  • metadata.annotations
  • metadata.labels
  • metadata.name
  • metadata.namespace
  • metadata.uid

Take annotations and labels as an example. Save the following sample code in a YAML file named pod.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: test-downwardapi
  labels:
    region: cn-beijing
    zone: cn-beijing-h
  annotations:
    eci/test: virtual-kubelet
spec:
  nodeName: virtual-kubelet
  containers:
    - name: nginx
      image: nginx
      command: ["sh", "-c"]
      args:
      - while true; do cat /etc/podinfo/labels; sleep 5; cat /etc/podinfo/annotations; sleep 5; done
      volumeMounts:
        - name: podinfo
          mountPath: /etc/podinfo
  volumes:
    - name: podinfo
      downwardAPI:
        items:
          - path: "labels"
            fieldRef:
              fieldPath: metadata.labels
          - path: "annotations"
            fieldRef:
              fieldPath: metadata.annotations

Use the kubectl client to create an ECI based on the preceding configuration file.

# kubectl create -f pod.yaml
pod/test-downwardapi created
# kubectl get pod test-downwardapi
NAME               READY   STATUS    RESTARTS   AGE
test-downwardapi   1/1     Running   0          32s
# kubectl logs -f test-downwardapi
zone="cn-beijing-h"eci/test="virtual-kubelet"region="cn-beijing"
zone="cn-beijing-h"eci/test="virtual-kubelet"region="cn-beijing"
zone="cn-beijing-h"eci/test="virtual-kubelet"region="cn-beijing"
zone="cn-beijing-h"eci/test="virtual-kubelet"region="cn-beijing"
zone="cn-beijing-h"eci/test="virtual-kubelet"region="cn-beijing"
zone="cn-beijing-h"eci/test="virtual-kubelet"region="cn-beijing"
zone="cn-beijing-h"eci/test="virtual-kubelet"region="cn-beijing"
zone="cn-beijing-h"eci/test="virtual-kubelet"region="cn-beijing"
zone="cn-beijing-h"eci/test="virtual-kubelet"region="cn-beijing"
zone="cn-beijing-h"eci/test="virtual-kubelet"region="cn-beijing"