<p>I'm currently using Kubernetes to schedule a DaemonSet on both master and worker nodes. </p>

<p>The DaemonSet definition is the same for both node types (same image, same volumes, etc), the only difference is that when the entrypoint is executed, I need to write a different configuration file (which is generated in Python with some dynamic values) if the node is a master or a worker.</p>

<p>Currently, to overcome this I'm using two different DaemonSet definitions with an env value which tells if the node is a master or not. Here's the yaml file (only relevant parts):</p>

<pre><code>apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: worker-ds
  namespace: kube-system
  labels:
    k8s-app: worker
spec:
  ...
    spec:
      hostNetwork: true
      containers:
        - name: my-image
          ...
          env:
            - name: NODE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            - name: IS_MASTER
              value: "false"
      ...
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: master-ds
  namespace: kube-system
  labels:
    k8s-app: master
spec:
  ...
    spec:
      hostNetwork: true
      nodeSelector:
        node-role.kubernetes.io/master: ""
      tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
      containers:
        - name: my-image
          ...
          env:
            - name: NODE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            - name: IS_MASTER
              value: "true"
      ...
</code></pre>

<p>However, since the only difference is the <strong>IS_MASTER</strong> value, I want to collapse both the definitions in a single one that programmatically understands if the current node where the pod is being scheduled is a master or a worker.</p>

<p>Is there any way to know this information about the node programmatically (even reading a configuration file [for example something that only the master has or viceversa] in the node or something like that)?</p>

<p>Thanks in advance.</p>

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

<p>If you only want a single <code>DaemonSet</code> definition, you can add a <code>sidecar</code> container to your pod, the <code>sidecar</code> container can <a href="https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/#accessing-the-api-from-a-pod" rel="nofollow noreferrer">access the k8s api</a>, then your main container can get something useful from the <code>sidecar</code>.</p>

<p>By the way, I think your current solution is properly :)</p>
