How to Deploy a Kubernetes Cluster in Azure Virtual Machines?
Last Updated :
10 Apr, 2024
Azure Kubernetes Service provides a platform for managing containers with the help of Kubernetes. It also provides an easy and managed way for the deployment and scaling of containerized applications. Containerized applications are deployed in the Kubernetes cluster in Azure. But we can also manually set up a Kubernetes cluster in Azure. Let's see how to deploy a Kubernetes cluster on Azure VMs.
Primary Terminologies
- Kubernetes: It is an open-source container orchestration platform designed to automate the deployment, scaling, and management of containerized applications.
- Kubernetes Cluster: It is a set of nodes on which containerized applications run.
Deploy Kubernetes Cluster in Azure VM
Step 1: Deploy Azure VM
- Go to the Azure portal and create a minimum of 2 virtual machines, as described in this article. Create VMs with a minimum configuration of 2 vCPUs and 8 GB RAM.
- Recommend you use Ubuntu as OS.
- One VM will act as a master node for our cluster while others will act as worker nodes.
- Once all VMs are deployed start with the following steps.
- Follow Step 2 to Step 5 for all the VMs.
Step 2: Disable the firewall for VM
- SSH to the VM using the below command
ssh username@public-ip
.png)
- As we will be starting Kubernetes API server the firewall may interfare with our output. Hence disable the firewall using below command.
sudo ufw disable
.png)
- Then disable swapping for swapping devices using below commands.
swapoff -a
sudo sed -i '/swap/d' /etc/fstab
1.png)
- Now we will add following parameters in kernel parameters. Run below command.
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF
.png)
- Apply the new system configuration using below command.
sudo sysctl --system
.png)
Step 3: Install the certificate applications.
- Install the below applications with the help of below command.
sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Step 4: Install Docker
- Now lets install docker as root user . first switch to root user
sudo su
.png)
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
.jpg)
apt update
.png)
apt install docker.io
.png)
Step 5: Install Kubernetes
- Being as root add kubernetes to apt list
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
.png)
.jpg)
apt update
.png)
- Finally install kubelet , kubeadm & kubectl
apt-get install -y kubelet kubeadm kubectl
.png)
Step 6: Initialize cluster and kubeadm (Only for master node)
- First get the Ip address of your machine.
ip addr
.png)
- From output copy address for eth0 interface.
- Initiate Kubeadm and start the cluster. Replace your IP address in command .
kubeadm init --apiserver-advertise-address=<apiserver-advertise-address-ip> --pod-network-cidr=192.168.0.0/16 --ignore-preflight-errors=all
.jpg)
.png)
- This will start the Kubernetes api server . Copy the kubeadm join command from output which required in next steps .Finally add config files
export KUBECONFIG=/etc/kubernetes/admin.conf
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
.png)
- Now we are done with the configuration of master node . We just have to install container networking in cluster. Logout from root and then run below command
kubectl apply -f "https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s-1.11.yaml"
.jpg)
Step 7: Connect The worker node.
- On worker node after following step 2 to 5 paste the kubeadm command copied from master node.
- You should see that worker node is joined.
Step 8: Verify the cluster.
- On master node run Kubernetes commands to list all components.
kubectl get all -A
.jpg)
Conclusion
Thus we have seen how we can install a Kubernetes cluster manually on Azure Virtual machines . This allows to build kubernetes cluster from scratch allowing to manage each component of Kubernetes separately. This can be furthur modified for complex configurations.
Similar Reads
How To Use Kind To Deploy Kubernetes Clusters?
Kind also referred to as Kubernetes in Docker is a popular open-source tool used for running a Kubernetes cluster locally. Kind uses Docker containers as Cluster Nodes making it substantially faster than its alternatives like Minikube or Docker Desktop which uses a Virtual Machine. Kind is commonly
10 min read
How to Deploy React App on Azure Virtual Machines?
In this article, we will study how we can deploy our existing React web application to Azure VM on Ubuntu Server. We will also see how to use the public IP of the Azure VM to access the React application using Nginx. For this article, you should know about setting up a VM in Azure. We will see how t
5 min read
How To Deploy Dashboard UI On A Kubernetes Cluster Locally ?
Docker Desktop is easily the most popular containerization software for developers and teams. But Docker Desktop would not only allow you to play with containers but can enable you to use Kubernetes without downloading any external cluster like Minikube. Docker Desktop is a secure, out-of-the-box co
6 min read
How to Scale a Kubernetes Cluster ?
Scaling a Kubernetes cluster is crucial to meet the developing needs of applications and ensure the finest performance. As your workload increases, scaling becomes vital to distribute the weight, enhance useful resource usage, and maintain high availability. This article will guide you through the t
8 min read
How to Deploy Angular App in Kubernetes ?
In the modern world of web development, Angular has become one of the most popular frameworks for building dynamic and responsive web applications. As the demand for scalability and reliability increases, deploying these applications in a containerized environment using Kubernetes has become a commo
5 min read
How To Deploy Nginx In Kubernetes ?
Kubernetes is an open-source container orchestration tool used to deploy, scale, and manage containerized applications. On the other hand, NGINX is a web service used for proxying and load balancing. Here in this article, I have first discussed what is Kubernetes and its features. Then I have discus
8 min read
How to Deploy Kubernetes on AWS?
Kubernetes, the open-supply box orchestration platform, has emerged as the solution for dealing with containerized applications. When deploying Kubernetes in the cloud, Amazon Web Services (AWS) gives a robust and scalable environment. In this manual, we can walk you through the manner of deploying
7 min read
How to Add Node to Existing Kubernetes Cluster
Kubernetes allows the management and orchestration of containerized deployments. We can use various cluster managing tools, but Kubeadm allows us to create and manage Kubernetes clusters from scratch. Kubernetes cluster can be autoscaled with the use of Cluster management services. In this article,
4 min read
How to Deploy Node.js Application in Kubernetes?
Deploying the Node.js application on Kubernetes in a containerized manner makes it highly scalable,fault-tolerant, and allows for zero downtime. Kubernetes allows container orchestration that can be used in many ways during deployment. Load balancing is provided, which helps with automatic load tran
4 min read
How To Deploy Python Application In Kubernetes ?
In today's IT world we are moving from the monolithic to microservice architecture to make our applications highly available and scalable to bring fault tolerance. In this transformation, containerization i.e., containerizing the application are a fundamental aspect of this micro services. In this a
6 min read