Score:2

How do I configure Kubernetes to use kubenet with kubeadm?

in flag

I deployed a Kubernetes cluster using kubeadm.

$ kubectl get nodes
NAME                                          STATUS     ROLES                  AGE   VERSION
ip-172-31-33-9.us-east-2.compute.internal     NotReady   <none>                 48m   v1.22.2
ip-172-31-46-53.us-east-2.compute.internal    NotReady   control-plane,master   49m   v1.22.2
ip-172-31-47-245.us-east-2.compute.internal   NotReady   <none>                 6s    v1.22.2

The nodes are NotReady because I haven't installed a networking plugin. I want to use keep it simple and use kubenet. The instructions say:

Kubelet must be run with the --network-plugin=kubenet argument to enable the plugin

but I can't figure out how to do that. I have tried adding it to various configuration files, such as /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf and /etc/sysconfig/kubelet, and restaring kubelet, but none of it works.

How do I use kubenet with kubeadm?

in flag
Hi timkay welcome to S.F. You have said you "tried it" but "none works" but yet you shared none of your attempts with us in order to gauge what you're already tried and why it might not be working. Please read the [how to ask](https://serverfault.com/help/how-to-ask) page. In the spirit of trying to be a little helpful, did you remember to run `systemctl daemon-reload` in between edits? systemd does not use the latest values on disk -- it must be forced to re-read them. Good luck!
in flag
As I said, the docs say to add `--network-plugin=kubenet` to the kubelet command line, but I never have a kubelet command line, as kubelet gets started by kubeadm. Thus, I don't have any attempts to share with you.
Score:1
in flag

You can use the /etc/default/kubelet file to override kubelet arguments. As can be found in the 10-kubeadm.conf file:

...
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
EnvironmentFile=-/etc/default/kubelet
...

I'll show you how it works.


First, I set up the Kubernetes control plane:

# kubeadm init
[init] Using Kubernetes version: v1.22.2
...

# mkdir -p $HOME/.kube
# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
# sudo chown $(id -u):$(id -g) $HOME/.kube/config

After successful initialization, we can check the value of the --network-plugin argument that kubelet is currently using and the status of the coredns Pods:

# ps aux | grep "kubelet" | grep "network-plugin"
root     27488  5.1  3.6 1816612 145808 ?      Ssl  10:42   0:01 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --network-plugin=cni --pod-infra-container-image=k8s.gcr.io/pause:3.5

# kubectl get pod -n kube-system | grep "coredns"
coredns-78fcd69978-bbc52          0/1     Pending   0          2m26s
coredns-78fcd69978-fdcv9          0/1     Pending   0          2m26s

From the above output, we can see that --network-plugin=cni and coredns Pods are in the Pending state.

Let's create the /etc/default/kubelet file and write the kubelet arguments there:
NOTE: You may need to customize the --pod-cidr and --pod-infra-container-image to suit your needs.

# touch /etc/default/kubelet

# echo 'KUBELET_KUBEADM_ARGS="--network-plugin=kubenet --pod-cidr=10.20.0.0/24 --pod-infra-container-image=k8s.gcr.io/pause:3.5"' > /etc/default/kubelet

# cat /etc/default/kubelet
KUBELET_KUBEADM_ARGS="--network-plugin=kubenet --pod-cidr=10.20.0.0/24 --pod-infra-container-image=k8s.gcr.io/pause:3.5"

Then we need to reload systemd manager configuration and restart kubelet:

# systemctl daemon-reload
# systemctl restart kubelet

Finally, we can check if it works as expected:

# ps aux | grep "kubelet" | grep "network-plugin"
root     27841  6.9  3.5 1890600 143760 ?      Ssl  10:47   0:01 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --network-plugin=kubenet --pod-cidr=10.20.0.0/24 --pod-infra-container-image=k8s.gcr.io/pause:3.5
   
# kubectl get pod -n kube-system | grep "coredns"
coredns-78fcd69978-bbc52          1/1     Running   0          6m51s
coredns-78fcd69978-fdcv9          1/1     Running   0          6m51s   

# kubectl get nodes
NAME      STATUS   ROLES                  AGE   VERSION
kmaster   Ready    control-plane,master   15m   v1.22.2

You can follow these steps for all of your nodes.

Additionally, please remember that (more information can be found in the kubenet documentation):

Kubenet is a very basic, simple network plugin, on Linux only. It does not, of itself, implement more advanced features like cross-node networking or network policy. It is typically used together with a cloud provider that sets up routing rules for communication between nodes, or in single-node environments.

Wytrzymały Wiktor avatar
it flag
Hello @timkay and welcome to ServerFault! Please remember to [react to answers for your questions](https://stackoverflow.com/help/someone-answers). That way we know if the answers were helpful and other community members could also benefit from them. Try to [accept answer](https://stackoverflow.com/help/accepted-answer) that is the final solution for your issue, upvote answers that are helpful and comment on those which could be improved or require additional attention. Enjoy your stay!
in flag
Thank you, @matt_j. I followed your instructions, which I summarized this way: 1. Install as before, using kubeadm. 2. Create a file /etc/default/kubelet, with extra kubelet parameters. 3. Restart kubelet with systemctl daemon-reload && systemctl restart kubelet. I did that, and the command line parameters for kubelet didn't change. The env variable KUBELET_KUBEADM_ARGS would tell me that it's used by kubeadm to start kubelet, but we don't run kubeadm at all after making changes as per your instructions.
matt_j avatar
in flag
How did you check that the kubelet parameters did not change ? Could you please use this command: `ps aux | grep "kubelet" | grep "network-plugin"` ?
Wytrzymały Wiktor avatar
it flag
Hello @timkay. Any updates?
in flag
I gave up on Kubernetes and wrote my own replacement.
Minding avatar
pl flag
No need to run `systemctl daemon-reload`, since no `systemd` configuration changed that would need to be reloaded. I also don't like using `/etc/default` for custom configurations. Otherwise very helpful, thanks!
Minding avatar
pl flag
Actually `kubeadm` ["does not support kubenet"](https://unofficial-kubernetes.readthedocs.io/en/latest/getting-started-guides/kubeadm/) according to this wiki.
Score:0
jp flag

kubeadm gives the possibility to use a --config yaml file that is documented here. In this file you can use the cli parameters from kubelet as extra args like --network-plugin=kubelet as network-plugin: kubelet:

apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
bootstrapTokens:
...
nodeRegistration:
...
  kubeletExtraArgs:
    ...
    network-plugin: kubenet
    pod-cidr: 10.20.0.0/24

in flag
Kubernetes is so messed up. I gave up on it a long time ago and wrote my own replacement, which is only a few hundred lines of code. I am quite disappointed that the industry seems to be a pyramid scheme. People write complex software that only highly trained people can use. Where is the craftmanship? As Elon says, "no part is the best part." Stop fixing complexity problems by making everything more complex.
Oskar avatar
jp flag
@timkay True words, I can fully understand your statement :)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.