Limit the number of pods per node
Asked Answered
S

2

5

I'm trying to limit the number of pods per each node from my cluster. I managed to add a global limit per node from kubeadm init with config file:

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). I would like to keep the default value at init and change the value at join on each node. 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. I can create more than 10 pods for that specific node. Also kubectl get node <node> -o yaml returns status.capacity.pods with its default value (110). How can I proceed in order to have this pods limit applied per each node?

I would like to mention that I have basic/limited knowledge related to Kubernetes.

Thank you!

Sulfapyrazine answered 24/2, 2020 at 14:34 Comment(0)
S
7

There is a config.yaml file at /var/lib/kubelet. 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.

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.

sudo systemctl restart kubelet 

Currently in kubeadm join there is no way to pass a kubelet config file.

Shippy answered 24/2, 2020 at 15:33 Comment(0)
R
1

You can also set the maximum number of pods per node with the kubelet --max-pods option.

Raymund answered 24/2, 2020 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.