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

使用Kubernetes示例CronJob遇配额超限错误求助

CronJob创建Pod触发配额超限错误的解决办法

我参考Kubernetes的CronJob示例,仅添加了test命名空间(无服务器权限),但在Lens中创建Pod时遇到以下错误:

Error creating: pods "hello-27928364--1-ftzjb" is forbidden: exceeded quota: test-rq, requested: limits.cpu=16,limits.memory=64Gi,requests.cpu=16,requests.memory=64Gi, used: limits.cpu=1,limits.memory=2G,requests.cpu=1,requests.memory=2G, limited: limits.cpu=12,limits.memory=24Gi,requests.cpu=12,requests.memory=24Gi

我的CronJob YAML配置如下:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: hello
  namespace: test
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: hello
              image: busybox:1.28
              imagePullPolicy: IfNotPresent
              command:
                - /bin/sh
                - c
                - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure

问题原因

你没有为容器指定CPU和内存的请求(requests)与限制(limits),Kubernetes会为未设置资源约束的Pod分配默认的超大资源请求值(此处为16核CPU、64Gi内存),直接超出了test命名空间的配额上限(12核CPU、24Gi内存)。

解决方法

在容器配置中添加resources字段,设置合理的资源请求和限制,示例修改后的YAML如下:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: hello
  namespace: test
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: hello
              image: busybox:1.28
              imagePullPolicy: IfNotPresent
              command:
                - /bin/sh
                - c
                - date; echo Hello from the Kubernetes cluster
              resources:
                requests:
                  cpu: "100m"  # 等价于0.1核CPU
                  memory: "64Mi"
                limits:
                  cpu: "200m"
                  memory: "128Mi"
          restartPolicy: OnFailure

说明

  • requests:Kubernetes为Pod调度时预留的最小资源量,确保Pod能被分配到有足够资源的节点
  • limits:Pod允许使用的最大资源上限,防止单个Pod占用过多集群资源
  • 你可以根据实际需求调整数值,只要不超过test命名空间的剩余配额(当前剩余11核CPU、22Gi内存)即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 19:31:22