injecting controller's information into containers in k8s

3/2/2018

downwardAPI could be used to inject pod's information into containers.

That could be done as below,

  volumes:
    - name: stinfo
          downwardAPI:
            items:
              - path: "annotations"
                fieldRef:
                  fieldPath: metadata.annotations
              - path: "labels"
                fieldRef:
                  fieldPath: metadata.labels

Now I want to inject controllers' information into containers, how could I do that?

For example, I want to know how many replicas there is for deployment/statefulset.

Any advice?

Thx.

-- Jared
kubernetes

1 Answer

3/2/2018

The information you look for is dynamic so to get that you should use service account bound to your pod (for RBAC make sure it is attached and can read what you need) and make a direct API call to get current value.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow