Giter Site home page Giter Site logo

minikubehost's Introduction

Minikube Host on a Photon OS VM

MyLogo
Minikube is a lightweight Kubernetes implementation that creates a VM on your local machine and deploys a simple cluster containing only one node.



Abstract

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).

Table of Contents

  1. Introduction
  2. Goals and Objectives
  3. Method
  4. Target Audience
  5. Document Status
  6. Disclaimer
  7. Scope and Limitations
  8. Environment
  9. Acknowledgments
  10. References
  11. Conclusion
  12. Making the Minikube Host
    1. Basic Configuration of the Photon OS VM
    2. Docker Post-installation
    3. Installing Minikube and kubectl
    4. Test-start-the-cluster
    5. Checking the cluster status
  13. Interacting with the cluster
    1. Deploying hello-minikube
    2. Checking the deployment
    3. Giving access to service
  14. Enabling port forwarding
    1. Firewall configuration
    2. Using port forwarding
  15. Clean up and stop Minikube
  16. Minikube and multi node clusters
    1. Three node cluster
    2. Get nodes
    3. Labeling the worker nodes
    4. Deleting Nodes
    5. Cleaning all in Minikube
  17. Next - Hello Minikube

Introduction

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.

Goals and Objectives

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.

Method

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.

Target Audience

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.

Document Status

Note

Ready to be carefully reviewed by Patrik or other friends who find their way to this repo.

Disclaimer

Caution

This is intended for learning, testing, and experimentation. The emphasis is not on security or creating an operational environment suitable for production.

Scope and Limitations

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.

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

Acknowledgments

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.

References

Conclusion

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.

Making the Minikube Host

Basic Configuration of the Photon OS VM

Setting hostname, running update, installing sudo and creating the user labuser.

hostnamectl hostname minikubeHost                                                             
tdnf update -y
tdnf install sudo -y

Docker Post-installation

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 Minikube and kubectl

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

Test start the cluster

Login as labuser and start minikube:

sudo -iu labuser
minikube start

Checking the cluster status

Gets the status of the local Kubernetes cluster using the command minikube status.

minikube status

Interacting with the cluster

Deploying hello-minikube

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

Checking the deployment

It will soon shows up when the fallowing command is run.

kubectl get services hello-minikube

Giving access to service.

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

Enabling port forwarding

Firewall configuration

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

Using port forwarding

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

Clean up and stop Minikube

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).

Minikube and multi node clusters

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.
KubernetesComponents
Figure 01 provides an overview of the various components within a Kubernetes cluster.

Three node 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.

Get nodes

You can control and view the three nodes that were just created using the following command.

kubectl get nodes

GetNodes
Figure 02 shows the result of the command.

Labeling the Worker Nodes

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 GetLabelNodes
Figure 03 shows the result after labeling the nodes.

Deleting 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.

Cleaning all in Minikube

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

Next - Hello Minikube

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.

minikubehost's People

Contributors

rafaelurrutiasilva avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.