You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GKE多区域测试集群nodeAffinity配置技术咨询

Node Affinity Configuration for Your GKE Multi-Zone Cluster

Hey there! Based on your GKE 1.9.4 setup, here's a practical nodeAffinity configuration to make sure your frontend and backend pods land exactly on their designated node pools.

Frontend Pods (Targeting frontend Labeled Nodes)

For your frontend workloads, you’ll want to enforce scheduling only on nodes in the frontend-pool (labeled frontend). Add this section under the spec.template.spec block of your frontend Deployment YAML:

affinity:
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
      - matchExpressions:
        - key: frontend
          operator: In
          values:
          - "true" # Adjust this value to match your actual node label value

What this does:

  • requiredDuringSchedulingIgnoredDuringExecution: Guarantees the pod only gets scheduled on nodes matching the label rule. Once the pod is running, if the node’s label changes later, the pod won’t be evicted (this is ideal for stable frontend workloads).
  • matchExpressions: Matches nodes where the frontend key exists and has the value you specified—double-check this aligns with how you labeled your frontend-pool nodes.

Backend Pods (Targeting backend Labeled Nodes)

For backend workloads, use this configuration to pin them exclusively to nodes in the backend-pool (labeled backend):

affinity:
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
      - matchExpressions:
        - key: backend
          operator: In
          values:
          - "true" # Match your actual node label value here

Quick Validation Steps

Before applying these configs, confirm your node labels are correctly set:

  1. List all nodes and their labels with this command:
    kubectl get nodes --show-labels
    
  2. Verify that nodes in frontend-pool have the frontend=true (or your custom value) label, and backend-pool nodes have backend=true.

Optional: Flexible Preferred Scheduling

If you ever want to prioritize the target node pool but allow fallback scheduling elsewhere (e.g., during node pool maintenance), use preferredDuringSchedulingIgnoredDuringExecution instead:

affinity:
  nodeAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
    - weight: 100
      preference:
        matchExpressions:
        - key: frontend
          operator: In
          values:
          - "true"

The weight (1-100) sets how strong this preference is relative to other scheduling rules.

内容的提问来源于stack exchange,提问作者d.ansimov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:45:02