Kubernetes Cluster on Vagrant

In this tutorial we will cover the installation of a Kubernetes Cluster over 3 virtual machines spawned using Virtualbox and Vagrant. This can be also useful to install Kubernetes over Bare Metal server or any sort of Virtual Machines as well.

Assumptions

  • Vagrant and Virtualbox are already installed.
  • We have 3 Centos 7 virtual machines running.

Pre-requisites

  • Set the host-names for all 3 machines with the below commands
    • sudo hostnamectl set-hostname kubem
    • sudo hostnamectl set-hostname worker1
    • sudo hostnamectl set-hostname worker2
  • Disable selinux
    • set selinux 0
    • edit the file /etc/sysconfig/selinux and disable selinux
    • or use the below command directly to disable selinux
    • sudo sed -i s/^SELINUX=.*$/SELINUX=disabled/ /etc/selinux/config
  • Disable swap memory
    • swapoff -a
    • vim /etc/fstab
    • or
    • sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
  • Set net bridge for proper traffic routing
    • cat < /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF
  • Reload sysctl
    • sysctl --system
  • Set DNS entries in /etc/hosts
    • 192.168.10.60 kubem
    • 192.168.10.61 worker1
    • 192.168.10.62 worker2
  • Docker Installation
    • yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    • yum update -y
    • yum install -y yum-utils device-mapper-persistent-data lvm2 -y
    • sudo yum install docker-ce -y
    • sudo yum install docker-ce -y
    • systemctl enable docker
    • systemctl start docker
    • systemctl status docker
    • systemctl status docker
    • docker version
    • docker info
  • Installing kubelet, kubeadm, kubectl
    • cat < /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg EOF
    • yum install -y kubelet-1.15.1 kubeadm-1.15.1
    • systemctl enable kubelet
    • systemctl start kubelet
  • Initialize the kubernetes cluster
    • kubeadm init --apiserver-advertise-address=172.31.19.193 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.244.0.0/12
  • Become Non-root user
    • mkdir -p $HOME/.kube
    • sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    • sudo chown $(id -u):$(id -g) $HOME/.kube/config
  • Creating the CNI and Dashboard:
    • kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
    • kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml
    • kubectl -n kube-system edit service kubernetes-dashboard
    • change from ClusterIP to NodePort
    • kubectl describe services kubernetes-dashboard -n kube-system
    • kubectl -n kube-system get secret
    • kubectl -n kube-system describe secret namespace-contoller-token-xyxyx
    • now use this token to login to the cluster IP

Deepak Gupta

A full time technologist cum foodieeeeeee... I spend most of my time playing with open source tools and technologies. I prefer hanging out most of the time, and have been a taveller since ages, besides being a biker at heart I do love to practice photography in my liesure.

Bangalore, INDIA https://hellodk.io/