Getting Started with minikube

0
825

Learn how to install minikube, and deploy Nginx in Kubernetes using load balancer.

minikube provisions and manages local Kubernetes clusters. It helps to manage or use resources for development test scenarios. The configuration of Kubernetes installation requires a lot of resources and is not easy. minikube comes to the rescue here.

In this article we will install minikube, deploy Nginx and access it using load balancer. We will go through the minikube dashboard as well.

Installation

Let’s install minikube in Windows using Chocolatey. This package manager for Windows is amazingly simple. Installation instructions are available at https://minikube.sigs.k8s.io/docs/start/ for Linux, MacOS, and Windows for different architectures, release types, and installer types.

The prerequisites are:

  • 2 CPUs or more
  • 2GB of free memory
  • 20GB of free disk space
  • Internet connection
  • Container or virtual machine manager, such as Docker, Hyperkit, Hyper-V, KVM, Parallels, Podman, VirtualBox, or VMware Fusion/Workstation

    Figure 1: Virtual box
    Figure 1: Virtual box

To install minikube using Chocolatey, execute choco install minikube in Windows Powershell.

PS C:\WINDOWS\system32> choco install minikube
Chocolatey v0.10.15
Installing the following packages:
minikube
By installing you accept licenses for the packages.
Progress: Downloading Minikube 1.26.1... 100%

Minikube v1.26.1 [Approved]
minikube package files install completed. Performing other installation steps.
 ShimGen has successfully created a shim for minikube.exe
 The install of minikube was successful.
  Software install location not explicitly set, could be in package or
  default install location if installer.

Chocolatey installed 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Did you know the proceeds of Pro (and some proceeds from other
 licensed editions) go into bettering the community infrastructure?
 Your support ensures an active community, keeps Chocolatey tip top,
 plus it nets you some awesome features!
 https://chocolatey.org/compare

Verify whether minikube is installed or not using the minikube version command.

PS C:\WINDOWS\system32> minikube version
minikube version: v1.26.1
commit: 62e108c3dfdec8029a890ad6d8ef96b6461426dc

Check the minikube status and profile. 

PS C:\WINDOWS\system32> minikube status
* Profile “minikube” not found. Run “minikube profile list” to view all profiles.
  To start a cluster, run: “minikube start”
PS C:\WINDOWS\system32> minikube profile list

* Exiting due to MK_USAGE_NO_PROFILE: No minikube profile was found.
* Suggestion:

    You can create one using ‘minikube start’.

Install VirtualBox in the Windows system and verify existing status.

Now execute the minikube start –driver=virtualbox command.

PS C:\WINDOWS\system32> minikube start --driver=virtualbox
* minikube v1.26.1 on Microsoft Windows 10 Home Single Language 10.0.19044 Build 19044
* Using the virtualbox driver based on user configuration
* Starting control plane node minikube in cluster minikube
* Creating virtualbox VM (CPUs=2, Memory=3000MB, Disk=20000MB) ...
! This VM is having trouble accessing https://k8s.gcr.io
* To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
* Preparing Kubernetes v1.24.3 on Docker 20.10.17 ...
  - Generating certificates and keys ...
  - Booting up control plane ...
  - Configuring RBAC rules ...
  - Using image gcr.io/k8s-minikube/storage-provisioner:v5
<Output Snipped>

Next, you can verify minikube status.

PS C:\WINDOWS\system32> minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

Virtualbox will now have a minikube virtual machine available, as shown in Figure 2.

Figure 2: minikube virtual machine
Figure 2: minikube virtual machine

Next, we will verify the profile list available for minikube.

PS C:\WINDOWS\system32> minikube profile list

|----------|------------|---------|----------------|------|---------|---------|-------|--------|
| Profile  | VM Driver  | Runtime |       IP       | Port | Version | Status  | Nodes | Active |
|----------|------------|---------|----------------|------|---------|---------|-------|--------|
| minikube | virtualbox | docker  | 192.168.59.101 | 8443 | v1.24.3 | Running |     1 | *      |
|----------|------------|---------|----------------|------|---------|---------|-------|--------|

Table 1 lists some other commands available for minikube.

Basic commands

start Starts a local Kubernetes cluster
status Gets the status of a local Kubernetes cluster
stop Stops a running local Kubernetes cluster
delete Deletes a local Kubernetes cluster
dashboard Accesses the Kubernetes dashboard running within the minikube cluster

Images commands

docker-env Provides instructions to point your terminal’s docker-cli to the Docker engine inside minikube
cache Manages cache for images
image Manages images
Configuration and management commands

addons Enables or disables a minikube addon
config Modifies persistent configuration values
profile Gets or lists the current profiles (clusters)
update-context Updates kubeconfig in case of an IP or port change

Networking and connectivity commands

service Returns a URL to connect to a service
tunnel Connects to load balancer services
Advanced commands

mount Mounts the specified directory into minikube
ssh Logs into the minikube environment (for debugging)
kubectl Runs a kubectl binary matching the cluster version
node Adds, removes, or lists additional nodes
cp Copies the specified file into minikube
Troubleshooting commands

ip Retrieves the IP address of the specified node
logs Returns logs to debug a local Kubernetes cluster
update-check Prints current and latest version numbers
version Prints the version of minikube
options Shows a list of global command-line options (applies to all commands)

 

Once minikube is up and running, let’s visit the minikube dashboard (Figure 3).

Figure 3: Minikube dashboard
Figure 3: Minikube dashboard
PS C:\WINDOWS\system32> minikube dashboard
* Enabling dashboard ...
  - Using image kubernetesui/dashboard:v2.6.0
  - Using image kubernetesui/metrics-scraper:v1.0.8
* Verifying dashboard health ...
* Launching proxy ...
* Verifying proxy health ...
* Opening http://127.0.0.1:55011/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser…

You can check and verify the allocation of resources in the minikube dashboard shown in Figure 4.

Figure 4: Minikube resources
Figure 4: Minikube resources

Deployment of load balancer in minikube

Let’s use Nginx deployment in a minikube cluster.

PS C:\WINDOWS\system32> kubectl create deployment --image=nginx nginx-app
deployment.apps/nginx-app created

Once successfully deployed, you can verify the deployment in the minikube dashboard, as shown in Figure 5.

Figure 5: Nginx deployment
Figure 5: Nginx deployment

The dashboard also shows services in the minikube (Figure 6).

Figure 6: Nginx service
Figure 6: Nginx service

Figure 7 shows the Nginx pod and container.Figure 7: Nginx pod

Figure 7: Nginx pod
Figure 7: Nginx pod

Now, expose the Nginx deployment as follows:

PS C:\WINDOWS\system32> kubectl expose deployment nginx-app --type=LoadBalancer --port=80
service/nginx-app exposed

Next, execute the minikube tunnel.

PS C:\WINDOWS\system32> minikube tunnel
Status:
        machine: minikube
        pid: 5388
        route: 10.96.0.0/12 -> 192.168.59.101
        minikube: Running
        services: [nginx-app]
    errors:
                minikube: no errors
                router: no errors
                loadbalancer emulator: no errors

Verify the external endpoint in the service section of the minikube dashboard (Figure 8).

Figure 8: External endpoint
Figure 8: External endpoint

Now click on the external endpoint URL (Figure 9).

Figure 9: Ngnix welcome screen
Figure 9: Ngnix welcome screen

The following commands are available for different actions in minikube.

  • Check minikube status: minikube status
  • Stop minikube: minikube stop
  • Delete minikube cluster: minikube delete
  • Uninstall minikube: choco uninstall minikube

LEAVE A REPLY

Please enter your comment!
Please enter your name here