《OpenShift 4.x HOL教程汇总》
说明:为在项目中运行DaemonSet,不建议为项目使用"openshift.io/node-selector"注释。这是因为可能由于使用了该注释,使得属于该项目的DaemonSet无法运行在其希望运行的Node上。如果一个项目有上述注释,可以使用以下命令情况该注释的内容。
$ oc patch namespace my-daemon -p '{"metadata": {"annotations": {"openshift.io/node-selector": ""}}}' 在OpenShift的控制台中进入my-daemon项目,然后运行以下YAML创建名为hello-daemon的DaemonSet。 apiVersion: apps/v1 kind: DaemonSet metadata: name: hello-daemon spec: selector: matchLabels: app: hello-openshift template: metadata: labels: app: hello-openshift spec: nodeSelector: kubernetes.io/hostname: ip-10-0-155-228 containers: - name: hello-openshift image: openshift/hello-openshift ports: - containerPort: 8080 查看DaemonSet的详细信息,可看到OpenShift缺省是将hello-daemon在2个Worker Node上各运行了1个Pod。 $ oc get ds NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE hello-daemon 2 2 2 2 2 <none> 21s $ oc describe ds/hello-daemon Name: hello-daemon Selector: app=hello-openshift Node-Selector: <none> Labels: <none> Annotations: deprecated.daemonset.template.generation: 1 Desired Number of Nodes Scheduled: 2 Current Number of Nodes Scheduled: 2 Number of Nodes Scheduled with Up-to-date Pods: 2 Number of Nodes Scheduled with Available Pods: 2 Number of Nodes Misscheduled: 0 Pods Status: 2 Running / 0 Waiting / 0 Succeeded / 0 Failed Pod Template: Labels: app=hello-openshift Containers: hello-openshift: Image: openshift/hello-openshift Port: 8080/TCP Host Port: 0/TCP Environment: <none> Mounts: <none> Volumes: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulCreate 107s daemonset-controller Created pod: hello-daemon-szhrz Normal SuccessfulCreate 107s daemonset-controller Created pod: hello-daemon-ktbgn 查看pod信息,确认2个pod运行在worker node上了。 $ oc get pod -n my-daemon -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES hello-daemon-ktbgn 1/1 Running 0 15m 10.131.0.107 ip-10-0-155-228.ap-southeast-1.compute.internal <none> <none> hello-daemon-szhrz 1/1 Running 0 15m 10.128.2.244 ip-10-0-190-239.ap-southeast-1.compute.internal <none> <none>