Kubernetes has become the standard for container orchestration, offering scalability and reliability for managing containerized applications. In this guide, we’ll walk through the process of creating a Kubernetes cluster from scratch, providing detailed commands and explanations along the way. By the end, you’ll have a fully functional Kubernetes cluster ready to deploy and manage your applications.
Step 1: Understanding Kubernetes Concepts: Before diving into cluster creation, let’s understand some key concepts:
Nodes: Machines that make up the cluster.
Master Node: Manages the cluster.
Worker Node: Hosts applications.
Pods: Deployable units.
Services: Enable access to pods.
Step 2: Choosing a Deployment Method: We’ll use kubeadm for manual setup, suitable for any infrastructure.
Step 3: Preparing Ubuntu Instances: Ensure each Ubuntu instance meets requirements.
Step 4: Installing Docker:
sudo apt-get update
sudo apt-get install docker.io -y
sudo systemctl enable docker
sudo systemctl restart docker
Step 5: Installing Kubernetes Components:
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gpg
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Step 6: Initializing the Master Node:
sudo kubeadm init
Step 7: Configuring kubectl:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Step 8: Installing Pod Network Add-on:
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.2/manifests/tigera-operator.yaml
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.2/manifests/custom-resources.yaml
Step 9: Joining Worker Nodes: Run join command from master node on each worker node.
sudo kubeadm token create --print-join-command
Run the copied kubeadm join command as a root user on the worker node
Step 10: Verifying Cluster Setup:
kubectl get nodes
Conclusion: Congratulations! You’ve successfully created a Kubernetes cluster. Explore Kubernetes documentation for further learning and deployment possibilities.
Resources:
Kubernetes Official Documentation: https://kubernetes.io/docs/
kubeadm Documentation: https://kubernetes.io/docs/reference/setup-tools/kubeadm/