10.2.3. 使用 NodeMaintenance 自定义资源将节点设置为维护模式
您可以使用 NodeMaintenance 自定义资源(CR)将节点置于维护模式。应用 NodeMaintenance CR 时,所有允许的 pod 都会被驱除并关闭该节点。被驱除的 pod 会被放入到集群中的另一节点中。
先决条件
-
安装 OpenShift Container Platform CLI
oc。 -
以具有
cluster-admin权限的用户身份登录集群。
流程
创建以下节点维护 CR,并将文件保存为
nodemaintenance-cr.yaml:apiVersion: nodemaintenance.kubevirt.io/v1beta1 kind: NodeMaintenance metadata: name: maintenance-example1 spec: nodeName: node-1.example.com2 reason: "Node maintenance"3 运行以下命令来应用节点维护计划:
$ oc apply -f nodemaintenance-cr.yaml运行以下命令,将
<node-name>替换为节点的名称来检查维护任务的进度:$ oc describe node <node-name>输出示例
Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal NodeNotSchedulable 61m kubelet Node node-1.example.com status is now: NodeNotSchedulable
10.2.3.1. 检查当前 NodeMaintenance CR 任务的状态 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
您可以检查当前 NodeMaintenance CR 任务的状态。
先决条件
-
安装 OpenShift Container Platform CLI
oc。 -
以具有
cluster-admin特权的用户身份登录。
流程
运行以下命令,检查当前节点维护任务的状态:
$ oc get NodeMaintenance -o yaml输出示例
apiVersion: v1 items: - apiVersion: nodemaintenance.kubevirt.io/v1beta1 kind: NodeMaintenance metadata: ... spec: nodeName: node-1.example.com reason: Node maintenance status: evictionPods: 31 pendingPods: - pod-example-workload-0 - httpd - httpd-manual phase: Running lastError: "Last failure message"2 totalpods: 5 ...