一个或多个容器没有资源限制-在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

门楣发出这个警告。

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

为每个容器声明内存和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"
正如您所知,该警告来自VS代码扩展ms-kubernetes-tools.vscode-kubernetes-tools中的linter。如果你想让门楣禁用警告
One or more containers do not have resource limits - this could starve other processes

然后编辑VS代码setting.json如下所示:

{
"vs-kubernetes": {
"disable-linters": ["resource-limits"],
...
},
...
}

我使用我的YAML对象文件,以前我将每个对象都放在一个单独的文件中,最近我注意到对于;部署";对象文件我有以下linting警告:

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

在解决这个问题之前,我决定对我的对象定义进行一点重构,并在一个文件中定义多个相关的对象。因此,现在我有了与以前相同的部署,以及一个卷声明和一个服务,所有内容都在同一个文件中。

但后来我注意到,linting警告不会显示在部署中,但如果我从文件中删除服务和卷声明,而不显示部署,它就会显示出来。

因此,我认为linting代码没有考虑到每个文件定义多个对象的可能性。

谢谢!

最新更新