In this article on “14 Steps to Install kubernetes on Ubuntu 18.04 and 16.04” we are going to create Kubernetes cluster along with kubeadm on Ubuntu 18.04 (The same steps can be used for the Ubuntu 16.04 as well) kubeadm is command line tool to interact with kubernetes cluster. Kubeadm relies on fast deployment feature of Docker and running the system services of kubernetes master and etcd server as container. We are going to use two nodes Master node Worker node Prerequisites Reading time is about 20 minutes Vagrant 2.2.7 or latest – For installationi nstruction click here VM VirtualBox – For installation instruction click here As a minimum requirement for kubernetes installation we need – Step 1 – Start your vagrant box Master Node – 2 cpus, 2 GB Memory Worker Node – 1 cpu, 1 GB Memory Use following Vagrantfile to spin up your vagrant box Vagrant.configure( ) |config| config.vm.define |master| master.vm.box_download_insecure = master.vm.box = master.vm.network , : master.vm.hostname = master.vm.provider |v| v.name = v.memory = v.cpus = end end config.vm.define |worker| worker.vm.box_download_insecure = worker.vm.box = worker.vm.network , : worker.vm.hostname = worker.vm.provider |v| v.name = v.memory = v.cpus = end end end "2" do "master" do true "hashicorp/bionic64" "private_network" ip "100.0.0.1" "master" "virtualbox" do "master" 2048 2 "worker" do true "hashicorp/bionic64" "private_network" ip "100.0.0.2" "worker" "virtualbox" do "worker" 1024 1 SSH into the master node Step 2 – Update host files on both master and worker node master node – $ vagrant ssh master Add host entry for master as well as worker node vagrant@master:~$ sudo vi /etc/hosts master.jhooq.com master worker.jhooq.com worker 100.0 .0 .1 100.0 .0 .2 Test the worker node by sending from master [vagrant@master ~]$ ping worker PING worker.jhooq.com ( ) ( ) bytes data. bytes worker.jhooq.com ( ): icmp_seq= ttl= time= ms bytes worker.jhooq.com ( ): icmp_seq= ttl= time= ms 100.0 .0 .2 56 84 of 64 from 100.0 .0 .2 1 64 0.462 64 from 100.0 .0 .2 2 64 0.686 Test the master node by sending from worker [vagrant@worker ~]$ ping master PING master.jhooq.com ( ) ( ) bytes data. bytes master.jhooq.com ( ): icmp_seq= ttl= time= ms bytes master.jhooq.com ( ): icmp_seq= ttl= time= ms 100.0 .0 .1 56 84 of 64 from 100.0 .0 .1 1 64 0.238 64 from 100.0 .0 .1 2 64 0.510 Step 3 – Install Docker on both master and worker node You need to install Docker on both the node. So run the following installation command on both the nodes [vagrant@master ~]$ sudo apt-get update [vagrant@master ~]$ sudo apt install docker.io Enable and start docker vagrant@master:~$ sudo systemctl enable docker Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service. [vagrant@master ~]$ sudo systemctl start docker Check the docker service status [vagrant@master ~]$ sudo systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded ( systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Thu : : UTC; s ago Docs: https: /lib/ 2020 -04 -23 19 10 59 4 //docs.docker.com We need to disable firewall as well as swapping on master as well as worker node. Because to install kubernetes we need to disable the swapping on both the nodes Step 4 – Disable the firewall and turnoff the “swapping” vagrant@worker:~$ sudo ufw disable Firewall stopped and disabled on system startup [vagrant@worker ~]$ sudo swapoff -a Step 5 – Install “apt-transport-https” package To download the kubernetes and its public we need to install “apt-transport-https” package on both master as well as worker node vagrant@master:~$ sudo apt-get update && sudo apt-get install -y apt-transport-https Step 6 – Download the public keys We need to have the public keys for accessing packages on Google Cloud. So run the following command to get the public keys on both master as well as worker node vagrant@worker:~$ curl -s https: OK //packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - Step 7 – Add kubernetes repo As a next step we need to add the kubernetes repo to both master as well as worker node vagrant@worker:~$ sudo bash -c 'echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list' Step 8 – Install kubernetes Now after adding the kubernetes repo we need to install the kubernetes on both mater as well as worker node vagrant@master:~$ sudo apt-get update && sudo apt-get install -y kubelet kubeadm kubectl Step 9 – Enable and Start kubelet Alright now we have installed the kubernetes, now we need to enable the kubelet support for both master as well worker node [vagrant@master ~]$ sudo systemctl enable kubelet [vagrant@master ~]$ sudo systemctl start kubelet Step 10 – Initialize the kubernetes cluster Okay now we have reach to point where we have done all the prerequisite for initializing the kubernetes cluster. Let’s run the kubernetes initialization command on only on master [vagrant@master ~]$ sudo kubeadm init --apiserver-advertise-address= --pod-network-cidr= / 100.0 .0 .1 10.244 .0 .0 16 Note down kubeadm join command which we are going to use from worker node to join the master node using token. sudo kubeadm join : --token g2bsw7 xr3bqc21eqyc6r7 --discovery-token-ca-cert-hash sha256: b2b0608b9300b3342a8d0a0e9204c8fc74d45b008043a810f94e4f1fb8861f 100.0 .0 .1 6443 .5 39 Step 11 – Move kube config file to current user (only run on master) To interact with the kubernetes cluster and to use kubectl command, we need to have the kube config file with us. Use the following command to get the kube config file and put it under working directory. [vagrant@master ~]$ mkdir -p $HOME/.kube [vagrant@master ~]$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config [vagrant@master ~]$ sudo chown $(id -u):$(id -g) $HOME/.kube/config Step 12 – Apply CNI from kube-flannel.yml(only run on master) After the master of the cluster is ready to handle jobs and the services are running, for the purpose of making containers accessible to each other through networking, we need to set up the network for container communication Get the CNI(container network interface) configuration from flannel [vagrant@master ~]$ wget https: //raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml Note – But since we are working on the VMs so we need to check our Ethernet interfaces first. Look out for the Ethernet i.e. eth1 which has a ip address 100.0.0.1(this is the ip address which we used in vagrant file) [vagrant@master ~]$ ip a s : lo: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:bb:14:75 brd ff:ff:ff:ff:ff:ff inet 10.0.2.15 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:fb:48:77 brd ff:ff:ff:ff:ff:ff inet 100.0.0.1 4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> 1 2: eth0: < > LOOPBACK,UP,LOWER_UP Now we need to add the extra args for eth1 in kube-flannel.yml [vagrant@master ~]$ vi kube-flannel.yml Searche for – “flanneld” In the args section add : – –iface=eth1 - --iface=eth1 args: - --ip-masq - --kube-subnet-mgr - --iface=eth1 Apply the flannel configuration vagrant@master:~$ kubectl apply -f kube-flannel.yml podsecuritypolicy.policy/psp.flannel.unprivileged created clusterrole.rbac.authorization.k8s.io/flannel created clusterrolebinding.rbac.authorization.k8s.io/flannel created serviceaccount/flannel created configmap/kube-flannel-cfg created daemonset.apps/kube-flannel-ds-amd64 created daemonset.apps/kube-flannel-ds-arm64 created daemonset.apps/kube-flannel-ds-arm created daemonset.apps/kube-flannel-ds-ppc64le created daemonset.apps/kube-flannel-ds-s390x created Step 13 – Join worker nodes to master(only run on worker) In the Step 10 we generated the token and kubeadm join command. Now we need to use that join command from our worker node vagrant@worker:~$ sudo kubeadm join : --token g2bsw7 xr3bqc21eqyc6r7 --discovery-token-ca-cert-hash sha256: b2b0608b9300b3342a8d0a0e9204c8fc74d45b008043a810f94e4f1fb8861f 100.0 .0 .1 6443 .5 39 W0423 : : join.go: ] [preflight] WARNING: JoinControlPane.controlPlane settings will be ignored when control-plane flag is not set. [preflight] Running pre-flight checks [WARNING IsDockerSystemdCheck]: detected the Docker cgroup driver. The recommended driver is . Please follow the guide at https: [preflight] Reading configuration the cluster... [preflight] FYI: You can look at config file [kubelet-start] Downloading configuration the kubelet the ConfigMap the kube-system namespace [kubelet-start] Writing kubelet configuration to file [kubelet-start] Writing kubelet environment file flags to file [kubelet-start] Starting the kubelet [kubelet-start] Waiting the kubelet to perform the TLS Bootstrap... This node has joined the cluster: * Certificate signing request was sent to apiserver and a response was received. * The Kubelet was informed the secure connection details. Run on the control-plane to see node join the cluster. 19 27 00.344480 18268 346 "cgroupfs" as "systemd" //kubernetes.io/docs/setup/cri/ from this with 'kubectl -n kube-system get cm kubeadm-config -oyaml' for from "kubelet-config-1.18" in "/var/lib/kubelet/config.yaml" with "/var/lib/kubelet/kubeadm-flags.env" for of new 'kubectl get nodes' this Step 14 – Check the nodes status(only run on master) To check the status of the nodes use [vagrant@master ~]$ kubectl get nodes NAME STATUS ROLES AGE VERSION master Ready master m v1 worker Ready <none> s v1 26 .18 .2 63 .18 .2 Summary So this was our beginner tutorial which involves around – 14 Steps to Install kubernetes on Ubuntu 18.04 and 16.04. With that we can conclude what we have achieved – Congratulations we have successfully installed kubernetes on Ubuntu 18.04 After installing kubernetes we are successfully join the worker nodes with master.