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

GKE Autopilot部署Go容器失败,报资源不足求助

问题描述
  • 用Go编写的容器可在Docker Desktop及内置Kubernetes集群正常部署运行
  • 推送至Artefact Repository后,部署到GKE Autopilot集群失败,但CloudRun可正常运行
  • 报错信息:

    Cannot schedule pods: Insufficient cpu.
    PodUnschedulable
    Reason: Cannot schedule pods: Insufficient cpu.
    涉及Pod:gmail-sender-7944d6d4d4-tsdt9、gmail-sender-7944d6d4d4-pc9xp、gmail-sender-7944d6d4d4-kdlds
    另出现:PodUnschedulable Cannot schedule pods: Insufficient memory.

  • 部署文件如下:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: gmail-sender
  labels:
    app: gmail-sender
spec:
  replicas: 1
  selector:
    matchLabels:
      app: gmail-sender
  template:
    metadata:
      labels:
        app: gmail-sender
    spec:
      containers:
        - name: gmail-sender
          image: europe-west2-docker.pkg.dev/ea-website-359514/gmail-sender/gmail-sender:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8099
---
apiVersion: v1
kind: Service
metadata:
  name: gmail-sender-cluster-ip
  labels:
    app: gmail-sender
spec:
  ports:
    - port: 8099
      protocol: TCP
解决方案

GKE Autopilot对Pod的资源请求有默认约束,当未显式指定资源请求和限制时,Autopilot会套用默认值,可能导致集群无足够资源调度Pod;而CloudRun采用无服务器托管模式,资源分配逻辑不同,因此可正常运行。

解决步骤:

  1. 显式配置Pod资源请求与限制
    在Deployment的容器字段中添加resources配置,根据应用实际需求设置合理的CPU和内存值,示例:

    containers:
      - name: gmail-sender
        image: europe-west2-docker.pkg.dev/ea-website-359514/gmail-sender/gmail-sender:latest
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 8099
        resources:
          requests:
            cpu: "100m"  # 0.1核CPU
            memory: "128Mi"
          limits:
            cpu: "500m"
            memory: "256Mi"
    

    注意:Autopilot有最小资源请求限制,如CPU最低100m、内存最低128Mi,具体数值可能因集群区域略有差异。

  2. 检查集群资源配额
    即便Autopilot是托管集群,项目在特定区域仍有资源配额限制。可通过GCP控制台或执行gcloud container clusters describe <cluster-name> --region <region>命令,查看集群可用资源情况,确认是否存在配额不足问题。

  3. 确认节点适配逻辑
    Autopilot会自动管理节点池,若应用需特定类型节点(如高CPU/内存),可在Deployment中添加节点选择器或污点容忍配置,但优先确保资源请求设置正确,Autopilot通常会自动适配调度需求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 04:01:13