简体   繁体   English

限制每个节点的 Pod 数量

[英]Limit the number of pods per node

I'm trying to limit the number of pods per each node from my cluster.我正在尝试限制集群中每个节点的 pod 数量。 I managed to add a global limit per node from kubeadm init with config file:我设法使用配置文件从 kubeadm init 添加每个节点的全局限制:

apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
networking:
  podSubnet: <subnet>
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
maxPods: 10

This is not quite well because the limit is applied even on master node (where multiple kube-system pods are running and the number of pods here may increase over 10).这不太好,因为该限制甚至适用于主节点(其中多个 kube-system pod 正在运行,此处的 pod 数量可能会增加超过 10 个)。 I would like to keep the default value at init and change the value at join on each node.我想在 init 时保留默认值并在每个节点上更改 join 时的值。 I have found something:我发现了一些东西:

apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
maxPods: 10
---
apiVersion: kubeadm.k8s.io/v1beta1
kind: JoinConfiguration
discovery:
  bootstrapToken:
    apiServerEndpoint: "<api_endpoint>"
    token: "<token>"
    unsafeSkipCAVerification: true

but, even if no error/warning appears, it seems that the value of maxPods is ignored.但是,即使没有出现错误/警告,似乎也忽略了 maxPods 的值。 I can create more than 10 pods for that specific node.我可以为该特定节点创建 10 个以上的 pod。 Also kubectl get node <node> -o yaml returns status.capacity.pods with its default value (110).此外kubectl get node <node> -o yaml returns status.capacity.pods及其默认值 (110)。 How can I proceed in order to have this pods limit applied per each node?我该如何继续以使每个节点应用此 pod 限制?

I would like to mention that I have basic/limited knowledge related to Kubernetes.我想提一下,我有与 Kubernetes 相关的基本/有限的知识。

Thank you!谢谢!

There is a config.yaml file at /var/lib/kubelet . /var/lib/kubelet有一个 config.yaml 文件。 This config file is generated from kubelet config map in kube-system namespace when you run kubeadm join.Partial content of the file is as below.该配置文件是在运行 kubeadm join 时从 kube-system 命名空间中的 kubelet 配置映射生成的。文件的部分内容如下。

apiVersion: kubelet.config.k8s.io/v1beta1
authentication:
  anonymous:
    enabled: false
  webhook:
    cacheTTL: 0s
    enabled: true
  x509:
    clientCAFile: /etc/kubernetes/pki/ca.crt
authorization:
  mode: Webhook
  webhook:
    cacheAuthorizedTTL: 0s
    cacheUnauthorizedTTL: 0s
clusterDNS:
- 10.96.0.10
maxPods: 10

You can change that file and add maxPods parameter and then restart kubelet on the node.您可以更改该文件并添加 maxPods 参数,然后在节点上重新启动 kubelet。

sudo systemctl restart kubelet 

Currently in kubeadm join there is no way to pass a kubelet config file.目前在 kubeadm join 中无法传递 kubelet 配置文件。

您还可以使用 kubelet --max-pods选项设置每个节点的最大 Pod 数。

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

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