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

使用kops创建单master K8s集群时kube-dns等Pod无法运行

解决kops单master集群中Pod无法调度到master节点的问题

问题根源

从你的节点描述信息能看到,master节点带有一个关键污点:

Taints: node-role.kubernetes.io/master:NoSchedule

这个污点会告诉Kubernetes调度器绝对不要把普通Pod调度到master节点上——而你的集群是单master无worker的架构,调度器找不到可调度的节点,自然就让kube-dns和kube-autoscaler一直处于Pending状态了。

你手动执行kubectl taint nodes --all node-role.kubernetes.io/master-移除污点的方法是有效的,不过我们可以通过kops的配置在集群创建阶段就自动完成这个设置,省去后续手动操作的步骤。


方法1:创建集群时通过命令行参数修改污点

kops允许你在kops create cluster命令中用--master-taint参数覆盖master节点的默认污点配置。如果希望调度器优先避免但在必要时允许Pod调度到master,可以把污点的effect改成PreferNoSchedule:

kops create cluster \
  --name=your-cluster-name \
  --state=s3://your-state-bucket \
  --zones=ap-southeast-1a \
  --master-size=m3.large \
  --node-count=0 \
  --master-taint node-role.kubernetes.io/master:PreferNoSchedule

如果是完全允许Pod调度到master(适配你的单master无worker场景),更可靠的方式是用配置文件来修改,因为kops默认会自动添加NoSchedule污点,命令行参数无法直接完全移除它。


方法2:通过配置文件自定义master节点污点

这种方式灵活性更高,适合需要精细配置的场景:

  1. 先导出集群的配置模板(dry-run模式):
kops create cluster \
  --name=your-cluster-name \
  --state=s3://your-state-bucket \
  --zones=ap-southeast-1a \
  --master-size=m3.large \
  --node-count=0 \
  --dry-run -o yaml > cluster.yaml
  1. 编辑cluster.yaml,找到master实例组的taints部分(通常在spec.instanceGroups下的master组):
    原配置大概是这样:
spec:
  instanceGroups:
  - name: master-ap-southeast-1a
    role: Master
    taints:
    - key: node-role.kubernetes.io/master
      value: ""
      effect: NoSchedule
    # 其他配置...
  1. 你可以选择两种修改方式:
    • 将effect改为PreferNoSchedule(调度器优先不调度到master,但无worker时会允许)
    • 直接删除整个taints条目(完全移除污点,允许所有Pod调度到master)
      修改后的示例:
    # 方式1:改为PreferNoSchedule
    taints:
    - key: node-role.kubernetes.io/master
      value: ""
      effect: PreferNoSchedule
    
    # 方式2:完全移除污点
    # taints: []
    
  2. 使用修改后的配置文件创建集群:
kops create -f cluster.yaml
kops update cluster --name=your-cluster-name --state=s3://your-state-bucket --yes

验证配置

集群创建完成后,执行kubectl describe nodes查看master节点的Taints字段,确认污点已修改或移除。此时kube-dns和kube-autoscaler应该会自动调度到master节点,不再处于Pending状态。

内容的提问来源于stack exchange,提问作者Jin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 07:03:09