Is it possible to know if the node where a Kubernetes Pod is being scheduled is master or worker? Is it possible to know if the node where a Kubernetes Pod is being scheduled is master or worker? kubernetes kubernetes

Is it possible to know if the node where a Kubernetes Pod is being scheduled is master or worker?


Unfortunately, there is not a convenient way to access the node information in pod.

If you only want a single DaemonSet definition, you can add a sidecar container to your pod, the sidecar container can access the k8s api, then your main container can get something useful from the sidecar.

By the way, I think your current solution is properly :)


You can tell a node is the master if it has the label node-role.kubernetes.io/master: "".What you need to do is access that label from your containers which can be done with the Downward Api (Edit: Wrong, only Pod information can be accessed from the Downward Api). You can mount the labels inside your containers using:

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

You can then search the content of that file from within the container.