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 (often abbreviated as K8s) is an open-source container orchestration platform designed to automate the deployment, scaling, and management of containerized applications. Originally developed by Google and now maintained by the Cloud Native Computing Foundation (CNCF), Kubernetes simplifies the complex task of managing containerized workloads across multiple environments, including on-premises, cloud, and hybrid infrastructures.

At its core, Kubernetes provides a declarative approach to managing applications, meaning users define the desired state of their application, and Kubernetes ensures that state is maintained. It does this through features such as self-healing, load balancing, automated rollouts and rollbacks, storage orchestration, and service discovery.

Key Features of Kubernetes

  1. Automated Scaling – Kubernetes automatically scales applications based on demand using the Horizontal Pod Autoscaler (HPA).
  2. Self-Healing – If a container or node fails, Kubernetes restarts or reschedules the workload to maintain availability.
  3. Load Balancing – It distributes traffic across multiple instances of an application to ensure stability and performance.
  4. Storage Orchestration – Kubernetes integrates with various storage backends, including cloud storage, network-attached storage (NAS), and local disks.
  5. Service Discovery – Applications running in Kubernetes can communicate with each other using built-in DNS-based service discovery.
  6. Automated Rollouts & Rollbacks – Kubernetes ensures smooth application updates by rolling out changes gradually and rolling back if an issue occurs.
How to install Kubernetes on Ubuntu Server 18

Use Cases of Kubernetes

Kubernetes is widely used in different industries and scenarios, including:

1. Microservices Architecture

Kubernetes is a perfect fit for microservices-based applications, where multiple independent services communicate with each other. It helps in deploying, scaling, and managing microservices efficiently.

2. DevOps & CI/CD Automation

Many organizations use Kubernetes as part of their DevOps pipelines to automate the deployment of applications in Continuous Integration/Continuous Deployment (CI/CD) workflows. Tools like Jenkins, GitLab CI/CD, and ArgoCD integrate seamlessly with Kubernetes.

3. Hybrid & Multi-Cloud Deployments

Kubernetes allows organizations to deploy and manage applications across multiple cloud providers (AWS, Google Cloud, Azure) or in a hybrid setup (on-premises + cloud).

4. AI & Machine Learning Workloads

Kubernetes is used in AI/ML applications where models are trained and deployed in containerized environments using frameworks like TensorFlow, PyTorch, and Kubeflow.

5. Edge Computing & IoT

With lightweight Kubernetes distributions like K3s and MicroK8s, organizations can deploy workloads at the edge for IoT applications, reducing latency and bandwidth costs.

Alternatives to Kubernetes

While Kubernetes is a leading container orchestration platform, several alternatives exist, each with unique benefits:

  1. Docker Swarm – A native clustering and orchestration tool by Docker, simpler than Kubernetes but with fewer features.
  2. Nomad (by HashiCorp) – A lightweight, flexible orchestrator that supports containers, VMs, and standalone applications.
  3. Amazon ECS (Elastic Container Service) – A fully managed container orchestration service by AWS, integrated with other AWS services.
  4. Azure Service Fabric – A Microsoft alternative designed for microservices and container orchestration in Azure environments.
  5. OpenShift (by Red Hat) – A Kubernetes-based enterprise platform with added security and developer-friendly tools.

Conclusion

Kubernetes has revolutionized the way organizations deploy and manage modern applications, offering flexibility, scalability, and automation. Whether for microservices, DevOps, AI, or hybrid cloud setups, Kubernetes is a powerful tool. However, its complexity may not be suitable for every use case, and alternatives like Docker Swarm, Nomad, or managed services like AWS ECS might be better suited for specific needs. Understanding Kubernetes and its alternatives helps organizations choose the right solution for their infrastructure.

Recommended Training: Certified Kubernetes Administrator (CKA) with Practice Tests from Mumshad Mannambeth, KodeKloud Training

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

Need a dependable Linux system administrator? I specialize in managing, optimizing, and securing Linux servers to keep your operations running flawlessly. Check out my services on Fiverr!


FAQs

1. What are the prerequisites for installing Kubernetes on Ubuntu Server 18?
You need a minimum of 2GB RAM, a multi-core CPU, swap disabled, and Docker or another container runtime installed.

2. Do I need multiple nodes to install Kubernetes?
No, you can set up a single-node cluster for testing, but for production, a multi-node setup is recommended.

3. Which tool is used to install Kubernetes on Ubuntu Server 18?
You can use kubeadm for manual installation or MicroK8s for a lightweight deployment.

4. How do I verify that Kubernetes is installed correctly?
You can check the cluster status using Kubernetes commands and ensure all nodes are running.

5. Is Kubernetes on Ubuntu Server 18 suitable for production use?
Yes, but it requires proper configuration, security hardening, and monitoring to be production-ready.


Exit mobile version