Streamlining Your Kubernetes Cluster Setup with Kubeadm
Kubeadm is a tool that automates the process of setting up a Kubernetes cluster. It streamlines the process of setting up the control plane, including configuring the API server, controller manager, and scheduler, and creating the necessary Kubernetes objects. Kubeadm also generates a kubelet configuration file for setting up worker nodes and joining them to the cluster.
Prerequisites: Before setting up a Kubernetes cluster, ensure that you have the necessary hardware, software, and networking resources in place. This includes setting up a control node and one or more worker nodes, installing a container runtime such as Docker, and configuring networking
sudo apt update -y
sudo apt install docker.io -y
sudo apt update -y
: This command updates the package list on your system. It retrieves the latest information about packages available for installation from the repositories configured on your system.sudo apt install
docker.io
-y
: This command installs the Docker container runtime on your system. The-y
flag is used to automatically answer "yes" to any prompts that may come up during the installation process.
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl start docker
: This command starts the Docker service on your system. Once the service is started, you can use the Docker CLI to interact with Docker containers and images.sudo systemctl enable docker
: This command configures the Docker service to start automatically on boot. This ensures that the Docker service is always running, even after a system reboot.
curl -fsSL "https://packages.cloud.google.com/apt/doc/apt-key.gpg" | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/kubernetes-archive-keyring.gpg
/usr/share/keyrings/kubernetes-archive-
: File locationkeyring.gpg
.https://packages.cloud.google.com/apt/doc/apt-key.gpg
: This is the URL of the Kubernetes repository signing key.
echo 'deb https://packages.cloud.google.com/apt kubernetes-xenial main' | sudo tee /etc/apt/sources.list.d/kubernetes.list
These command will add Kubernetes package repository to your system's package sources by creating a new file /etc/apt/sources.list.d/kubernetes.list
sudo apt update -y
sudo apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y
First it will update then sudo apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y
: This command installs the specified version of kubeadm
, kubectl
, and kubelet
packages from the Kubernetes package repository.
The above all commands must be run on both the Kubernetes master node and worker nodes to install the required dependencies and Kubernetes components.
On the master node, these commands are used to install the Kubernetes control plane components (kubeadm
, kubelet
, and kubectl
) and dependencies such as docker.io
.
On the worker nodes, these commands are used to install the kubelet
and kubectl
components and dependencies required to join the worker node to the Kubernetes cluster
----- Both Master & Worker Node ----
# using 'sudo su' is not a good practice.
sudo apt update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo apt install docker.io -y
sudo systemctl enable --now docker # enable and start in single command.
# Adding GPG keys.
curl -fsSL "https://packages.cloud.google.com/apt/doc/apt-key.gpg" | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/kubernetes-archive-keyring.gpg
# Add the repository to the sourcelist.
echo 'deb https://packages.cloud.google.com/apt kubernetes-xenial main' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update
sudo apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y
Now Only For Master
kubeadm init
sudo su
: Turn it to the superuser (root) account. This is necessary because thekubeadm init
command requires superuser privileges to execute.kubeadm init
: This command initializes a new Kubernetes control plane on the current node. When executed, this command performs several tasks, including:
Downloading and installing the required Kubernetes control plane components (
etcd
,kube-apiserver
,kube-controller-manager
, andkube-scheduler
).Creating the Kubernetes configuration files required to run the control plane components.
Generating the join token required for worker nodes to join the cluster.
Setting up the
kubectl
configuration file for the current user to access the newly-created Kubernetes cluster.
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
These commands are used to set up the kubectl
configuration for the current user, allowing you to interact with the newly-created Kubernetes cluster
kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
When this command is executed, Kubernetes will download the Weave Net CNI plugin YAML file from the specified URL and deploy it to the cluster using the kubectl apply
command. Once the deployment is complete, Weave Net will be responsible for managing the networking between pods running on different worker nodes in the Kubernetes cluster.
kubeadm token create --print-join-command
This command is used to generate a new join token that can be used to add new worker nodes to the Kubernetes cluster
Master Node
kubeadm init
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
kubeadm token create --print-join-command
Now Only For Worker Nodes
sudo su
kubeadm reset pre-flight checks
The command kubeadm reset
is used to reset a Kubernetes cluster to its initial state. It undoes all changes made by kubeadm init
and kubeadm join
commands. When you run kubeadm reset
, it removes the /etc/kubernetes/
directory, which contains all the configuration files and cryptographic materials generated by kubeadm init
and kubeadm join
. It also removes the kubelet configuration files from the default location /etc/systemd/system/kubelet.service.d/
.
Paste the Join command on worker node with --v=5
(Verbosity logs)
Worker Node
sudo su
kubeadm reset pre-flight checks
sudo -----> Paste the Join command on worker node with `--v=5`
kubectl get nodes
paste these on Master Node to check connectivty.
Subscribe to my newsletter
Read articles from Sushrut Netkar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by