In this project, you will create a Kubernetes cluster using kubeadm. This will involve setting up the control plane node and worker nodes, configuring network settings, and ensuring the cluster is functioning correctly.
Before you begin, make sure you have a clean environment. You can use virtual machines, cloud instances, or physical machines. Ensure that each machine has the following minimum requirements:
- 2 GB or more of RAM per machine
- 2 CPUs or more
- Full network connectivity between all machines in the cluster
- Unique hostname, MAC address, and product_uuid for every node
Follow the official Installing kubeadm guide to install kubeadm, kubelet, and kubectl on each node.
-
Update the package index and install packages needed to use the Kubernetes apt repository:
sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl
-
Download the Google Cloud public signing key:
sudo curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
-
Add the Kubernetes apt repository:
sudo bash -c 'cat <<EOF >/etc/apt/sources.list.d/kubernetes.list deb https://apt.kubernetes.io/ kubernetes-xenial main EOF'
-
Update apt package index, install kubelet, kubeadm, and kubectl, and pin their version:
sudo apt-get update sudo apt-get install -y kubelet kubeadm kubectl sudo apt-mark hold kubelet kubeadm kubectl
On the control plane node, run the following command to initialize the cluster:
sudo kubeadm init --pod-network-cidr=192.168.0.0/16
This command will set up the control plane components and create a new cluster. The --pod-network-cidr
option specifies the CIDR block for the pod network.
To start using your cluster, you need to set up the kubeconfig file:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Install a pod network addon so that your pods can communicate with each other. Here is an example using the Calico network plugin:
kubectl apply -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml
On each worker node, run the kubeadm join
command that was output when you initialized the control plane node. If you didn't save the command, you can generate a new token on the control plane node:
kubeadm token create --print-join-command
Run the output command on each worker node to join them to the cluster.
Check the status of the nodes to ensure they are all part of the cluster:
kubectl get nodes
You should see a list of all nodes in the cluster with a STATUS of "Ready".
Deploy a simple web server application to verify your cluster is working:
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort
Get the NodePort and access the application via a web browser or curl command:
kubectl get services