{"id":1991,"date":"2021-11-30T12:00:00","date_gmt":"2021-11-30T11:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/kubernetes-beginner-tutorial-deploy-spring-boot-to-kubernetes-cluster\/"},"modified":"2026-07-05T03:26:13","modified_gmt":"2026-07-05T01:26:13","slug":"kubernetes-beginner-tutorial-deploy-spring-boot-to-kubernetes-cluster","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/kubernetes-beginner-tutorial-deploy-spring-boot-to-kubernetes-cluster\/","title":{"rendered":"Kubernetes Beginner Tutorial \u2013 Deploy Spring Boot to Kubernetes Cluster"},"content":{"rendered":"<p>In this tutorial, we would learn how to deploy a Spring Boot application to a local Kubernetes cluster. This would be the first of series of tutorials on DevOps with Docker and Kubernetes for beginners. At the end of the series, you should be able to deploy web applications along with their databases to Docker and Kubernetes cluster.<\/p>\n<p>In this very part, we would setup Kubernetes cluster locally (Minikube), create a simple SpringBoot application and deploy to the Kubernetes cluster<\/p>\n<p>We cover the following<\/p>\n<ol>\n<li><a href=\"#t1\">Have Docker Installed and Tested<\/a><\/li>\n<li><a href=\"#t2\">Setup Minikube<\/a><\/li>\n<li><a href=\"#t3\">Create and Build a Spring Boot Application<\/a><\/li>\n<li><a href=\"#t4\">Create a Docker Image<\/a><\/li>\n<li><a href=\"#t5\">Optional &#8211; Push the Image to Docker Hub<\/a><\/li>\n<li><a href=\"#t6\">Create Deployment and Deploy to Kubernetes Cluster<\/a><\/li>\n<li><a href=\"#t7\">Test the Deployment<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>Follow the steps below:<\/p>\n<p><strong id=\"t1\">Step 1 &#8211; Have Docker installed<\/strong><\/p>\n<p>You need to ensure that Docker is installed and running. Use this command:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">docker version\r\n<\/pre>\n<p>You may want to get used to docker and Spring Boot using\u00a0 this short practical tutorial:<\/p>\n<p class=\"entry-title\"><a href=\"https:\/\/www.kindsonthegenius.com\/introduction-to-dockerfile-with-spring-boot-how-to-dockerize-springboot-app\/\" target=\"_blank\" rel=\"noopener\">Introduction to Dockerfile with Spring Boot \u2013 How to Dockerize SpringBoot App<\/a><\/p>\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=q83IoIJ4y4s\" target=\"_blank\" rel=\"noopener\">SpringBoot Docker &#8211; Video Tutorial<\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t2\">Step 2 &#8211; Setup Minikube<\/strong><\/p>\n<p>Minikube is a way to run Kubernetes cluster locally on your machine. Also check that you have Minikube.<\/p>\n<p>Use the command<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">minikube version\r\n<\/pre>\n<p>Once you are sure Minkube is installed, go ahead to start it using the command:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">minikube start\r\n<\/pre>\n<p>Just to let you know, <strong>kubectl<\/strong> is a command line tool for managing Minikube.<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t3\">Step 3 &#8211; Create and build a SpringBoot Application<\/strong><\/p>\n<p>In this demo, we just create a simple SpringBoot REST API that return a string. But this works for bigger applications as well (without database because we would be talking about database deployment later). I call this application <strong>kubedemo<\/strong><\/p>\n<p>Use the command below to create your jar file<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">mvn clean install -DskipTests\r\n<\/pre>\n<p>You can now check that the target folder of your application contains your jar file.<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t4\">Step 4 &#8211; Create a Docker image of your application<\/strong><\/p>\n<p>To do this you should have a docker file in the root directory of your application. The complete procedure to <a href=\"https:\/\/www.kindsonthegenius.com\/introduction-to-dockerfile-with-spring-boot-how-to-dockerize-springboot-app\/\" target=\"_blank\" rel=\"noopener\">dockerize your Spring Boot Application is given here. <\/a>The easiest way to create a docker image of your application is to use Buildpacks. The command is simply:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">mvn spring-boot:build-image\r\n<\/pre>\n<p>This command would create a local image of your application using the jar file you created in step 3.<\/p>\n<p>You can verify that the image is created using the command below:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">docker images\r\n<\/pre>\n<p>This command would list all the docker images available in your local repository. You should see the new image you just built!<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t5\">Step 5 &#8211; Push to Docker Hub (Optional)<\/strong><\/p>\n<p>You can actually leave your image locally. But it&#8217;s fine you know how to push your image to Docker hub online. In this way, you can get them from anywhere or even share with friends.<\/p>\n<p>You need two commands:<\/p>\n<p>First, tag the image:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">docker tag kubedemo:0.0.1-SNAPSHOT kindsonthegenius\/kubedemo\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Second, push to Docker hub:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">docker push kindsonthegenius\/kubedemo\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong id=\"t6\">Step 6 &#8211; Deploy to Kubernetes Cluster<\/strong><\/p>\n<p>As you know, a cluster is a collection of two or more machines called nodes. Same is true of Kubernetes. A Kubernetes cluster is made up of a number of nodes. However, the nodes in a Kubernetes cluster consists of <strong>&#8216;sub-nodes<\/strong>&#8216; called <strong>pods<\/strong>. So when we setup Minikube, we did create a cluster with a single node but could have several pods.<\/p>\n<p>To be able to deploy our image to Kubernetes, we need to do three things:<\/p>\n<p><em>1. Create a deployment<\/em><\/p>\n<p>A deployment is a yml file that specifies how your application would run in the Kubernetes cluster.\u00a0 You can have this yaml file created automatically for you using the command:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl create deployment kubedemo --image=kindsonthegenius\/kubedemo --dry-run -o=yaml\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><em>2. Create a Service<\/em><\/p>\n<p>A service defines how connections can be make from outside the cluster into your application running inside the Kubernetes cluster. To have a service created for you, use the command:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl create service clusterip kubedemo --tcp=8080:8080 --dry-run -o=yaml\r\n<\/pre>\n<p>In this case, we specify that our application would be running on port 8080 both inside and outside the container. ClusterIp indicates that we can connect to the application using the cluster&#8217;s ip address. The command below gives you the details of the cluster including the IPs.<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl get all\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><em>3. Apply the deployment<\/em><\/p>\n<p>This means you actually deploy the application to the cluster and the pods(containers are started). Use the command:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl apply -f deployment.yaml\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong id=\"t7\">Step 7 &#8211; Test Your Deployment<\/strong><\/p>\n<p>Now we need to check that everything is working! First you may want to check that the pods are up. This can be done using the command<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl get pods\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Then you can use the command below to get the list of services<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl get services\r\n<\/pre>\n<p>Finally, use the command below to fire up your application:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">minikube service &lt;service-name&gt;\r\n<\/pre>\n<p>This command opens up your browser and you can then go ahead to visit the endpoint \/home<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we would learn how to deploy a Spring Boot application to a local Kubernetes cluster. This would be the first of series &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-1991","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1991","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=1991"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1991\/revisions"}],"predecessor-version":[{"id":2159,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1991\/revisions\/2159"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=1991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=1991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=1991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}