繁体   English   中英

为什么 Kubernetes 不为 pod 设置 1 个 CPU 限制?

[英]Why doesn't Kubernetes set a 1 CPU limit for a pod?

我的 Kubernetes 版本是 1.22

我正在学习 Kubernetes CKAD 课程。

在资源和限制部分它说:

Let's now look at a container running on a node in the Docker world.

A Docker container has no limit to the resources it can consume on a node.

Say a container starts with one CPU on a node.

It can go up and consume as much resource as it requires suffocating the native processes on the node or other containers of resources.

However, you can set a limit for the resource usage on these parts by default.

Kubernetes sets a limit of one CPU to containers, so if you do not specify explicitly, a container will be limited to consume only one CPU from the node.

The same goes with memory.

By default, Kubernetes sets a limit of 512 Mi on containers.

If you don't like the default limits, you can change them by adding a limit section under the resources section in your file.

Specify new limits for the memory and CPU like this when the pod is created.

我创建了 podr nginx,在其中我只指定了 reguest:

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: nginx-test
  name: nginx-test
spec:
  containers:
  - image: nginx
    name: nginx-test
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
  dnsPolicy: ClusterFirst
  restartPolicy: Always

创建 pod 后,我看到 CPU 和 RAM 是无限的:

  Namespace                   Name                                                              CPU Requests  CPU Limits  Memory Requests  Memory Limits  Age
  ---------                   ----                                                              ------------  ----------  ---------------  -------------  ---
  only-test                   nginx-test                                                        250m (0%)     0 (0%)      64Mi (0%)        0 (0%)         8m33s

也许这对 Docker 来说是真的? 我正在使用容器。

我想到了。 要使用默认资源,您需要在特定命名空间中创建 LimitRange。

例子:

apiVersion: v1
kind: LimitRange
metadata:
  name: mem-limit-range
spec:
  limits:
  - default:
      memory: 512Mi
    defaultRequest:
      memory: 256Mi
    type: Container
apiVersion: v1
kind: LimitRange
metadata:
  name: cpu-limit-range
spec:
  limits:
  - default:
      cpu: 1
    defaultRequest:
      cpu: 0.5
    type: Container

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM