尝试限制内存时未找到预期的密钥错误



我试图通过Kubernetes运行一个测试容器,但我遇到了错误。下面是我的deploy.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.22.0 (955b78124)
creationTimestamp: null
labels:
io.kompose.service: nginx
name: nginx
spec:
containers:
requests:
storage: 2Gi
cpu: 0.5
memory: "128M"
limits:
cpu: 0.5
memory: "128M" # This is the line throws error
- type: PersistentVolumeClaim
max:
storage: 2Gi
min:
storage: 1Gi
.
.
.

当我运行kubectl apply -k .时,我得到这个错误:

error: accumulating resources: accumulation err='accumulating resources from 'deploy.yaml': yaml: line 19: did not find expected key': got file 'deploy.yaml', but '/home/kus/deploy.yaml' must be a directory to be a root

我试着阅读Kubernetes,但我不明白为什么我会出错。

编辑1

我更改了我的deploy.yaml文件,正如@whites11所说,现在它就像:

.
.
.
spec:
limits:
memory: "128Mi"
cpu: 0.5
.
.
.

现在我得到这个错误:

resourcequota/storagequota unchanged
service/nginx configured
error: error validating ".": error validating data: ValidationError(Deployment.spec): unknown field "limits" in io.k8s.api.apps.v1.DeploymentSpec; if you choose to ignore these errors, turn validation off with --validate=false

您共享的文件不是有效的YAML。

limits:
cpu: 0.5
memory: "128M" # This is the line throws error
- type: PersistentVolumeClaim
max:
storage: 2Gi
min:
storage: 1Gi

limits字段具有混合类型(hash和collection(,显然是错误的。

似乎您采用了指定pod资源限制的语法,并将其与用于限制存储消耗的语法混合使用。

在您的部署规范中,您可能希望设置如下限制:

apiVersion: apps/v1
kind: Deployment
...
spec:
...
template:
...
spec:
containers:
- ...
resources:
limits:
cpu: 0.5
memory: "128M"

并如文档中所述处理命名空间级别的存储限制。

您应该将yaml文件更改为:

apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx:alpine
resources:
limits:
memory: "128Mi"
cpu: "500m"

相关内容

  • 没有找到相关文章

最新更新