Kubernetes the HARD WAY with Kubeadm
Rounak Surana
?? SRE/DevOps Evangelist | Driving Cloud Infrastructure Excellence | Kubernetes & Terraform Expert
The kubeadm tool is used to bootstrap a smaller Kubernetes cluster where you can experience all Kubernetes features. The cluster spin-up using kubeadm is eligible to pass the Kubernetes Conformance Program. The cluster life-cycles functions and cluster upgrade also supports by kubeadm.
If you are getting started with Kubernetes, then this is the perfect start to bootstrapping a cluster using kubeadm. As well as if you want to test two-node or three-node cluster, you can do it on your local machine or workstation by creating a guest operating system. You can automate these commands using any configuration management tool.
You can install kubeadm on your local machine or laptop, any of the cloud servers, or on Arduino, Raspberry Pi, etc.
Our Kubernetes Architecture will look like below. It is a simple 2 Node Cluster with One Master and One Worker. The networking is via Flannel
Prerequisites:
2 provisioned Cloud Servers on any platform either AWS, Azure, GCP, DigitalOcean. We will ensure that the OS must be similar for both instances. In this guide, we will be demonstrating on AWS.
The ec2-dashboard will look like this:
NOTE - You might have to add INBOUND Rules to the security group to SSH as well as Interconnectivity of Master and Worker Node.
Step 1: Install some software and Configure Docker on both Master and Worker Node
sudo apt-get update #Install some packages sudo apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common #Adding key from Docker Repo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - #Adding repository sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" #Install Docker and related packages sudo apt-get update && sudo apt-get -y install docker-ce docker-ce-cli #By default the docker service will be up and running, if not you can manually start with below command systemctl start docker
Step 2: Kernel Parameter Configuration (only on Master Node)
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sudo sysctl --system
Step 3: Configuring Repository and Installation of Kubeadm and related packages (on both Master and Worker Node)
#Adding appropriate key curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list deb https://apt.kubernetes.io/ kubernetes-xenial main EOF sudo apt-get update #Install Kubelet, Kubeadm and Kubectl sudo apt-get install -y kubelet kubeadm kubectl sudo apt-mark hold kubelet kubeadm kubectl
Verify Kubeadm installation and version:
Step 4: Initialize Cluster with Kubeadm (On Master Node)
#Initialize Kubeadm Cluster sudo kubeadm init --pod-network-cidr=10.244.0.0/16
Perform the below steps (On Master Node):
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
**IMP** - Note that you will see coredns pod in the pending state when getting all resources like below. If this will remain in pending state, we will not be able to join the worker nodes to the master node.
Step 5: Install Network Addon(Flannel) on Master Node
To bring them up and in running state, we will install a Network Addon(Flannel):
#Creating a kube-flannel pod in kube-system namespace kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Perform the below steps to Join Worker Node 01 to the Master Node (On Worker Node):
sudo kubeadm join 172.31.14.207:6443 --token tfrewt.3l26givmyk9e9mp6 --discovery-token-ca-cert-hash sha256:2cc4f26fa89816fcc04b6697b024dad11904822c54b6f15bb83fb1b74bd4ef30
You can verify if the Worker Node has joined the cluster with sudo kubectl get nodes on Master Node
You will also see 2 new pods now created now on the Worker Node.
We can also verify if the things are working as expected by running a standard nginx pod and see it deployed on to the Worker Node.
#Deploy ngnix pod sudo kubectl run nginx --image nginx
I hope you enjoyed and learned the proper way of creating Kubernetes Cluster on AWS with Kubeadm. Please share with your friends and connections if you find it useful and worth reading.
For any queries, please feel free to reach out to me on [email protected] or Linkedin.
??? Engineer & Manufacturer ?? | Internet Bonding routers to Video Servers | Network equipment production | ISP Independent IP address provider | Customized Packet level Encryption & Security ?? | On-premises Cloud ?
1 年This is a great article! I'm impressed with how Kubeadm simplifies the process of spinning up a Kubernetes Cluster on a Virtual Cloud Server. I'm sure this will help many developers out there. Have you also tried setting up an EKS Cluster with AWS? What were the challenges you faced? Would love to know your thoughts. #Kubernetes #DevOps #Cloud #EKS #KOPS
Sales and Engagement at Vention | One of the biggest killers of companies is premature scale
4 年Nicely written and presented Rounak. We should have a chat about getting together and presenting this in an online format soon, check out my K8S group https://www.meetup.com/DevOps-For-Everyone/
Senior Data Engineer at Accenture | SQL | POWER BI | SSIS | AZURE DATA FACTORY | AZURE SYNAPSE ANALYTICS
4 年Great article!! Keep going ??
AWS Cloud Operations Head @Stellantis. Ex-Capgemini, Ex-Ericsson
4 年Hey Rounak..we have same kind of setup in our project with Aws load balancer to expose the apps with secure SSL. Let me know you want to explore the same.
Senior DevOps Engineer at Tata Consultancy Services | TCS AI Cloud
4 年Excellent work Just one question in my mind as you created one pod there what if i want to expose that pod as type LoadBalancer will i get External IP or not?