OpenShift 4 - 通过DaemonSet在指定Node上运行守护程序

tech2024-10-31  10

《OpenShift 4.x HOL教程汇总》

文章目录

通过DaemonSet在Worker Node上运行守护程序通过DaemonSet在指定Node上运行守护程序

通过DaemonSet在Worker Node上运行守护程序

查看当前OpenShift集群中的Worker Node。 $ oc get node -l node-role.kubernetes.io/worker NAME STATUS ROLES AGE VERSION ip-10-0-155-228.ap-southeast-1.compute.internal Ready worker 8d v1.18.3+012b3ec ip-10-0-190-239.ap-southeast-1.compute.internal Ready worker 8d v1.18.3+012b3ec 创建项目 $ oc new-project my-daemon

说明:为在项目中运行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>

通过DaemonSet在指定Node上运行守护程序

查看一个Node节点的标签信息。以下查到该Node中有“kubernetes.io/hostname=ip-10-0-155-228”的标签。 $ oc describe node ip-10-0-155-228.ap-southeast-1.compute.internal Name: ip-10-0-155-228.ap-southeast-1.compute.internal Roles: worker Labels: beta.kubernetes.io/arch=amd64 beta.kubernetes.io/instance-type=m5.4xlarge beta.kubernetes.io/os=linux failure-domain.beta.kubernetes.io/region=ap-southeast-1 failure-domain.beta.kubernetes.io/zone=ap-southeast-1a kubernetes.io/arch=amd64 kubernetes.io/hostname=ip-10-0-155-228 kubernetes.io/os=linux node-role.kubernetes.io/worker= node.kubernetes.io/instance-type=m5.4xlarge node.openshift.io/os_id=rhcos topology.kubernetes.io/region=ap-southeast-1 topology.kubernetes.io/zone=ap-southeast-1a 。。。 在OpenShift控制台的项目里创建以下DaemonSet,其中使用了上一步查到的标签作为“nodeSelector”。 apiVersion: apps/v1 kind: DaemonSet metadata: name: hello-daemon1 namespace: my-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,确认这次hello-daemon1只运行在标签为“kubernetes.io/hostname=ip-10-0-155-228”的节点中了。 $ oc get ds -n my-daemon NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE hello-daemon1 1 1 1 1 1 kubernetes.io/hostname=ip-10-0-155-228 79m
最新回复(0)