How to Install Kubernetes on Ubuntu - Table of Content
- What is Kubernetes
- How to install Kubernetes on Ubuntu
- How to install Kubernetes on Ubuntu using MicroK8s
- How to install Kubernetes on Ubuntu using Docker
- Conclusion
What is Kubernetes
Kubernetes is an open-source tool that uses containers to make applications portable and easy to deploy. It provides good decisions about cluster management and how they can react to the cluster events.
It makes the integration easier with other services, making it easier to monitor applications and provide all the logging services. It works well with other DevOps practices like continuous integration and continuous delivery, making implementing agile practices in a software team easier. Other benefits of using Kubernetes include scaling your applications, reducing production costs by managing the resources, and using auto scaling to meet your needs.
Most of the developers use Docker to create the images. That's why most of the time, Kubernetes works well with Docker. Making containerized applications goes through provisioning, scaling, balancing, networking, and deployment. Kubernetes changed the deployment lifecycle and saved many companies the pains they were going through during the development processes.
Become a Kubernetes Certified professional by learning this Kubernetes Training !
How to install Kubernetes on Ubuntu
Prerequisites
- You should have servers running Ubuntu
- Ensure that you meet the 2GB of RAM and 2 CPUs.
- Install Docker for method 2.
- Be conversant with the sudo commands.
Kubernetes Certification Training
- Master Your Craft
- Lifetime LMS & Faculty Access
- 24/7 online expert support
- Real-world & Project Based Learning
How to install Kubernetes on Ubuntu using MicroK8s
Using MicroK8s gives you the ability to install Kubernetes using one node. They are lightweight and only use single commands to install all the required dependencies and services, and work well with IoT and edge applications.
To install Kubernetes using this method, you have to follow the following steps:
1. First, let us install the MicroK8s on the machine by using the following command
sudo snap install micro k8s --classic
2. Create admin privileges and add users
sudo usermod -a -G microk8s $USER
sudo chown -f -R $USER ~/.kube
3. Update the sessions of the user
su - $USER
4. Confirm the status of the Kubernetes after starting it
micro k8s status --wait-ready
5. Turn on several services you may use by typing the following command
micro k8s enable dashboard dns ingress
6. To get access to all the resources and features, you can type
micro k8s enable --help
7. You can stop all the services using the following command
micro k8s disable ‹name›
8. Now, you can use Kubernetes by typing the following
micro k8s kubectl get all --all-namespaces
9. Start and access its dashboard by typing
micro k8s dashboard-proxy
How to install Kubernetes on Ubuntu using Docker
1. Installing docker
In this step, we are going to install Docker. If you already have it installed, you can go to the next step. First, we have to ensure we have an updated package list. Type the following command
sudo apt-get update
Let us now install Docker after the update. Install on both the servers you use.
sudo apt-get install docker.io
Confirm the Docker version by typing the following
docker ––version
2. Launching and enabling the Docker
Launch the Docker by typing the following command
sudo systemctl enable docker
Ensure that the Docker is running after the launch
sudo systemctl status docker
If it has not started running, type the following command
sudo systemctl start docker
Repeat the above commands on the different nodes of the server
3. Installing the Kubernetes
Let us now install Kubernetes, and we have to ensure we are using the right software by assigning keys. To assign keys, we use the following command:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
Most people get errors that curl is not yet installed on their PC. To install curl, we use the following command.
sudo apt-get install curl
Ensure that all the nodes on each software have installed keys.
Subscribe to our YouTube channel to get new updates..!
4. Add the Kubernetes software
When installing Kubernetes, most of them don't add themselves into the software repositories, and you have to do it manually.
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
Ensure you add repositories for all the nodes.
5. Installation of Kubernetes tools
There are several Kubernetes tools like Kubeadm (Kubernetes Admin) that help in the administration and ensure that developers follow the correct procedures when building clusters. One of the common tools is Kubelet which helps run and start nodes and containers through the command line.
First, let us install the tools. It tekes a few minutes to complete, and try to be patient
sudo apt-get install kubeadm kubelet kubectl
sudo apt-mark hold kubeadm kubelet kubectl
Confirm if the installation is successful by typing the following
kubeadm version
Repeat the processes for all the nodes.
6. Performing the Kubernetes deployment
We have to disable the swap memories of the servers of the project. It helps in preventing Kubernetes from throwing any bad errors along the way.
sudo swapoff –a
Now, assign and give each server node a unique hostname by typing the following command. You have to understand which server you will use as the master node.
sudo hostnamectl set-hostname master-node
Change the hostname using the following command
sudo hostnamectl set-hostname host1.
7. Let us initialize the Kubernetes on the master nodes
Ensure that you are on the master server node and type this command
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
Be keen to check the last entry of the command after processing and copy the entry that appears with a message at the end after kubeadm join. It will be helpful when you want to join the working nodes to the cluster.
Now create the directories for your clusters
- kubernetes-master:~$ mkdir -p $HOME/.kube
- kubernetes-master:~$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
- kubernetes-master:~$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
8.Deploying the pods network to clusters
Pod networks help in communication between different nodes in a cluster. Most of them use flannel networks. Type the following command and wait for a few minutes.
sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Ensure everything is working perfectly by typing the following command:
kubectl get pods --all-namespaces
Top 30 frequently asked Kubernetes Interview Questions!
9. Join the nodes to the clusters
Type the following command to join the nodes
kubeadm join --discovery-token abcdef.67574466464abcdef --discovery-token-ca-cert-hash sha256:1234..cdef 1.8.3.4:5543
Ensure the numbers in the command match the numbers of your server. Do that for all the nodes and give it a few minutes.
Confirm the status of the nodes and then go to the master server and type the following command
kubectl get nodes
It will give you a list of all the nodes connected to the clusters.
Conclusion
We have seen two ways to install Kubernetes on Ubuntu. The process is a bit long, and you have to follow the steps keenly to avoid missing some crucial steps. Working with Docker makes the process easier. Kubernetes provides documentation for those who may face issues during installation. After installing Kubernetes, you can use it to install different applications using less time and to automate the whole process. The whole setup makes the deployment of containerized applications successful.
Related Articles:
About Author
As a senior Technical Content Writer for HKR Trainings, Gayathri has a good comprehension of the present technical innovations, which incorporates perspectives like Business Intelligence and Analytics. She conveys advanced technical ideas precisely and vividly, as conceivable to the target group, guaranteeing that the content is available to clients. She writes qualitative content in the field of Data Warehousing & ETL, Big Data Analytics, and ERP Tools. Connect me on LinkedIn.
Upcoming Kubernetes Certification Training Online classes
Batch starts on 21st Nov 2024 |
|
||
Batch starts on 25th Nov 2024 |
|
||
Batch starts on 29th Nov 2024 |
|
FAQ's
Yes, you can run Kubernetes on Ubuntu by installing the kubernetes on both virtual and physical machines.
Yes, you can install kubernetes on linux.
Docker uses kubernetes and the Kubernetes server runs within Docker; it is used for local testing only
Yes, Docker can run without Kubernetes but you need some other kind of container runtime.