首页 > 解决方案 > 一个或多个容器没有资源限制 - VS Code Kubernetes 工具中的警告

问题描述

创建 pod-definition.yml 文件后。

apiVersion: v1
kind: Pod
metadata:
    name: myapp-pod
    labels: 
      app: myapp
      type: server
spec:
    containers:
        - name: nginx-container
          image: nginx

linter 给出了这个警告。

One or more containers do not have resource limits - this could starve other processes

标签: kubernetesvisual-studio-code

解决方案


为每个容器声明内存cpu的资源请求和限制是一种很好的做法。这有助于将容器调度到具有可用于您的 Pod 的资源的节点,并且还可以使您的 Pod 不使用其他 Pod 需要的资源 - 因此“这可能会使其他进程饿死”消息。

例如,为您的示例添加资源请求和限制

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels: 
    app: myapp
    type: server
spec:
  containers:
  - name: nginx-container
    image: nginx
    resources:
      limits:
        memory: 512Mi
        cpu: "1"
      requests:
        memory: 256Mi
        cpu: "0.2"

推荐阅读