{"id":1994,"date":"2022-02-05T12:00:00","date_gmt":"2022-02-05T11:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/setup-kubernetes-locally-deploy-springboot-application-step-by-step-tutorial\/"},"modified":"2026-07-05T03:26:19","modified_gmt":"2026-07-05T01:26:19","slug":"setup-kubernetes-locally-deploy-springboot-application-step-by-step-tutorial","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/setup-kubernetes-locally-deploy-springboot-application-step-by-step-tutorial\/","title":{"rendered":"Setup Kubernetes Locally \u2013 Deploy SpringBoot Application \u2013 Step by Step Tutorial"},"content":{"rendered":"<p>In this tutorial, you will learn how to easily setup local Kubernetes cluster. Then we would create a simple Spring Boot application and deploy to Kubernetes. I would be explaining each step as I go.<\/p>\n<p>In the next tutorial, we would learn how to deploy both database and application to Kubernetes cluster. Finally, we&#8217;ll learn how to automate the deployment using a Helm Chart.<\/p>\n<ol>\n<li><a href=\"#t1\">Overview of Kubernetes and its Components<\/a><\/li>\n<li><a href=\"#t2\">Setup Local Kubernetes Cluster (Minikube)<\/a><\/li>\n<li><a href=\"#t3\">Build the SpringBoot Image<\/a><\/li>\n<li><a href=\"#t4\">Create the Deployment<\/a><\/li>\n<li><a href=\"#t5\">Create the Service<\/a><\/li>\n<li><a href=\"#t6\">Access the Minikube Dashboard<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. Overview of Kubernetes and its Components<\/strong><\/h4>\n<p>Kubernetes is a container orchestration platform that helps you create and deploy images of of your application. To understand how it works, you need to know about these components.<\/p>\n<p><strong>Cluster<\/strong> &#8211; A cluster in Kubernetes has the same meaning as in other contexts. It is a collection of nodes (or Virtual Machines)<\/p>\n<p><strong>Minikube<\/strong> &#8211; Minikube is simply a local Kubernetes. In this way you don&#8217;t need to a cloud environment to learn and develop Kubernetes.<\/p>\n<p><strong>Node<\/strong> &#8211; A node is a single virtual machine. Think of it as a single computer.<\/p>\n<p><strong>Pod<\/strong> &#8211; A pod is the smallest unit of deployment in Kubernetes.\u00a0 A node can contain one or more pod. So your application actually runs in containers called pods.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Setup Local Kubernetes Cluster<\/strong><\/h4>\n<p>We would go through how to setup and test Kubernetes cluster on Mac. And it would be just a few simple steps.<\/p>\n<p><strong>Step 1<\/strong> &#8211; Download and install Docker (it&#8217;s quite simple but you can find steps here)<\/p>\n<p><strong>Step 2<\/strong> &#8211; Install Minikube. For Mac, the easiest way is the use Homebrew via the command<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">brew install minikube\r\n<\/pre>\n<p>Other ways to install here &#8211; <a href=\"https:\/\/minikube.sigs.k8s.io\/docs\/start\/\" target=\"_blank\" rel=\"noopener\">https:\/\/minikube.sigs.k8s.io\/docs\/start\/<\/a><\/p>\n<p>You can also see learn about <a href=\"https:\/\/www.kindsonthegenius.com\/dockers-containers-and-kubernetes-a-simple-explanation\/\" target=\"_blank\" rel=\"noopener\">Docker, Containers and Kubernetes here<\/a><\/p>\n<p><strong>Step 3<\/strong> &#8211; Start Kubernetes using the following command:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">minikube start\r\n<\/pre>\n<p>This command starts the local kubernetes cluster.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. Build the Image of Your SpringBoot Application<\/strong><\/h4>\n<p>You need to have an existing Spring Boot application. Now we would first create a Dockerfile, then we use the Dockerfile to build an image of our SpringBoot application.<\/p>\n<p><strong>Step 1<\/strong> &#8211; Create a Dockerfile. The content is shown below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">FROM adoptopenjdk\/openjdk11:alpine-jre\r\nADD target\/fleetmsv2-0.0.1-SNAPSHOT.jar app.jar\r\nENTRYPOINT [\"java\",\"-jar\",\"\/app.jar\"]\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2<\/strong> &#8211; Run the application to create the jar file.<\/p>\n<p><strong>Step 3<\/strong> &#8211; Run this command to make Kubernetes work with your local Docker installation<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">eval $(minikube docker-env)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4<\/strong>\u00a0&#8211; Build the docker image using the command below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">docker build -t springboot-kubernetes:1.0 .\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. Create the\u00a0 Deployment<\/strong><\/h4>\n<p>First we need to create a deployment. We can do this either using a command or using a yaml file. In this tutorial, we would use a command. In subsequent tutorial, we would use a yaml file. Same goes for the service.<\/p>\n<p><strong>Step 1<\/strong> &#8211; Run this command to create the deployment<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl create deployment springboot-kubernetes --image=springboot-kubernetes:1.0 --port=8080\r\n<\/pre>\n<p>This command creates a deployment which starts your SpringBoot application inside a Kubernetes cluster.<\/p>\n<p><strong>Step 2<\/strong> &#8211; Use the <em><strong>kubectl get pods<\/strong><\/em> command to check that the pod is up and running. This command also gives you the name of the pod<\/p>\n<p><strong>Step 3<\/strong> &#8211; Use the <strong><em>kubectl logs &lt;pod_name&gt;<\/em><\/strong> to view the logs. You&#8217;ll see that the application is started at pot 8080.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t5\">5. Create the Service and Access the Application<\/strong><\/h4>\n<p>We would now create a service. A service would help us to connect to the application running in a node inside the Kubernetes cluster. So we need to expose the deployment<\/p>\n<p><strong>Step 1<\/strong> &#8211; Get the name of the deployment using the command <strong><em>kubectl get deployments<\/em><\/strong><\/p>\n<p><strong>Step 2<\/strong> &#8211; Create a service by exposing the deployment using the command below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl expose deployment springboot-kubernetes --type=NodePort\r\n<\/pre>\n<p>You can get the services name using the <strong><em>kubectl get services<\/em><\/strong> command<\/p>\n<p><strong>Step 3<\/strong> &#8211; Get the service url using the command<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">minikube service springboot-kubernetes\r\n<\/pre>\n<p>This command would display the services url for container running inside the pod. It would also open the default browser and redirect to the url.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t6\">6. Access the Kubernetes Dashboard<\/strong><\/h4>\n<p>The minikube dashboard gives you a user interface showing the Kubernetes status as well as the services, workloads, pods, jobs etc.<\/p>\n<p>To access the Kubernetes dashboard, enter the command:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">minikube dashboard\r\n<\/pre>\n<p>This command would start the Minikube dashboard and display the corresponding url. Click on the link and it would launch the dashboard as shown below:<\/p>\n<figure id=\"attachment_14824\" aria-describedby=\"caption-attachment-14824\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2022\/02\/Screenshot-2022-02-05-at-12.52.18.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14824 size-large\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2022\/02\/Screenshot-2022-02-05-at-12.52.18-1024x690.png\" alt=\"Kubernetes Minikube Dashboard\" width=\"1024\" height=\"690\" srcset=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2022\/02\/Screenshot-2022-02-05-at-12.52.18-1024x690.png 1024w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2022\/02\/Screenshot-2022-02-05-at-12.52.18-300x202.png 300w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2022\/02\/Screenshot-2022-02-05-at-12.52.18-768x518.png 768w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2022\/02\/Screenshot-2022-02-05-at-12.52.18-1536x1035.png 1536w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2022\/02\/Screenshot-2022-02-05-at-12.52.18-2048x1380.png 2048w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2022\/02\/Screenshot-2022-02-05-at-12.52.18-600x404.png 600w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2022\/02\/Screenshot-2022-02-05-at-12.52.18-272x182.png 272w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-14824\" class=\"wp-caption-text\">Kubernetes Minikube Dashboard<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to easily setup local Kubernetes cluster. Then we would create a simple Spring Boot application and deploy to &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[414],"tags":[],"class_list":["post-1994","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1994","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=1994"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1994\/revisions"}],"predecessor-version":[{"id":2162,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1994\/revisions\/2162"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=1994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=1994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=1994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}