{{announcement.body}}
{{announcement.title}}

Running Spring Boot Application on Kubernetes Minikube on Windows (Part 2)

DZone 's Guide to

Running Spring Boot Application on Kubernetes Minikube on Windows (Part 2)

Check out this second installment on running Spring Boot apps on Kubernetes and Windows.

· Java Zone ·
Free Resource

Four windows side-by-side

Check out this second installment on running Spring Boot apps on Kubernetes and Windows.

Welcome to part two of "Running Spring Boot Application on Kubernetes Minikube On Windows." This article assumes that reader has previous knowledge around Spring Boot, containers, and Kubernetes. I will briefly try to touch upon all of them a little bit. After finishing both articles, the reader will be able to do the following:

1.    Create a Spring Boot application

2.   Create a Docker image of the application and store the image in Docker Hub

3.    Install minikube in Windows Workstation and run the Spring Boot Docker image in it

In the first part of the series, we created a Spring Boot application and provided basic RESTful CRUD services, dockerized it, and pushed it to Docker Hub. The same Docker image will be used here.

You may also like:  Running Spring Boot Application on Kubernetes Minikube on Windows (Part 1) 

In the second part of the series, we will be installing Kubernetes' minikube in the Windows Workstation, pulling the Spring Boot Docker image we have created in the first part of the series, and running the application in our minikube cluster. We are assuming that we are working with Windows 10 or higher with at least 8 GB RAM and 100 GB hard disk.

Installing Minikube

This section describes how we are going to install minikube in our workstation. I will also discuss some of the details regarding Kubernetes and minikube.

Kubernetes

Kubernetes is an open-source container orchestration engine that provides automated application deployment, scaling, and runtime management. It was initially created by Google and is now managed by the Cloud-Native Computing Foundation. It provides a stable, robust container management system, supporting many desired features like self-healing, service discovery, load balancing, batch execution, storage orchestration, etc. 

Minikube

Minikube is a local Kubernetes implementation that could be deployed on Linux, Mac, and Windows OS. It is a single cluster Kubernetes engine. It uses OS Virtualization or third-party hypervisor like Oracle Virtual Box. It is usually used for local development and POC.

Installing Minikube

Before installing minikube, we need to install the Docker toolbox, kubectl, and Oracle Virtual Box in the workstation.

Docker Toolbox provides the basic Docker implementation and command line for Windows. Kubectl contains a basic Kubernetes CLI. VirtualBox will act as your hypervisor used for virtualization. 

Docker Toolbox can be downloaded from github.com; kubectl can be downloaded here; Virtual Box can be downloaded here; and minikube can be downloaded here.

Before installing all the software, first, we need to disable the Windows Hypervisor feature as we will be using Virtual Box as our hypervisor. To do this, type "Windows Feature" in the Windows search box and disable the Windows Hypervisor feature, like so:

Windows Hypervisor Platform

After disabling the feature, you need to restart the system. After that, install the Docker Toolbox, Virtual Box, kubectl, and minikube. 

Starting Minikube

Before starting minikube, first, start the Docker Toolbox. In the Docker Toolbox, we have a prompt to do the docker login using the same username and password, which was created in the first part of this series. To start minikube, enter the following command in the command prompt:

minikube start


Starting minikube will take a few minutes initially, as it needs to create the virtual machine for the first time. The command will create the minikube cluster and one VM in the name of minikube. Once the cluster is started, we can verify the details of Kubernetes deployments, pods, and services in our browser locally by using the following command:

minikube dashboard


This command will open the web interface of minikube in the browser.

Installing Ingress Controller

Ingress is an API object that defines rules that allow external access to services in a cluster. The Ingress Controller fulfills the rules set in the Ingress. To install Ingress and verify the installation, enter the following commands:

minikube addons enable ingress

kubectl get pods -n kube-system


The second command will show all of the add-ons running in the Kubernetes cluster.

Running the Spring Boot Docker Image

Running the Docker image in the minikube has to be done in three steps.

1. Pull a Docker image and create a minikube deployment (we can use the Docker image published in the first part of the series)

2. Expose the deployment that will create a service inside the minikube cluster

3. Identify the URL of the service and access it from outside of the cluster

Creating a Deployment Using an Existing Docker Image

The command to create and run a deployment, as shown below:

kubectl run kube-demo --image=adityapratapbhuyan/aditya-test:kubedemo1 --port=8080


This command will use the tag kubedemo1 from the repository aditya-test  at deployment. 

Creating a Service for the Deployment

To access the deployment created in the above section from outside the minikube cluster, we need to expose it as a service. The command to expose it is provided below:

kubectl expose deployment kube-demo --target-port=8080 --type=NodePort

kubectl get services


The first command will create the service and the second command will display the list of services and their details. The service would be exposed at port 8080

Accessing the Service

Once the service is available, we need to access it from outside the cluster, To identify the external URL for the service, use the following command:

minikube service kube-demo --url


The output of the following command will be the external URL of the service. Use the URL and test the application as mentioned in the Validating the RESTful Service section of the first part of this series.

Conclusion

The second part provides details about installing minikube, creating a cluster, and running images inside it. The series needed a logical split into two parts. Readers can always use the references below for more details. 

Further Reading

Running Spring Boot Application on Kubernetes Minikube on Windows (Part 1) 

Quick Guide to Microservices With Kubernetes, Spring Boot 2.0, and Docker

Topics:
kubernetes ,container ,docker ,minikube ,paas services ,virtualization

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}