Minikube is a lightweight Kubernetes implementation that creates a VM on your local machine and deploys a simple cluster containing only one node.
I have been developing a Container Host using a Photon OS VM to conduct tests with Grafana, Prometheus, and metrics sourced from Harbor. Currently, I am applying this expertise to establish a Minikube Host on the same operating system, serving as the groundwork for diverse deployments within my Kubernetes cluster (Minikube).
- Introduction
- Goals and Objectives
- Method
- Target Audience
- Document Status
- Disclaimer
- Scope and Limitations
- Environment
- Acknowledgments
- References
- Conclusion
- Making the Minikube Host
- Interacting with the cluster
- Enabling port forwarding
- Clean up and stop Minikube
- Minikube and multi node clusters
- Next - Hello Minikube
Kubernetes is a portable, extensible, open source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. Minikube can be the ideal learning platform when delivering Kubernetes training. The Photon OS is a Linux based, open source, security-hardened, enterprise grade appliance operating system that is purpose built for Cloud and Edge applications.
I thought that the combination of a Virtual Machine created with Photon OS and Minikube installed would be the perfect lab environment for my journey in learning Kubernetes. The benefit of setting up a VM with all necessary lab components is the ability to easily prepare and store it as a template or OVA file. This streamlines the process of creating VMs for future use. After completing the lab, the VM can be deleted, ready to be recreated when needed again.
Create a Minikube Host VM based on Photon OS. The VM should be equipped with all the necessary tools to interact with Kubernetes clusters (Minikube) and should be easily reproducible as needed. Document all the required steps and instructions thoroughly.
I begin by downloading a OVA-file for Photon OS. I utilize this file to create a VM with the estimated resource configuration required for my labs. Subsequently, I prepare the VM by installing Minikube, Kubectl, Helm, and other tools essential for practical Kubernetes training and learning. The VM will also be saved as a OVA file for easely be used to speen of new VMs. The VM will also be saved as an OVA file for easy duplication and rapid provisioning of new VMs.
This guide is designed for individuals seeking to explore and gain insights into testing and learning Kubernetes. It is especially tailored for beginners, like myself, who are just starting their journey and need a reliable home platform for doing so.
Note
Ready to be carefully reviewed by Patrik or other friends who find their way to this repo.
Caution
This is intended for learning, testing, and experimentation. The emphasis is not on security or creating an operational environment suitable for production.
This guide provides a rapid method to establish a home Kubernetes environment for testing modern applications on a single Minikube Host VM. It is important to note that this guide is not intended for use as a reference in a production environment and does not comprehensively cover all the security considerations required for such an environment.
The following computer environment was utilized. For details regarding container image versions and other components, please refer to the respective sections in the application documentation available here.
Microsoft Windows 10 Enterprise, OS : Version 10.0.19045 N/A Build 19045
VMware Workstation 17 Pro: Version 17.5.0 build-22583795
VMware Photon OS: Version 5.0
Docker Client Engine - Community: Version 24.0.5, API version: 1.43, Go version: go1.20.10
Docker Server Engine - Community: Version 24.0.5, API version: 1.43, Go version: go1.20.10
Virtual Machine: 2vCPU, 8GB vRAM, 50 GB vDisk
Minikube version: v1.32.0
Kubectl Client Version: v1.29.0
Tip
While this was performed on a VMware Workstation with Photon OS, the process should be largely similar for your preferred Linux distribution in conjunction with another hypervisor like VirtualBox, for example
Big thanks to all the people involved in the material I refer to in my links! I would also like to express gratitude to everyone out there, including my colleagues and friends, who are creating things that help and inspire us to continue learning and exploring this never-ending world of computer technology.
- Downloading Photon OS
- Photon OS
- Container Host using a Photon OS VM
- Minikube Start
- Minikube Status
- Docker Postinstallation
- Hello-Minikube
- kubectl to Create a Deployment
- Minikube and Multi Node
- Kubernetes
It was not difficult to create a VM-based Minikube host. The VM has been saved as an OVA file for effortless duplication and quick provisioning of new VMs. This enables me to easily provision new VMs when needed. The creation of a completely new one can also be done by running my script create_minikubeHost.sh.
Setting hostname, running update, installing sudo and creating the user labuser.
hostnamectl hostname minikubeHost
tdnf update -y
tdnf install sudo -y
This Docker post-installation is necessary to meet the requirement of starting and running Minikube either as a non-privileged user or by using sudo. In this guide, I create a labuser, who runs Minikube throughout all the documented steps.
systemctl enable docker
systemctl start docker
useradd -m labuser
usermod -aG docker labuser
Verify that the user labuser can run docker.
sudo -u labuser docker run hello-world
Installing latest minikube stable releas.
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
install -m 755 minikube-linux-amd64 /usr/local/bin/minikube
rm minikube-linux-amd64
Installing latest kubectl stable releas.
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
install -m 0755 kubectl /usr/local/bin/kubectl
rm kubectl
Login as labuser and start minikube:
sudo -iu labuser
minikube start
Gets the status of the local Kubernetes cluster using the command minikube status.
minikube status
Test to deaploy the first application, hello-minikube and expose it on port 8080
kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0
kubectl expose deployment hello-minikube --type=NodePort --port=8080
It will soon shows up when the fallowing command is run.
kubectl get services hello-minikube
Minikube provides access to the actual service by running the command below.
minikube service hello-minikube
This will display a URL that can be used for local testing within the Minikube host.
curl http://192.168.49.2:30935
Use kubectl to forward the port. For this to work, configure the desired port on the Minikube Host firewall using root privileges. Make sure the port chosen is a higher number, so labuser can do the port forwarding
iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
iptables-save > /etc/systemd/scripts/ip4save
systemctl restart iptables
You can initiate port forwarding using the kubectl command. Log in as the labuser and execute the following command. Afterward, you should be able to browse to the IP address of the Minikube Host VM and the forwarded port
minikubeHostIP=$(ip address |grep inet |grep eth0 |awk '{print$2}' |sed 's,/24,,g')
kubectl port-forward --address $minikubeHostIP service/hello-minikube 8080:8080
or in one liner
kubectl port-forward --address $(ip address |grep inet |grep eth0 |awk '{print$2}' |sed 's,/24,,g') service/hello-minikube 8080:8080
Now you can clean up the resources created in the cluster.
kubectl delete service hello-minikube
kubectl delete deployment hello-minikube
minikube stop
Tip
Using stop command will stops a local Kubernetes cluster. This command stops the underlying VM or container, but keeps user data intact. The
cluster can be started again with the start command.
Using deletes command will a local Kubernetes cluster. This command deletes the VM, and removes all associated files.
Use minikube options for a list of global command-line options (applies to all commands).
By default, Minikube uses a single node in the created cluster. For a more realistic experience in deploying applications within a production-like cluster, you can configure Minikube to use multiple nodes.
Figure 01 provides an overview of the various components within a Kubernetes cluster.
Here, I will demonstrate how to create a three-node cluster, comprising one master node (control-plane) and two worker nodes. I have named it illusion. Achieve this by executing the following command.
su - labuser
minikube start --nodes 3 -p illusion
It might take a few minutes, but Minikube will give you updates as it progresses and will finish with a 'Done' message.
This creates (among other things) 3 containers: illusion, illusion-m02 and illusion-m03, as well as a Docker network named illusion.
You can control and view the three nodes that were just created using the following command.
kubectl get nodes
Figure 02 shows the result of the command.
To prevent deploying applications to the 'control-plane,' we need to label the other nodes as 'worker.' In my case, this can be accomplished using the command below, applying it to each node.
kubectl label node illusion-m02 node-role.kubernetes.io/worker=worker
kubectl label node illusion-m03 node-role.kubernetes.io/worker=worker
You may want to again using the kubectl get nodes
command again.<br
Figure 03 shows the result after labeling the nodes.
After deleting your application deployment, you might want to remove all the created cluster nodes. To do this, use the following command.
kubectl delete nodes illusion illusion-m02 illusion-m03
In my case, all nodes in my illusion-cluster need to be deleted. Alternatively, you can directly delete the illusion-profile to terminate everything at once.
Before stopping Minikube, consider cleaning up everything by deleting the current cluster profile. Once that's done, proceed to stop Minikube. Follow the instructions below.
minikube profile list # Lists all valid minikube profiles and detects all possible invalid profiles
minikube delete --profile illusion # Deletes a local Kubernetes cluster. This command deletes the VM, and removes all associated files.
In my case, delete everything associated with the illusion-profile, including the profile itself, leaving only the Docker Network intact.
To delete the remaining network, use the command:docker network rm illusion
Tip
The hello-minikube tutorial guides you through running a sample app on Kubernetes using Minikube and serves as a good next step in exploring Kubernetes.