
Minikube is an open-source program designed to help developers and system administrators run a single Kubernetes cluster on their own computers. With minimal resource usage, Minikube launches a local single-node Kubernetes cluster. For POC and development tests, this is perfect. This article will show us the driver options and the one that is easiest to use, how to install kubectl and everything we need in order to run a Kubernetes cluster for proof of concept and development test. Other useful articles can be found here: How to Install PlayonLinux on a Linux System and How to install Gradle on Ubuntu and How to Install Apache Subversion on a Linux System also How to install Unison on a Linux System and How to install Rust in a Linux System and How to Install MongoDB on a Linux System
Requirements
Below are the requirements needed to run Minikube
- Ubuntu 18.04 or higher
- A user account with sudo privileges, and
- Command line
Minikube’s features that work with Kubernetes
Below are the Mininikube’s features that work with Kubernetes.
- DNS
- NodePorts
- ConfigMaps and Secrets
- Dashboards
- Container Runtime: Docker, CRI-O, and containerd
- Enabling CNI (Container Network Interface)
- Ingress
- PersistentVolumes of type hostPath
Step1: Update the system the package index & system
The screenshot for each of the processes is shown below
apt update
APT transport allows the use of repositories accessed via the HTTP Secure protocol (HTTPS), also referred to as HTTP over TLS. It is available by default since apt 1.5 and was available before that in the package apt-transport-HTTPS.
Kindly run the following command to install the APT transport.
sudo apt install apt-transport-https
Kindly rn the following command below to upgrade
sudo apt upgrade
After the upgrade, if a reboot is necessary, carry out the procedure.
[ -f /var/run/reboot-required ] && sudo reboot -f
Step 2: Install KVM or Virtualbox driver but preferably Docker
All of the items needed to run KVM on the Ubuntu operating system may be found in the upstream official repository. Use the following commands to install them:
For thevirtualbox driver
, please run the command below
sudo apt install virtualbox virtualbox-ext-pack
To install the kvm driver
, please run the command below.
sudo apt update
sudo apt -y install qemu-kvm libvirt-dev bridge-utils libvirt-daemon-system libvirt-daemon virtinst bridge-utils libosinfo-bin libguestfs-tools virt-top
Load and enable the modulevhost-net
sudo modprobe vhost_net
sudo lsmod | grep vhost
echo "vhost_net" | sudo tee -a /etc/modules
enable libvert services
sudo systemctl start libvirtd
sudo systemctl enable libvirtd
Docker driver
Since we will be running Minikube within a VM it would make sense to have docker installed but if you have enabled virtualization in your bios you can choose not to install it because you can choose to use VirtualBox. Personally, I prefer the option of using docker as the preferred driver because, with docker as a driver, you would not need to modify anything in your bios. So, install docker and use the flag when running minikube — — driver=docker.
Here is an official link to the docker website as to how to properly install docker on your system How to install Docker
After installing docker run the following commands:
systemctl enable docker
systemctl start docker
systemctl status docker
finally, for docker, add your login user to the docker group with the following command:
sudo usermod -aG docker $USER && newgrp docker
sudo usermod -aG docker $USER && newgrp docker
Step 3: Download minikube
Downloading the minikube binary is required. Since the binary is under $PATH, I will place it under the /usr/local/bin directory.
wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
chmod +x minikube-linux-amd64
sudo mv minikube-linux-amd64 /usr/local/bin/minikube
you can check what version has been installed with the command
minikube version
Step 4: Install kubectl on Ubuntu
We require kubectl, a command-line tool for managing and deploying apps on Kubernetes:
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
Set the binaries for kubectl executable.
chmod +x ./kubectl
The binary should now be in your PATH:
sudo mv ./kubectl /usr/local/bin/kubectl
confirm the version with the command:
kubectl version -o json --client
Step 5: Starting minikube
Please note that minikube will not run in the root environment and as such you need to switch to your normal logged-in user session.
You can launch minikube now that the components have been installed. The Kubernetes single node cluster’s VM image will be downloaded and configured. You can do that with the command:
minikube start --driver=docker
From the screenshot above, we can see that minikube created a Kubernetes cluster for us, we can inspect this by using the command:
kubectl get nodes
Next, let’s create a deployment and call the name =techdirectarchive and image= nginx with a tag of latest
kubectl create deployment techdirectarchive --image=nginx:latest
As you can see a new deployment called techdirectarchive was created. But we can officially verify this with the command:
kubectl get deployments
Next, let’s expose the service for our techdirectarchive deployment with the command:
kubectl expose deployment techdirectarchive --type=NodePort --port=8080
We can also get the service using the command below:
Now let’s delete the deployment and also the service
kubectl delete deployment techdirectarchive
kubectl delete service techdirectarchive
We can stop minikube with the command:
minikube stop
How to expose a sample deployment
To expose an application deployed in a container, we will need to create a new deployment that is a Kubernetes object. The first thing to do would be to wake minikube up with the command
minikube start --driver=docker
The name of the deployment will be Redis and the image we shall be using is Redis as well.
As we can see from the image above, deployment was successfully created, We can verify this deployment that we just made by running the command:
kubectl get deployments
Let’s view the deployment’s details with this command:
kubectl describe deployment redis
After running the command below take a look at the essential actions the cluster made to pull and install the new application. Several lines of output should appear. Note that each message’s age is displayed in the first column; however, the LAST SEEN time does not print out chronologically due to JSON’s lack of order.
kubectl get events
Viewing existing items in a usable YAML output is possible. See how redis is currently deployed.
kubectl get deployments redis -o yaml
We can create a service if we want to view more about our newly created redis container but we will have to change the configuration and add a port. So let’s create a deployment file with the command:
vim deploymentfile.yml
Let’s populate the vim file with data by copying data from a similar file in Kubernetes documentation. Here is a link to it. Please note that we replaced wherever there was nginx with redis and added the section for port, and protocol. A sample is shown below:
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
labels:
app: redis
spec:
replicas: 3
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis
ports:
- containerPort: 80
protocol: TCP
Remember the reason why we did this was that we could not run the service successfully because the previous deployment had no port and protocol. So now that we have created a YAML file and indicated it, we will use replace to terminate and create a new deployment.
kubectl replace -f deploymentfile.yml
View the Pod and Deployment. Note the AGE shows the Pod was re-created.
kubectl get deploy,pod
Now let’s try to expose the resource again. This time it should work.
kubectl expose deployment redis
Verify the service configuration
kubectl get svc redis
The Endpoint is provided by kubelet and kube-proxy. Take note of the current endpoint IP
kubectl get ep redis
Let’s get the IP addresses of all running pods another way by using -o wide
kubectl get pod -o wide
We can scale from the current number we have to 6 using the command:
kubectl scale deployment redis --replicas=6
Let’s see if the total number of pods have increased by running
Let’s clean up by deleting our deployment
kubectl delete deployment redis
Summary
This tutorial has demonstrated how to set up Minikube and the Kubernetes command-line tool kubectl on Ubuntu Linux Machine, the commands should work for any version from 18 and above. In the article, we set up a local Kubernetes cluster with Minikube using the Docker driver on Ubuntu 22.04 LTS.
Additionally, we created a service and a deployment for you to use on your computer to demonstrate the fundamentals of utilizing Kubernetes. You should be able to use Kubernetes and Minikube now.