One of the easiest and cost-effective ways to get started with Kubernetes is using the Minikube. It will help you practice and gain familiarity with Kubernetes’ basic concepts. Minikube is a free and open-source virtual machine-based tool used for implementing the Kubernetes cluster.
Minikube provides a command-line-based interface that allows you to manage cluster operations i.e starting, stopping, and deleting nodes from the Cluster. Minikube also allows one to perform demo operations before having full Kubernetes installed which is time-consuming.
Features of Minikube are:
- Ingress- API with rules that dictates access to services in a cluster.
- Container Runtime: such as Docker, and rkt
- ConfigMaps and Secrets
- NodePorts and DNS
- Enabling CNI (Container Network Interface)
- It supports persistent volumes.
- Dashboards –a Web interface for management and monitoring.
- LoadBalancer – Scaling up applications to improve performance.
In this guide, we will walk through how to run Kubernetes on Debian 11 with Minikube. This is achieved using hypervisors such as KVM, VirtualBox e.t.c. In this guide, we are going to install Minikube Virtual Machine using KVM hypervisor.
Step 1: Install KVM / VirtualBox Hypervisor on Debian 11
You have an option of using either:
- VirtualBox hypervisor
- KVM hypervisor
From a performance perspective KVM is a winner and is highly recommended. We have guides on installing either on Debian system:
Nested Virtualization in VirtualBox
If you want to run minikube in a Virtual Machine on VirtualBox you may have to enable Nested virtualization.
vboxmanage list vms
VBoxManage modifyvm "Debian 11" --nested-hw-virt on
Validate KVM installation
On KVM verify that all the required modules are loaded – This confirms the system has support for virtualization.
$ lsmod | grep kvm
kvm_intel 327680 0
kvm 917504 1 kvm_intel
irqbypass 16384 1 kvm
Also validate that libvirt reports no errors:
$ virt-host-validate
Check the status of the service as below:
$ systemctl status libvirtd
● libvirtd.service - Virtualization daemon
Loaded: loaded (/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-08-30 16:11:18 EAT; 2min 29s ago
TriggeredBy: ● libvirtd.socket
● libvirtd-admin.socket
● libvirtd-ro.socket
Docs: man:libvirtd(8)
https://libvirt.org
Main PID: 48543 (libvirtd)
Tasks: 19 (limit: 32768)
Memory: 13.4M
CPU: 164ms
CGroup: /system.slice/libvirtd.service
└─48543 /usr/sbin/libvirtd
Aug 30 16:11:18 debian systemd[1]: Started Virtualization daemon.
Aug 30 16:11:19 debian dnsmasq[23444]: started, version 2.80 cachesize 150
Aug 30 16:11:19 debian dnsmasq[23444]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth nettlehash DN>
Aug 30 16:11:19 debian dnsmasq-dhcp[23444]: DHCP, IP range 192.168.122.2 -- 192.168.122.254, lease time 1h
Aug 30 16:11:19 debian dnsmasq-dhcp[23444]: DHCP, sockets bound exclusively to interface virbr0
Aug 30 16:11:19 debian dnsmasq[23444]: reading /etc/resolv.conf
Aug 30 16:11:19 debian dnsmasq[23444]: using nameserver 127.0.0.53#53
Aug 30 16:11:19 debian dnsmasq[23444]: read /etc/hosts - 7 addresses
.........................
Step 2: Install snapd on Debian 11 System
In the installation of Minikube, we will need a snap command, so we install snapd as below:
sudo apt install snapd
Now create a symbolic link between “/var/lib/snapd/snap” and “/snap”
sudo ln -s /var/lib/snapd/snap /snap
echo 'export PATH=$PATH:/var/lib/snapd/snap/bin' | sudo tee -a /etc/profile.d/snap.sh
Start and enable snapd communication socket as below
sudo systemctl enable --now snapd.service snapd.socket
Step 3: Install Kubectl tool on Debian 11.
This is a command-line tool that allows one to execute commands to the Kubernetes cluster. You can deploy and manage cluster resources with ease. Install kubectl on Debian 11 using the cURL command as below.
$ sudo snap install kubectl --classic
2021-08-24T18:39:53+03:00 INFO Waiting for automatic snapd restart...
kubectl 1.21.4 from Canonical✓ installed
Verify the installation by checking the installed kubectl version.
$ kubectl version -o yaml
clientVersion:
buildDate: "2021-08-19T15:45:37Z"
compiler: gc
gitCommit: 632ed300f2c34f6d6d15ca4cef3d3c7073412212
gitTreeState: clean
gitVersion: v1.22.1
goVersion: go1.16.7
major: "1"
minor: "22"sudo systemctl status libvirtd
platform: linux/amd64
The connection to the server localhost:8080 was refused - did you specify the right host or port?
Step 4: Install Minikube on Debian 11 – KVM / VirtualBox
With KVM hypervisor already installed, you are in a position to install Minikube on your Debian 11 system.
But first, download Minikube using the wget command as below:
sudo apt update && sudo apt install wget
wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 -O minikube
install docker drivers used by Minikube.
wget https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2
Change permission for the two binary files and copy them to /usr/local/bin/ path as below :
sudo chmod 755 minikube docker-machine-driver-kvm2
sudo cp minikube docker-machine-driver-kvm2 /usr/local/bin/
Make the file executable by issuing the command:
sudo chmod +x /usr/local/bin/minikube
With the above command, Minikube has been successfully installed on your Debian 11 machine. Now proceed and check the version of Minikube installed.
$ sudo minikube version
minikube version: v1.22.0
commit: a03fbcf166e6f74ef224d4a63be4277d017bb62e
When running the Minikube command, it is always good not to be prompted for the root password. This is avoided by running Minikube as a non-root user by adding a user to the libvirt group as below.
sudo usermod -aG libvirt $USER
Step 5: Run Kubernetes on Debian 11 using Minikube
Start Minikube on Debian 11 using the command:
# With VirtualBox Driver
$ minikube start --driver=virtualbox
# With KVM2 Driver
$ minikube start --driver=kvm2
Check official guide on VirtualBox specific features and KVM features of Minikube.
Sample Output:
😄 minikube v1.22.0 on Debian 11.0 (kvm/amd64)
✨ Using the kvm2 driver based on user configuration
💿 Downloading VM boot image ...
> minikube-v1.22.0.iso.sha256: 65 B / 65 B [-------------] 100.00% ? p/s 0s
> minikube-v1.22.0.iso: 242.95 MiB / 242.95 MiB 100.00% 2.29 MiB p/s 1m46s
👍 Starting control plane node minikube in cluster minikube
💾 Downloading Kubernetes v1.21.2 preload ...
> preloaded-images-k8s-v11-v1...: 502.14 MiB / 502.14 MiB 100.00% 2.22 MiB
🔥 Creating virtualbox VM (CPUs=2, Memory=2900MB, Disk=20000MB) ...
🐳 Preparing Kubernetes v1.21.2 on Docker 20.10.6 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔎 Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟 Enabled addons: default-storageclass, storage-provisioner
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
From the above output, the command selects the KVM driver, downloads the virtual machine boot image, and creates a Kubernetes cluster with a single node.
Check the status of Minikube:
$ minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
Check the docker environment in the cluster using the command:
$ minikube docker-env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/home/thor/.minikube/certs"
export MINIKUBE_ACTIVE_DOCKERD="minikube"
# To point your shell to minikube's docker-daemon, run:
# eval $(minikube -p minikube docker-env)
Access the Minikube command-line via SSH using the command below.
minikube ssh
Sample Output:
Setting default driver
You can as well set the default driver for Minikube Virtual Machine
# VirtualBox
minikube config set driver virtualbox
# KVM
minikube config set driver kvm2
Step 6: Create Pods in Minikube.
We now create and run pods in Kubernetes using the kubectl command. Here we will create our first pod as below.
$ kubectl create deployment webserver --image=nginx
deployment.apps/webserver created
This deployment process takes about 30 sec to be initiated. Check your running pod using:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
webserver-559b886555-dsgg2 0/1 ContainerCreating 0 13s
Step 7: Deploy Services in Minikube.
First, we need to have our service accessed from the outside. This is done by exposing a port on which the service is running. In this case, we will expose port 80 for our web server.
$ kubectl expose deployment webserver --type="NodePort" --port 80
service/webserver exposed
Then get the IP on which the service is running using the below command:
$ kubectl get service webserver
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
webserver NodePort 10.100.217.103 <none> 80:32106/TCP 37m
To display the environment of this application issue the below command with webserver-559b886555-dsgg2 as the name of the pod
$ kubectl exec webserver-559b886555-dsgg2 -- env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=webserver-559b886555-dsgg2
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
NGINX_VERSION=1.21.1
NJS_VERSION=0.6.1
PKG_RELEASE=1~buster
HOME=/root
Next, we will generate a URL that can be used to access the Nginx service.
$ minikube service webserver --url
http://192.168.99.101:32106
Enter the generated URL on a browser and you should see the below Nginx page.
Scaling applications
Scaling is the act of creating multiple replications of an application when large traffic is generated. This is used in Kubernetes to balance load requests.
Let’s scale our application to 4 replicas as below:
$ kubectl scale deployment webserver --replicas=4
deployment.apps/webserver scaled
To see the scaled applications, run:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
webserver-559b886555-9zl5j 1/1 Running 0 32s
webserver-559b886555-dsgg2 1/1 Running 0 64m
webserver-559b886555-j64b8 1/1 Running 0 32s
webserver-559b886555-kmlvt 1/1 Running 0 32s
Access the Pod Shell
Login into the pod shell is essential when one wants to do configurations such as adding config files. The below command is used to access the pod shell.
kubectl exec -it webserver-559b886555-dsgg2 -- bash
Sample Output:
Check the available directories and files.
root@webserver-559b886555-dsgg2:/# ls
bin docker-entrypoint.d home media proc sbin tmp
boot docker-entrypoint.sh lib mnt root srv usr
dev etc lib64 opt run sys var
Step 8: Access Minikube dashboard
While on the Minikube dashboard, you can easily manage your pods and other Kubernetes services. The dashboard is started by running the below command on the host terminal:
$ minikube dashboard
🔌 Enabling dashboard ...
▪ Using image kubernetesui/dashboard:v2.1.0
▪ Using image kubernetesui/metrics-scraper:v1.0.4
🤔 Verifying dashboard health ...
🚀 Launching proxy ...
🤔 Verifying proxy health ...
🎉 Opening http://127.0.0.1:43361/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
[0830/220852.143311:ERROR:file_io_posix.cc(152)] open /home/thor/.config/google-chrome/Crash Reports/pending/e7be5bfb-158d-4f1a-a774-fe852af98cef.lock: File exists (17)
Opening in existing browser session.
[16884:16884:0100/000000.611566:ERROR:sandbox_linux.cc(374)] InitializeSandbox() called with multiple threads in process gpu-process.
The dashboard then automatically loads on your default browser.
Step 9: Manage Pods and services
Terminate/delete running services using the below syntax;
$ kubectl delete services <service-name>
Service “<service-name>” deleted
Sample Output:
Delete a pod with the command:
$ kubectl delete deployment <pod-name>
Deployment.extensions “<pod-name>” deleted
This marks the end of our guide on how to run Kubernetes on Debian 11 with Minikube. Kubernetes is one of the best free and open-source orchestration tools. I hope this guide was significant.
Books For Learning Kubernetes Administration:
See related articles: