In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you an explanation of the kubernetes cpu restriction parameters. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.
Docker CPU limit parameter
Option
Description
-- cpus=
Specify how much of the available CPU resources a container can use. For instance, if the host machine has two CPUs and you set-- cpus= "1.5", the container is guaranteed at most one and a half of the CPUs. This is the equivalent of setting-cpu-period= "100000" and-cpu-quota= "150000". Available in Docker 1.13 and higher.
-- cpu-period=
Specify the CPU CFS scheduler period, which is used alongside--cpu-quota. Defaults to 100 micro-seconds. Most users do not change this from the default. If you use Docker 1.13 or higher, use-- cpusinstead.
-- cpu-quota=
Impose a CPU CFS quota on the container. The number of microseconds per-- cpu-period that the container is limited to before throttled. As such acting as the effective ceiling. If you use Docker 1.13 or higher, use-- cpus instead.
-- cpuset-cpus
Limit the specific CPUs or cores a container can use. A comma-separated list or hyphen-separated range of CPUs a container can use, if you have more than one CPU. The first CPU is numbered 0. A valid value might be 0-3 (to use the first, second, third, and fourth CPU) or 1 Magi 3 (to use the second and fourth CPU).
-- cpu-shares
Set this flag to a value greater or less than the default of 1024 to increase or reduce the container's weight, and give it access to a greater or lesser proportion of the host machine's CPU cycles. This is only enforced when CPU cycles are constrained. When plenty of CPU cycles are available, all containers use as much CPU as they need. In that way, this is a soft limit. -- cpu-shares does not prevent containers from being scheduled in swarm mode. It prioritizes container CPU resources for the available CPU cycles. It does not guarantee or reserve any specific CPU access.
①-- cpus indicates the number of CPU that the container can use. Change the parameter to specify a percentage, not a specific number. For example, if the host has four logical CPU and limits the container-cpus=2, the maximum CPU time that can be used by the container is 200%, but the time allocated by the four CPU may be 50% for each CPU, and not necessarily 2 of the CPU use 100%, while the other 2 CPU use 0%.
-- cpus is a parameter that comes out after docker 1.13 and is intended to replace the-- cpu-period and-- cpu-quota parameters, thus making the configuration easier.
②-- cpu-period means to set the CPU time period. The default value is 100000, and the unit is us, or 0.1s.
③-- cpu-quota indicates the maximum CPU time that the container can use, with the-- cpu-period value. If-cpu-quota=200000, that is 0.2s. That is to say, the container can use 0.2s CPU time within 0.1s cycle. Obviously, one CPU can not meet the requirements, and at least 2 CPU are needed.
④-- cpuset-cpus sets which CPU the container can use. For example, the container will use the 0-2 CPU if-- cpuset-cpus= "0je 1J 2" or-- cpuset-cpus= "0-2".
⑤-- cpu-shares. The container uses the weight of CPU. The default value is 1024. The higher the value, the greater the weight. This parameter takes effect only if multiple containers compete for the same CPU. For single-core CPU, if container An is set to-- cpu-shares=2048 and container B is set to-- cpus-shres=1024, container A will be allocated 66% of the CPU time only when the two containers need to use CPU time longer than the entire CPU cycle, and container B will be allocated 33% of the CPU time, which is about 2cpus-shres=1024 1. For multi-core CPU, this value will take effect only if multiple containers compete for the same CPU.
Kubernetes restrictions on CPU
First: resource object LimitRange restricts the resources of POD and Container
ApiVersion: v1kind: LimitRangemetadata: name: mylimitsspec: limits:-max: cpu: "2" memory: 1Gi min: cpu: 200m memory: 6Mi type: Pod-default: cpu: 300m memory: 200Mi defaultRequest: cpu: 200m memory: 100Mi max: cpu: "2" memory: 1Gi min: cpu: 100m memory: 3Mitype: Container
Spec: containers:-image: gcr.io/google_containers/serve_hostname imagePullPolicy: Always name: kubernetes-serve-hostname resources: limits: cpu: "1" memory: 512Mi requests: cpu: "1" memory: 512Mi
2. Docker stats to view container CPU utilization
Since CPUQuota is set up to be 4 times larger than CpuPeriod, the container can use 400% CPU
2. Docker stats to view container CPU utilization
Containers can use 600% CPU, now only 400%
2. Docker stats to view container CPU utilization
The usage time is equal to CpuPeriod and occupies 100%
As you can see from the figure below, 4 CPU each use 25%, which adds up to 100%. So limits.cpu:1 does not necessarily mean that the container will occupy only one CPU, but rather the percentage of CPU time that the container can use at most.
2. Docker stats to view container CPU utilization
The above is the description of the kubernetes cpu limit parameters shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.