Explore Courses
course iconScrum AllianceCertified ScrumMaster (CSM) Certification
  • 16 Hours
Best seller
course iconScrum AllianceCertified Scrum Product Owner (CSPO) Certification
  • 16 Hours
Best seller
course iconScaled AgileLeading SAFe 6.0 Certification
  • 16 Hours
Trending
course iconScrum.orgProfessional Scrum Master (PSM) Certification
  • 16 Hours
course iconScaled AgileSAFe 6.0 Scrum Master (SSM) Certification
  • 16 Hours
course iconScaled Agile, Inc.Implementing SAFe 6.0 (SPC) Certification
  • 32 Hours
Recommended
course iconScaled Agile, Inc.SAFe 6.0 Release Train Engineer (RTE) Certification
  • 24 Hours
course iconScaled Agile, Inc.SAFe® 6.0 Product Owner/Product Manager (POPM)
  • 16 Hours
Trending
course iconKanban UniversityKMP I: Kanban System Design Course
  • 16 Hours
course iconIC AgileICP Agile Certified Coaching (ICP-ACC)
  • 24 Hours
course iconScrum.orgProfessional Scrum Product Owner I (PSPO I) Training
  • 16 Hours
course iconAgile Management Master's Program
  • 32 Hours
Trending
course iconAgile Excellence Master's Program
  • 32 Hours
Agile and ScrumScrum MasterProduct OwnerSAFe AgilistAgile CoachFull Stack Developer BootcampData Science BootcampCloud Masters BootcampReactNode JsKubernetesCertified Ethical HackingAWS Solutions Artchitct AssociateAzure Data Engineercourse iconPMIProject Management Professional (PMP) Certification
  • 36 Hours
Best seller
course iconAxelosPRINCE2 Foundation & Practitioner Certificationn
  • 32 Hours
course iconAxelosPRINCE2 Foundation Certification
  • 16 Hours
course iconAxelosPRINCE2 Practitioner Certification
  • 16 Hours
Change ManagementProject Management TechniquesCertified Associate in Project Management (CAPM) CertificationOracle Primavera P6 CertificationMicrosoft Projectcourse iconJob OrientedProject Management Master's Program
  • 45 Hours
Trending
course iconProject Management Master's Program
  • 45 Hours
Trending
PRINCE2 Practitioner CoursePRINCE2 Foundation CoursePMP® Exam PrepProject ManagerProgram Management ProfessionalPortfolio Management Professionalcourse iconAWSAWS Certified Solutions Architect - Associate
  • 32 Hours
Best seller
course iconAWSAWS Cloud Practitioner Certification
  • 32 Hours
course iconAWSAWS DevOps Certification
  • 24 Hours
course iconMicrosoftAzure Fundamentals Certification
  • 16 Hours
course iconMicrosoftAzure Administrator Certification
  • 24 Hours
Best seller
course iconMicrosoftAzure Data Engineer Certification
  • 45 Hours
Recommended
course iconMicrosoftAzure Solution Architect Certification
  • 32 Hours
course iconMicrosoftAzure Devops Certification
  • 40 Hours
course iconAWSSystems Operations on AWS Certification Training
  • 24 Hours
course iconAWSArchitecting on AWS
  • 32 Hours
course iconAWSDeveloping on AWS
  • 24 Hours
course iconJob OrientedAWS Cloud Architect Masters Program
  • 48 Hours
New
course iconCareer KickstarterCloud Engineer Bootcamp
  • 100 Hours
Trending
Cloud EngineerCloud ArchitectAWS Certified Developer Associate - Complete GuideAWS Certified DevOps EngineerAWS Certified Solutions Architect AssociateMicrosoft Certified Azure Data Engineer AssociateMicrosoft Azure Administrator (AZ-104) CourseAWS Certified SysOps Administrator AssociateMicrosoft Certified Azure Developer AssociateAWS Certified Cloud Practitionercourse iconAxelosITIL 4 Foundation Certification
  • 16 Hours
Best seller
course iconAxelosITIL Practitioner Certification
  • 16 Hours
course iconPeopleCertISO 14001 Foundation Certification
  • 16 Hours
course iconPeopleCertISO 20000 Certification
  • 16 Hours
course iconPeopleCertISO 27000 Foundation Certification
  • 24 Hours
course iconAxelosITIL 4 Specialist: Create, Deliver and Support Training
  • 24 Hours
course iconAxelosITIL 4 Specialist: Drive Stakeholder Value Training
  • 24 Hours
course iconAxelosITIL 4 Strategist Direct, Plan and Improve Training
  • 16 Hours
ITIL 4 Specialist: Create, Deliver and Support ExamITIL 4 Specialist: Drive Stakeholder Value (DSV) CourseITIL 4 Strategist: Direct, Plan, and ImproveITIL 4 Foundationcourse iconJob OrientedData Science Bootcamp
  • 6 Months
Trending
course iconJob OrientedData Engineer Bootcamp
  • 289 Hours
course iconJob OrientedData Analyst Bootcamp
  • 6 Months
course iconJob OrientedAI Engineer Bootcamp
  • 288 Hours
New
Data Science with PythonMachine Learning with PythonData Science with RMachine Learning with RPython for Data ScienceDeep Learning Certification TrainingNatural Language Processing (NLP)TensorflowSQL For Data Analyticscourse iconIIIT BangaloreExecutive PG Program in Data Science from IIIT-Bangalore
  • 12 Months
course iconMaryland UniversityExecutive PG Program in DS & ML
  • 12 Months
course iconMaryland UniversityCertificate Program in DS and BA
  • 31 Weeks
course iconIIIT BangaloreAdvanced Certificate Program in Data Science
  • 8+ Months
course iconLiverpool John Moores UniversityMaster of Science in ML and AI
  • 750+ Hours
course iconIIIT BangaloreExecutive PGP in ML and AI
  • 600+ Hours
Data ScientistData AnalystData EngineerAI EngineerData Analysis Using ExcelDeep Learning with Keras and TensorFlowDeployment of Machine Learning ModelsFundamentals of Reinforcement LearningIntroduction to Cutting-Edge AI with TransformersMachine Learning with PythonMaster Python: Advance Data Analysis with PythonMaths and Stats FoundationNatural Language Processing (NLP) with PythonPython for Data ScienceSQL for Data Analytics CoursesAI Advanced: Computer Vision for AI ProfessionalsMaster Applied Machine LearningMaster Time Series Forecasting Using Pythoncourse iconDevOps InstituteDevOps Foundation Certification
  • 16 Hours
Best seller
course iconCNCFCertified Kubernetes Administrator
  • 32 Hours
New
course iconDevops InstituteDevops Leader
  • 16 Hours
KubernetesDocker with KubernetesDockerJenkinsOpenstackAnsibleChefPuppetDevOps EngineerDevOps ExpertCI/CD with Jenkins XDevOps Using JenkinsCI-CD and DevOpsDocker & KubernetesDevOps Fundamentals Crash CourseMicrosoft Certified DevOps Engineer ExperteAnsible for Beginners: The Complete Crash CourseContainer Orchestration Using KubernetesContainerization Using DockerMaster Infrastructure Provisioning with Terraformcourse iconTableau Certification
  • 24 Hours
Recommended
course iconData Visualisation with Tableau Certification
  • 24 Hours
course iconMicrosoftMicrosoft Power BI Certification
  • 24 Hours
Best seller
course iconTIBCO Spotfire Training
  • 36 Hours
course iconData Visualization with QlikView Certification
  • 30 Hours
course iconSisense BI Certification
  • 16 Hours
Data Visualization Using Tableau TrainingData Analysis Using Excelcourse iconEC-CouncilCertified Ethical Hacker (CEH v12) Certification
  • 40 Hours
course iconISACACertified Information Systems Auditor (CISA) Certification
  • 22 Hours
course iconISACACertified Information Security Manager (CISM) Certification
  • 40 Hours
course icon(ISC)²Certified Information Systems Security Professional (CISSP)
  • 40 Hours
course icon(ISC)²Certified Cloud Security Professional (CCSP) Certification
  • 40 Hours
course iconCertified Information Privacy Professional - Europe (CIPP-E) Certification
  • 16 Hours
course iconISACACOBIT5 Foundation
  • 16 Hours
course iconPayment Card Industry Security Standards (PCI-DSS) Certification
  • 16 Hours
course iconIntroduction to Forensic
  • 40 Hours
course iconPurdue UniversityCybersecurity Certificate Program
  • 8 Months
CISSPcourse iconCareer KickstarterFull-Stack Developer Bootcamp
  • 6 Months
Best seller
course iconJob OrientedUI/UX Design Bootcamp
  • 3 Months
Best seller
course iconEnterprise RecommendedJava Full Stack Developer Bootcamp
  • 6 Months
course iconCareer KickstarterFront-End Development Bootcamp
  • 490+ Hours
course iconCareer AcceleratorBackend Development Bootcamp (Node JS)
  • 4 Months
ReactNode JSAngularJavascriptPHP and MySQLcourse iconPurdue UniversityCloud Back-End Development Certificate Program
  • 8 Months
course iconPurdue UniversityFull Stack Development Certificate Program
  • 9 Months
course iconIIIT BangaloreExecutive Post Graduate Program in Software Development - Specialisation in FSD
  • 13 Months
Angular TrainingBasics of Spring Core and MVCFront-End Development BootcampReact JS TrainingSpring Boot and Spring CloudMongoDB Developer Coursecourse iconBlockchain Professional Certification
  • 40 Hours
course iconBlockchain Solutions Architect Certification
  • 32 Hours
course iconBlockchain Security Engineer Certification
  • 32 Hours
course iconBlockchain Quality Engineer Certification
  • 24 Hours
course iconBlockchain 101 Certification
  • 5+ Hours
NFT Essentials 101: A Beginner's GuideIntroduction to DeFiPython CertificationAdvanced Python CourseR Programming LanguageAdvanced R CourseJavaJava Deep DiveScalaAdvanced ScalaC# TrainingMicrosoft .Net Frameworkcourse iconSalary Hike GuaranteedSoftware Engineer Interview Prep
  • 3 Months
Data Structures and Algorithms with JavaScriptData Structures and Algorithms with Java: The Practical GuideLinux Essentials for Developers: The Complete MasterclassMaster Git and GitHubMaster Java Programming LanguageProgramming Essentials for BeginnersComplete Python Programming CourseSoftware Engineering Fundamentals and Lifecycle (SEFLC) CourseTest-Driven Development for Java ProgrammersTypeScript: Beginner to Advanced

How To Install Kubernetes on Ubuntu [Step-By-Step Guide]

Updated on 27 May, 2021

12.34K+ views
7 min read

Kubernetes is a free and open-source container management framework providing a forum for automated deployment, scaling, and container operations across host clusters. You can use your hybrid, local and public cloud infrastructure free of charge with Kubernetes to operate your organisation's deployment tasks.

In this tutorial, we will illustrate the installation of Kubernetes in Ubuntu and deploy Kubernetes in a two-node Ubuntu cluster. Meanwhile, read about how to Install Jenkins on Ubuntu.

Kubernetes (or, as is informally known, the K8s) is an open-source system which is used for containerized systems automation, scaling and management. Some of the advantages of Kubernetes include:

  • Automatic installation and machine rollback:  Kubernetes updates an interface progressively and monitors its health to ensure that all instances are not destroyed simultaneously. If something goes wrong, Kubernetes will reverse changes for us.
  • Load balancing and service exploration: The Pods can be loaded by Kubernetes and can distribute IP addresses and DNS names for the collection of Pods.
  • Repository orchestration: Users can install local or cloud storage systems automatically.
  • Container automatic packaging: Kubernetes distributes containers automatically according to their resource specifications and other restrictions. The greater the allocation of the container and its resources, the better the device efficiency.
  • Use of Kubernetes packages: Kubernetes can handle your package configurations, in addition to its services.
  • Self-recovery: Kubernetes tracks the container situation and can substitute it with new containers if anything goes wrong. Containers are also recreated that are already destroyed.
  • Kubeadm: automates Kubernetes installation and setup, including the API, Controller Manager and Kube DNS server.

What is Kubeadm?

Kubeadm automates Kubernetes components including API servers, Controller Manager and Kube DNS installation and setup. However, it does not build users or manage the installation and configuration of operating system dependencies.

A configuration management tool like Ansible or SaltStack can be used for these preliminary tasks. The use of these tools makes it much easier and more feasible to create new clusters or to recreate existing clusters.

Prerequisites:

  • Hardware Requirement:

    • For Master: 
      • RAM: 2 GB 
      • CPU: 2 Cores
    • For Slave: 
      • RAM: 1 GB
      • CPU: 1 Core 
  • Software Requirement:

    • 2 or more Ubuntu 18.04 servers 
    • Access to a sudo or root privileged user account on each device 
    • The apt package manager. 

Swap disabled. You MUST disable swap in order for the kubernetes to work properly.

The commands and procedures specified in this article were executed on an Ubuntu 18.04 LTS framework. You can open all commands through either the Dash, or the Ctrl+Alt+T shortcut, as we will use the Ubuntu command line, the Terminal. 

The two-node cluster will consist of a Master Node and Slave Node. These two nodes must be installed with Kubernetes.

Master Node: The master Node is responsible for the administration of the cluster state (a node in Kubernetes refers to a server). 

Slave Node: The servers on which your workloads (i.e., container applications and services) are running are worker nodes or slave nodes. When delegated, the workload is continued by a worker even though the master falls when the schedule is complete. By adding workers, the capacity of a cluster can be increased. 

Follow the steps below to install Kubernetes on the two nodes in Ubuntu. 

Installation Procedure:

Step 1: Installing Docker

On both master and slave nodes, the following must be performed.

1. Docker's installation is the first thing to do. Login into the server to do this and export the command:

$ sudo apt-get install docker.io 

In order to continue the installation, you will be asked to choose a Y/N option. Please enter Y to continue, then press Enter and your machine will be configured with Docker.

2. The installation can also be checked by using the following instruction, and the Docker version number:

$ docker --version 

You must add your user to the docker community once Docker is installed (otherwise you must carry out all the sudo docker commands which could lead to security problems).

3. Use the command to connect your user to the docker group:

$ sudo usermod -aG docker $USER 

Log out and log in, so that adjustments come into effect.

4. Launch and activate the docker daemon with the commands:

$ sudo systemctl start docker 
$ sudo systemctl enable docker 

Step 2: Installing Kubernetes 

Now, install Kubernetes on both the machines. As Kubernetes is downloaded from a non-standard repository, it is essential for the software to be authentic. This is achieved with the addition of a signing key.

1. Add the GPG Kubernetes key with the command:

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

2. If curl is not installed on your system, then you can install it with the commands:

$ sudo apt install curl 

In order to continue the installation, you will be asked to choose a Y/N option. Please enter Y, then press Enter. You will then install the Curl utility on your device.

3. Sometimes Kubernetes is not added in default repository. To add the Xenial Kubernetes repository, run the following command on both nodes:

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

4. Installing Kubeadm (Kubernetes Admin) on both nodes by command is the final stage of the installation process:

$ sudo apt-get install kubeadm kubelet kubectl 

Run the below command to check whether the versions of the components installed are compatible with each other

sudo apt-mark hold kubeadm kubelet kubectl

In order to continue the installation, you will be asked to choose a Y/N option. Please enter Y to continue, then press Enter. Kubeadm will then be installed on your device.

5. You can also check Kubeadm's version number and verify the installation using the following command:

$ kubeadm version

Repeat for each server node.

Ensure that on each computer you install the same package version. Instability can arise from various versions. This mechanism also prevents Kubernetes from being updated automatically.

Step 3: Running and Deploying Kubernetes

1. Disable swap memory:

You can deactivate the swap memory in both nodes because Kubernetes does not work properly on a swap-based device. Run the following command to disable swap memory on both nodes:

$ sudo swapoff -a 

2. Unique hostnames to each node:

In order to facilitate things, each server needs to be assigned a specific hostname.

  • To assign it a unique hostname, run the following command in the master node:
$ sudo hostnamectl set-hostname master-node 
  • To assign it a unique hostname, run the following command in the slave node:
  $ sudo hostnamectl set-hostname slave-node

In case of additional worker nodes, use the command to set a unique hostname on each.

3. Initialize Kubernetes on Master Node:

Switch to the master server node and type:

 $ sudo kubeadm init –pod-network-cidr=192.168.43.211/24  

You can find pod network CIDR in /etc/kubernetes/manifests/kube-controller-manager.yaml

sudo grep cidr /etc/kubernetes/manifests/kube-*

Upon completion of the command, a kubeadm join message is displayed at the end. Depending on your Internet connection, the process can take a minute or more. Make a note of the entire entry. This is used for joining the cluster's nodes.

  • You need to run the following as a daily user to start using your cluster:
$ mkdir  -p $HOME/ .kube 
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config 
 $sudo chown $(id -u):$(id -g) $HOME/.kube/config 
  • By running the following command, you can check the status of the master node:
$ kubectl get nodes 

4. Deploy Pod Network to Cluster:

A pod network is a communication medium between network nodes.

  • This article uses the following command to deploy a Flannel pod network in our cluster:
$ sudo kubectl apply -f  https://raw.githubusercontent.com/coreos/  flannel/master/Documentation/kube-flannel.yml 
  • To display the network status, use the following command:
$ kubectl get pods --all-namespaces

5. Add the slave node to form a cluster:

you can enter the kubeadm join command on each slave node to connect it to the cluster.

  • Run the command that you created when you initialized Kubernetes on your master node at the slave node:
$ sudo kubeadm join 192.168.100.6:6443 --token        06tl4c.oqn35jzecidg0r0m --discovery-token-ca-cert-hash                            sha256:c40f5fa0aba6ba311efcdb0e8cb637ae0eb8ce27b7a03d47be6d966142f2204c
  • So now you run the command on the master node, it confirms that your device has two nodes, the Master node and Server nodes.
$ sudo kubectl get nodes 

This shows that the two-node cluster now operates via the container management system in Kubernetes.

4) Uninstalling Kubernetes

1. Clear Pods

Using this command, you can delete all the nodes:

$ kubectl delete node --all 

2. Remove  kubeadm completely

$ sudo apt-get purge kubeadm kubectl kubelet kubernetes-cni kube* 
$ sudo apt-get autoremove

Learn more about the core concepts of Kubernetes Components, Architecture, Pods and Deployment with Kubernetes Training Course

Conclusion: 

You should now have Kubernetes installed on Ubuntu, after following carefully the steps stated in this article. 

This network uses many servers for back-and-forth communication. You can launch and manage Docker containers on several servers on the pod from Kubernetes. 

The Kubernetes container management system installed on two Ubuntu nodes was discussed in this post. We then developed and deployed Kubernetes to a single two-node cluster. This clustered network is now available for use,and you can use any service like a Nginx server or Apache container.