Demo - Deployment with kubeadm
Demo - Deployment with kubeadm
-
Currently latest version of Kubernetes is 1.31
-
Before using
kubeadm, need a container runtime. -
First thing you need to do is download public signing keys for kubernetes repos.
-
Need to select the versions (1.31 in this case).
-
Paste the
curlcommand in all three nodes.
-
-
Add the specific Kubernete’s repository - run the command in all three nodes.
-
Update packages in all three nodes.
-
Install the
kubelet,kubeadmandkubectlpackages.- The above packages are installed on all three nodes.
-
Check the version of
kubeadmwithkubeadm version. -
Enable the
kubeletservice withsystemctl enable --now kubelet. -
A container runtime needs to be installed on all three nodes.
-
Control Plane components are installed as Pods on the Master Node.
-
Install the container runtime (best is
containerd). -
Install the
containerdpackage. Run this on every node. -
cgroupsallow you to specify resource groups on your containers. -
cgroupfsis the default driver and then you also havesystemd. -
Both the
kubeletand thecontainer runtimeneed to use the samecgroupdriver. -
If you
initsystem issystemd, then need to use thesystemddriver. -
How to verify -
ps -p 1and it tells you whether this issystemdor not.-
Need to create a kubelet configuration.
-
If under the configuration a
cgroupdriver is not set, it defaults tosystemd.
-
-
Kubernetes 1.22 defaults automatically to
systemd. -
Need to set the
container runtimeto use thesystemddriver.-
Create a file for
containerd- this is set in/etc/containerd/config.toml -
Usually need to manually create the above directory.
-
Needs to be done on all nodes.
-
-
containerdallows the generation of default configurations. - Good command for generating the configuration:
containerd config default | sed 's/SystemdCgroup = false/SystemdCgroup = true/' | sudo tee /etc/containerd/config.toml -
Run the above command on all nodes.
- Then restart
containerdon all nodes.systemctl restart containerd -
Initialise the Control Plane node.
- If have multiple Master Nodes, need to pick one that you’ll run the command on first.
-
If planning to have more multiple Control Plane nodes, need to pass in
--control-plane-endpoint=<VIRTUAL=IP>and point it to a load balancer.-
Then don’t need to change anything afterwards.
-
For a single Control Plane node, no need to pass in the above value.
-
-
With
--pod-network-cider=, this will be the IP address pool that the pods grab their IPs from.- Fpr example,
10.0.0.0/16- all pods would get an IP address from this subnet.
- Fpr example,
-
kubeadmtries to detect a runtime by using a list of well-known endpoints. -
Optional is if you need to manually pass in a socket with
--cri-socket=<PATH_TO_SOCKET> -
For the
kubeadmutility, there is the flag--apiserver-advertise-addressflag.-
When working with a single Control Plane node cluster,
--apiserver-advertise-addresstells the cluster what the IP address of yourkube-apiserveris. -
--apiserver-advertise-addressis set as the IP of the Master Node.- This is the standard IPv4 or IPv6 address.
-
If you have multiple interfaces, the above flag is a good way to find that interface.
-
- Then run the following
kubeadmcommand:sudo kubeadm init --apiserver-advertise-address 192.168.56.11 --pod-network-cidr "10.244.0.0/16" --upload-certs -
--pod-network-cidris the subnet the pods pull all of their IP addresses from. -
--upload-certsplaces all certificates into asecretand then all nodes have access to this. -
The above command will generate the CA certificates for the API server and all of the certificates for the
etcdserver. You can see the configuration file for your kubelet. It also provisions the static pod manifest for the different components and it brings in other components. -
Once complete, the command provisions a config file.
-
Can check the file at
/etc/kubernetes/admin.conf.-
This has a kube-config file, then we can talk to the master node.
-
We copy this to the home directory at
mkdir -p $HOME/.kubeand then the following commands:
-
-
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
-
Running
kubectl get nodeswill show the Control Plane node in aNotReadystate. This is expected, have not set up Network Plugin we need. -
Need to deploy a pod network for the cluster.
-
Join the worker nodes up with the provided command.
-
When setting up multiple Master Nodes, the command to join multiple Control Plane nodes will also be given.
- One Master Node would not see the above output displayed.
-
Then we install the Pod Network Addon
-
A good option is Flannel
-
A Kubernetes Manifest is given to apply the Pod Network Addon.
-
If using a custom CIDR network (i.e. not
10.244.0.0/16) , have to download the manifest and modify the network to match your own.-
You can
wgetthekube-flannel.yamlfile. -
Once you open the file, you configure the Pod Network under the
net-conf.jsontitle, under where it saysNetwork.- Need to make sure the IP range given also matches the
--pod-network-cidrcommand that was initially given as well.
- Need to make sure the IP range given also matches the
-
-
Then do
kubectl apply -f <flannel.yaml>
-
-
Then check with
kubectl get pod -n kube-systemnamespace as well. -
Also check with
kubectl get pod -n kube-flannel -
Finally have the other worker nodes join the cluster without issue.
-
When the
kube-flannelnamespace is checked again withkubectl get pod -n kube-flannel, it deploys the network plugin agent on every single nodes - that is why the amount of pods increases. -
Run a test pod with
kubectl run web --image=nginx.