11.9. 平衡忽略托管的集群中的标签
扩展节点池后,您可以使用 balancingIgnoredLabels 在节点池中平均分配机器。
先决条件
-
您已创建了
HostedCluster和NodePool资源。
流程
使用相同的标签值,将
node.group.balancing.ignored标签添加到每个相关节点池。运行以下命令:oc patch -n <hosted_cluster_namespace> \ nodepool <node_pool_name> \ --type=merge \ --patch='{"spec": {"nodeLabels": {"node.group.balancing.ignored": "<label_name>"}}}'$ oc patch -n <hosted_cluster_namespace> \ nodepool <node_pool_name> \ --type=merge \ --patch='{"spec": {"nodeLabels": {"node.group.balancing.ignored": "<label_name>"}}}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow 运行以下命令,为托管集群启用集群自动扩展:
oc patch -n <hosted_cluster_namespace> \ hostedcluster <hosted_cluster_name> \ --type=merge \ --patch='{"spec": {"autoscaling": {"balancingIgnoredLabels": ["node.group.balancing.ignored"]}}}'$ oc patch -n <hosted_cluster_namespace> \ hostedcluster <hosted_cluster_name> \ --type=merge \ --patch='{"spec": {"autoscaling": {"balancingIgnoredLabels": ["node.group.balancing.ignored"]}}}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow 从
NodePool资源中删除spec.replicas字段,以允许集群自动扩展管理节点数。运行以下命令:oc patch -n <hosted_cluster_namespace> \ nodepool <node_pool_name> \ --type=json \ --patch='[{"op": "remove", "path": "/spec/replicas"}]'$ oc patch -n <hosted_cluster_namespace> \ nodepool <node_pool_name> \ --type=json \ --patch='[{"op": "remove", "path": "/spec/replicas"}]'Copy to Clipboard Copied! Toggle word wrap Toggle overflow 启用集群自动扩展,为节点池配置最小和最大节点数。运行以下命令:
oc patch -n <hosted_cluster_namespace> \ nodepool <nodepool_name> \ --type=merge --patch='{"spec": {"autoScaling": {"max": 3, "min": 1}}}'$ oc patch -n <hosted_cluster_namespace> \ nodepool <nodepool_name> \ --type=merge --patch='{"spec": {"autoScaling": {"max": 3, "min": 1}}}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow 运行以下命令来生成
kubeconfig文件:hcp create kubeconfig \ --name <hosted_cluster_name> \ --namespace <hosted_cluster_namespace> > nested.config
$ hcp create kubeconfig \ --name <hosted_cluster_name> \ --namespace <hosted_cluster_namespace> > nested.configCopy to Clipboard Copied! Toggle word wrap Toggle overflow 在扩展节点池后,运行以下命令来检查所有计算节点是否处于
Ready状态:oc --kubeconfig nested.config get nodes -l 'hypershift.openshift.io/nodePool=<node_pool_name>'
$ oc --kubeconfig nested.config get nodes -l 'hypershift.openshift.io/nodePool=<node_pool_name>'Copy to Clipboard Copied! Toggle word wrap Toggle overflow 运行以下命令确认新节点包含
node.group.balancing.ignored标签:oc --kubeconfig nested.config get nodes \ -l 'hypershift.openshift.io/nodePool=<node_pool_name>' \ -o jsonpath='{.items[*].metadata.labels}' | grep "node.group.balancing.ignored"$ oc --kubeconfig nested.config get nodes \ -l 'hypershift.openshift.io/nodePool=<node_pool_name>' \ -o jsonpath='{.items[*].metadata.labels}' | grep "node.group.balancing.ignored"Copy to Clipboard Copied! Toggle word wrap Toggle overflow 运行以下命令,为托管集群启用集群自动扩展:
oc patch -n <hosted_cluster_namespace> \ hostedcluster <hosted_cluster_name> \ --type=merge \ --patch='{"spec": {"autoscaling": {"balancingIgnoredLabels": ["node.group.balancing.ignored"]}}}'$ oc patch -n <hosted_cluster_namespace> \ hostedcluster <hosted_cluster_name> \ --type=merge \ --patch='{"spec": {"autoscaling": {"balancingIgnoredLabels": ["node.group.balancing.ignored"]}}}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow
验证
验证每个节点池调配的节点数量平均分布。例如,如果您创建了具有相同标签值的三个节点池,节点数可能是 3、2 和 3。运行以下命令:
oc --kubeconfig nested.config get nodes -l 'hypershift.openshift.io/nodePool=<node_pool_name>'
$ oc --kubeconfig nested.config get nodes -l 'hypershift.openshift.io/nodePool=<node_pool_name>'Copy to Clipboard Copied! Toggle word wrap Toggle overflow