Install Kubernetes Cluster using kubeadm
Kubernetes is a most popular container orchestrator tool. Here we will learn how to set it up in production environment for very low scale using two nodes.
#Prerequisites
- Two virtual machines with Ubuntu installed and sudo privileges. One for master node and one for worker node.
- Basic understanding of container runtime that is docker.
#End Goal
- Install Kubernetes cluster for low scale applications.
- Setup Pod Network in cluster, so that applications inside multiple pods can talk with each other.
#Installation on Master and Worker Node
Note: Configure both master and worker machine till 6th steps.
- Update the existing packages and install required dependencies.
apt-get update && apt-get install -y apt-transport-https
- Add key.
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
- Setup kubernetes repository
cat <<EOF > /etc/apt/sources.list.d/kubernetes.list deb http://apt.kubernetes.io/ kubernetes-xenial main EOF
- Update repository to fetch kubernetes package.
apt-get update
- Install Container runtime- Docker
apt-get install -y docker-ce
- Install kubelet (Kuberenetes node agent), kubeadm, kubectl (client tool to manage kubernetes) and kubernetes-cni (kubernetes conatiner network interface).
apt-get install -y kubelet kubeadm kubectl kubernetes-cni=0.6.0-00
Note: Till here, you have to setup on both the nodes of cluster.
#Setup Master Node
- Initialise the master node using kubeadm (Run this command only on master node)
kubeadm init
- After running above command, you will get commands to setup your kubectl client and to join other nodes this cluster. Setup kubectl client by run those commands and save cluster join command for later use.
- After setting up kubectl client, install pod network plugin. For this tutorial we will use weave plugin.
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
- See, node status
kubectl get node NAME STATUS AGE masterserver Ready,master 1m
#Setup Worker Node
- Run the command that got printed after initialising the cluster
Here, kubernetes cluster is ready to use.
#Setup Nginx webserver
- Create deployment
kubectl create deployment nginx --image=nginx:latest
- Create service to expose application on node port
kubectl expose deployment nginx --type=NodePort --port 80
- Check on which node port the application is running
kubectl get svc
- Surf the application on browser.
Yay! Nginx webserver got deploy on Kubernetes cluster.
0 comments:
Post a Comment