Site icon CentLinux

How to install Kubernetes on Ubuntu Server 18

Share on Social Media

Learn step-by-step how to install Kubernetes on Ubuntu Server 18. This comprehensive guide covers all the essential commands and configurations needed to set up a Kubernetes cluster on your Ubuntu 18.04 system efficiently. #centlinux #ubuntu #k8s

What is Kubernetes?

Kubernetes (commonly stylized as k8s) is an open-source container-orchestration system for automating application deployment, scaling, and management. It was originally designed by Google, and is now maintained by the Cloud Native Computing Foundation. It aims to provide a “platform for automating deployment, scaling, and operations of application containers across clusters of hosts”.  (Courtesy: Wikipedia)

It works with a range of container tools, including Docker. Many cloud services offer a Kubernetes-based platform or infrastructure as a service (PaaS or IaaS) on which Kubernetes can be deployed as a platform-providing service. Many vendors also provide their own branded Kubernetes distributions.

In this article, you will learn how to install Kubernetes cluster on Ubuntu Server 18.04 LTS. We are configuring two Ubuntu Server nodes (a master node and a worker node), however the same steps can be used if you are planning to configure more nodes.

This tutorial will guide you about how to install a two node Kubernetes cluster on Ubuntu Server. And won’t address the theory and practical usage of Kubernetes. Therefore, if you intend to learn more about Kubernetes, then we highly recommend you to read Kubernetes: Up and Running: Dive into the Future of Infrastructure (PAID LINK) by O’Reilly Media.

Recommended Online Training: Kubernetes Training from Basic to Advanced

Ubuntu Servers Specification

We are using two KVM virtual machines with following specification.

Master Node:

Worker Node:

We have already installed Docker on both nodes. You can do the same by following our previous post Install Docker on Ubuntu Server 18 LTS.

Pre-installation configurations for Kubernetes

We need to configure name resolution between Ubuntu server nodes. For this purpose, we can either use an Authoritive DNS server or by using the Local DNS Resolver.

Connect with kubernetes-01 (master node) by using a ssh tool.

We are configuring the Local DNS Resolver for this purpose.

$ sudo vi /etc/hosts

Add following lines in this file.

192.168.116.218 kubernetes-01 kubernetes-01.centlinux.com
192.168.116.219 kubernetes-02 kubernetes-02.centlinux.com

Repeat the above step on kubernetes-02 (worker node).

Check installed version of Docker.

$ docker --version
Docker version 18.09.7, build 2d0083d

Verify that the Docker service is running on both nodes.

$ systemctl status docker
â docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e
   Active: active (running) since Sun 2020-02-16 11:17:17 UTC; 28min ago
     Docs: https://docs.docker.com
 Main PID: 1314 (dockerd)
    Tasks: 10
   CGroup: /system.slice/docker.service
           ââ1314 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/contain

Feb 16 11:17:17 docker-01.centlinux.com dockerd[1314]: time="2020-02-16T11:17:17.6
Feb 16 11:17:17 docker-01.centlinux.com systemd[1]: Started Docker Application Con

Turn off Swap on both Kubernetes nodes.

$ sudo sed -e '/swap/s/^/#/g' -i /etc/fstab
$ sudo swapoff -a

Add public key of Kubernetes Xenial repository in apt on both nodes.

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

Add Kubernetes Xenial repository on both nodes.

$ sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"

We have added the Kubernetes Xenial repository. We can now install Kubernetes on Ubuntu server using apt command.

Install Kubeadm on Ubuntu Server

Install Kubeadm using apt command on both nodes.

$ sudo apt install kubeadm -y

Check kubeadm version to verify if it is installed correctly.

$ kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:12:12Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"}

Pull required images for configuring Kubernetes on both nodes.

$ sudo kubeadm config images pull

Initialize Kubernetes on kubernetes-01 (master node) only.

$ sudo kubeadm init --apiserver-advertise-address=192.168.116.218
...
Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.116.218:6443 --token uivhq9.ecs1vzjiz5tal24j 
    --discovery-token-ca-cert-hash sha256:95ec6de9f2b260c807b021a1166abf45c55257b182ac94855f0ce60406c392d5

As required by the above output, we need to configure user environment before using Kubernetes. Therefore, execute following commands on kubernetes-01 (master node) only.

$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config

Join a Worker Node to Kubernetes Cluster

Connect with kubernetes-02.centlinux.com (worker node) by using ssh command.

Use the following command to join kubernetes-02 to our Kubernetes cluster as worker node.

$ sudo kubeadm join 192.168.116.218:6443 --token uivhq9.ecs1vzjiz5tal24j --discovery-token-ca-cert-hash sha256:95ec6de9f2b260c807b021a1166abf45c55257b182ac94855f0ce60406c392d5
...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

Connect with kubernetes-01 (master node) and get list of nodes to confirm that kubernetes-02 (worker node) has join the Kubernetes cluster.

$ sudo kubectl get nodes
NAME                        STATUS     ROLES    AGE     VERSION
kubernetes-01.centlinux.com   NotReady   master   54m     v1.17.3
kubernetes-02.centlinux.com   NotReady   <none>   8m27s   v1.17.3

We need to install a pod network, so our nodes can communicate with each others.

For this purpose, we are installing Flannel pod network on our Kubernetes cluster.

$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Check the status of nodes again.

$ sudo kubectl get nodes
NAME                        STATUS     ROLES    AGE     VERSION
kubernetes-01.centlinux.com   Ready   master   58m     v1.17.3
kubernetes-02.centlinux.com   Ready   <none>   12m27s   v1.17.3

We have successfully install Kubernetes on Ubuntu Server 18.04 LTS and setup a two node cluster. If you want to setup the same on CentOS 7, then you should follow our previous article install Kubernetes Cluster with Docker CE on CentOS 7.

Final Thoughts

Installing Kubernetes on Ubuntu Server 18 can seem daunting, but with the right guidance, it becomes a manageable task. By following this guide, you should now have a functional Kubernetes cluster ready for your development and deployment needs. If you need further assistance or want a professional to handle the setup for you, feel free to visit my Fiverr profile for expert services.


Exit mobile version