Saturday 6 October 2018

Setup Kuberenetes Cluster using kubeadm

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

  1. Two virtual machines with Ubuntu installed and sudo privileges. One for master node and one for worker node.
  2. Basic understanding of container runtime that is docker.

#End Goal

  1. Install Kubernetes cluster for low scale applications.
  2. 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.
  1. Update the existing packages and install required dependencies.

    apt-get update && apt-get install -y apt-transport-https

  2. Add key.

    curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
    

    
    
  3. Setup kubernetes repository

    cat <<EOF > /etc/apt/sources.list.d/kubernetes.list  
    deb http://apt.kubernetes.io/ kubernetes-xenial main  
    EOF
    

  4. Update repository to fetch kubernetes package.

    apt-get update
    

  5. Install Container runtime- Docker

    apt-get install -y docker-ce
    

  6. 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

  1.  Initialise the master node using kubeadm (Run this command only on master node)

    kubeadm init
    

  2. 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.

  3. 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')"
    

  4. See, node status

    kubectl get node  
    NAME               STATUS            AGE  
    masterserver   Ready,master   1m
    

#Setup Worker Node

  1. Run the command that got printed after initialising the cluster

Here, kubernetes cluster is ready to use.

#Setup Nginx webserver
  1. Create deployment

    kubectl create deployment nginx --image=nginx:latest
    

  2.  Create service to expose application on node port

    kubectl expose deployment nginx --type=NodePort --port 80
    

  3. Check on which node port the application is running

    kubectl get svc
    
  4. Surf the application on browser.
Yay! Nginx webserver got deploy on Kubernetes cluster.

0 comments:

Post a Comment

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel