Overview

Daemonsets are used to run a copy of a pod on specific or all nodes in an OpenShift Enterprise environment upon node creation.

Use daemonsets to create shared storage, run a logging pod on every node in your cluster, or deploy a monitoring agent on every node.

For more information on daemonsets, see the Kubernetes documentation.

Creating Daemonsets

Before creating daemonsets, ensure you have been given the required role by your OpenShift Enterprise administrator.

When creating Daemonsets, the nodeSelector field is used to indicate the nodes on which the Daemonset should deploy onto.

  1. Define the daemonset yaml file:

    apiVersion: extensions/v1beta1
    kind: DaemonSet
    metadata:
      name: hello-daemonset
    spec:
      selector:
          matchLabels:
            name: hello-daemonset (1)
      template:
        metadata:
          labels:
            name: hello-daemonset (2)
        spec:
          containers:
          - image: openshift/hello-openshift
            imagePullPolicy: Always
            name: registry
            ports:
            - containerPort: 80
              protocol: TCP
            resources: {}
            terminationMessagePath: /dev/termination-log
          serviceAccount: default
          terminationGracePeriodSeconds: 10
    1 The pod template.
    2 The node selector indicating the appropriate labels. Must match the pod template above.
  2. Create the daemonset object:

    oc create -f daemonset.yaml
  3. To verify that the pods were created, and that each node has a copy of the pod:

    1. Find the daemonset pods:

      $ oc get pods
      hello-daemonset-cx6md   1/1       Running   0          2m
      hello-daemonset-e3md9   1/1       Running   0          2m
    2. View the pods to verify the pod has been placed onto the node:

      $ oc describe pod/hello-daemonset-cx6md|grep Node
      Node:        openshift-node01.hostname.com/10.14.20.134
      $ oc describe pod/hello-daemonset-e3md9|grep Node
      Node:        openshift-node02.hostname.com/10.14.20.137

Currently, you cannot update a daemonset. You can delete a daemonset, but creating and using a new daemonset with a different template will recognize the existing pod as having matching labels dispite a mismatch in the pod template.

To update a daemonset, force a new pod to be created by deleting the pod or node.