In this article, we will see how to install Kubernetes with Minikube, in container virtualization context that we have already talked about it before.
What is Kubernetes?
Thanks to container-based virtualization, it is possible to build single applications as an aggregate of several modules or groups of containers. These can cooperate and are exposed outwards as a separate service.
Let’s think of a simple WordPress image for website development.
So that the related services work properly, you need to use coordination of further modules – such as the MySQL database – that will have to be loaded at specific times in the deploy.
If in this case, the Docker-compose is enough, imagine taking this to maxima to create more complex applications, composed of many more various modules and installed on nodes scattered on the network.
At this point, you will need to use more appropriate orchestration tools.
We are helped by Kubernetes – also known as K8s – an open-source project that manages the process of distribution and control of multi-container applications, working well with Docker, but also with other container systems.
Actually, in K8s, we don’t talk about containers or groups, but pods, each of which represents a single instance of an application and consists of one or more containers.
It basically deals with abstracting resources in order to insert a container inside a cluster, with a single IP address and port.
We cannot really talk about the differences between Kubernetes and Docker since they perform different functions, and both can survive without each other.
It is true, however, that by working together on applications and development, they can become much more powerful and secure.
This is perhaps one of the reasons why Kubernetes, originally developed by Google, is now under the wings of The Linux Foundation, the non-profit organization founded in 2007 to support the development of the Linux kernel and open source applications.
Its strong point in the management of distributed and complex container systems, obviously also increase the difficulty of implementation and use, as well as the attention that developers must pay to security since the nodes that collaborate must be connected securely.
How to use Kubernetes
There is no single method to use Kubernetes, but it is possible to use more than one way.
- You can use one of many distribution packages (not all free), such as Canonical Kubernetes, Pivotal Container Service, Rancher, Red Hat OpenShift or Suse CaaS Platform.
- Some Kubernetes distributions are installed and run in some virtual machine infrastructures like Amazon EC2, Azure Virtual Machines, Google Compute Engine.
- Some of the Linux distributions offer Kubernetes configuration tools; an example for all is Ubuntu, with its conjure-up.
- You can install Minikube to run Kubernetes locally, test and design your own applications.
With Minikube you can run Kubernetes locally as a single node within a virtual machine.
Before installing Minikube, you need to enable hardware resources virtualization in the BIOS, and install sequentially first a hypervisor (VirtualBox or hyperv for Windows) and then kubetcl, the command-line interface to follow commands on the Kubernetes cluster.
Following the official Kubernetes tutorial, you can install Minikube and start testing with deploying applications on a single node.
On a Linux Ubuntu, the steps to do are the following:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_1.6.2.deb \ > && sudo dpkg -i minikube_1.6.2.deb
Start a cluster using the driver of the installed virtual machine as a prerequisite (in our case: VirtualBox).
minikube start --vm-driver=virtualbox
Now, all we have to do is install kubectl with the following command:
sudo snap install kubectl --classic
Once this installation phase is finished, you can start using Kubernetes to interact with the minikube cluster.
For example, you can see the list of active pod states.
kubectl get po -A
Or interact with the cluster by starting a server.
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
Exposing it as a service
kubectl expose deployment hello-minikube --type=NodePort --port=8080
You can now open this service displayed in your browser with the following command:
minikube service hello-minikube
If you then want to stop or delete the cluster the commands to be executed are:
As we could see, Docker and Kubernetes are different solutions, each of which speaks one aspect of virtualization.
But used together in collaboration, they can make the management and implementation of applications more accessible, with essential features such as the speed of deployment, scalability and portability between different infrastructures.
When applications become complex, expanding across multiple distributed containers across multiple hosts or the cloud, Kubernetes can manage the security and management processes required.
In fact, it is possible to organize containers by optimizing the necessary resources distributed on different hosts, automating processes and adding or modifying storage.