Create daemonsets
Create a daemon set to automatically deploy and maintain pod replicas across selected nodes in your cluster, using node selectors to control placement.
When creating daemon sets, the nodeSelector field is used to indicate the
nodes on which the daemon set should deploy replicas.
|
|
To update a daemon set, force new pod replicas to be created by deleting the old replicas or nodes. |
-
The default project-wide node selector in your namespace is set to an empty string by using the
openshift.io/node-selectorannotation:$ oc patch namespace myproject -p \ '{"metadata": {"annotations": {"openshift.io/node-selector": ""}}}'You can alternatively apply the following YAML to disable the default project-wide node selector for a namespace:
apiVersion: v1 kind: Namespace metadata: name: <namespace> annotations: openshift.io/node-selector: '' #... -
If you are creating a new project, the default node selector is overwritten:
$ oc adm new-project <name> --node-selector=""
-
Define the daemon set yaml file:
apiVersion: apps/v1 kind: DaemonSet metadata: name: hello-daemonset spec: selector: matchLabels: name: hello-daemonset template: metadata: labels: name: hello-daemonset spec: nodeSelector: role: worker containers: - image: openshift/hello-openshift imagePullPolicy: Always name: registry ports: - containerPort: 80 protocol: TCP resources: {} terminationMessagePath: /dev/termination-log serviceAccount: default terminationGracePeriodSeconds: 10 #...where:
spec.selector.matchLabels.name-
Specifies the label selector that determines which pods belong to the daemon set.
spec.template.metadata.labels.name-
Specifies the pod template’s label selector. Must match the label selector above.
spec.template.spec.nodeSelector-
Specifies the node selector that determines on which nodes pod replicas should be deployed. A matching label must be present on the node.
-
Create the daemon set object by running the following command:
$ oc create -f daemonset.yaml
-
Verify that the pods were created and that each node has a pod replica by running the following command:
$ oc get podsExample outputhello-daemonset-cx6md 1/1 Running 0 2m hello-daemonset-e3md9 1/1 Running 0 2m -
Verify that the pods are placed onto the correct nodes by running the following command:
$ oc describe pod/hello-daemonset-cx6md|grep NodeExample outputNode: openshift-node01.hostname.com/10.14.20.134