{"id":1996,"date":"2022-02-06T12:00:00","date_gmt":"2022-02-06T11:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/deploy-springboot-application-to-kubernetesminikube-using-deployment-yaml-file\/"},"modified":"2026-08-31T09:46:49","modified_gmt":"2026-08-31T07:46:49","slug":"deploy-springboot-application-to-kubernetesminikube-using-deployment-yaml-file","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/deploy-springboot-application-to-kubernetesminikube-using-deployment-yaml-file\/","title":{"rendered":"Deploy SpringBoot Application to Kubernetes(Minikube) Using Deployment yaml file"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><em>Learn how to deploy SpringBoot Application to Kubernetes using Minikube and a deployment YAML file, create a Docker image, configure a service, and test the application.<\/em><\/p>\n\n\n<h3>TL;DR<\/h3>\n<ul>\n<li>\n<p>Create a Docker image for the SpringBoot application.<\/p>\n<\/li>\n<li>\n<p>Configure Minikube to access the local Docker repository.<\/p>\n<\/li>\n<li>\n<p>Create a Kubernetes <code>deployment.yaml<\/code> file for the SpringBoot application.<\/p>\n<\/li>\n<li>\n<p>Apply the deployment and check the status of the deployment and pods.<\/p>\n<\/li>\n<li>\n<p>Create a <code>service.yaml<\/code> file using a NodePort service.<\/p>\n<\/li>\n<li>\n<p>Access and test the SpringBoot application using the Minikube node IP and NodePort.<\/p>\n<\/li>\n<\/ul>\n<p>In the previous tutorial, you learnt<a href=\"https:\/\/kindsonthegenius.com\/blog\/setup-kubernetes-locally-deploy-springboot-application-step-by-step-tutorial\/\" target=\"_blank\" rel=\"noopener\"> How to Setup a Local Kubernetes Cluster (Minikube) and deploy a SpringBoot application<\/a>. You also learn <a href=\"https:\/\/kindsonthegenius.com\/blog\/setup-kubernetes-locally-deploy-springboot-application-step-by-step-tutorial\/#t6\" target=\"_blank\" rel=\"noopener\">how to access the Minikube dashboard<\/a> in the browser.<\/p>\n<p>In this lesson, you will learn how to deploy Spring Boot application using a deployment file.<\/p>\n<ol>\n<li><a href=\"#t1\">Create a Docker Image<\/a><\/li>\n<li><a href=\"#t2\">Create a Deployment File<\/a><\/li>\n<li><a href=\"#t3\">Create a Deployment Object using Apply Command<\/a><\/li>\n<li><a href=\"#t4\">Create and Test the Service<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. Create a Docker Image<\/strong><\/h4>\n<p>You first need to have a SpringBoot application. Then you also need to create a docker image of your SpringBoot application.<\/p>\n<p><strong>Step 1<\/strong> \u2013 First use this command to allow Minikube access to our docker repositories:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">eval $(minikube docker-env)\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2<\/strong> \u2013 Use this command to create a docker image.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">docker build -t springboot-kubernetes:1.0 .\n<\/pre>\n<p>At this point we have a docker image with name <strong><em>springboot-kubernetes<\/em><\/strong> with a tag of <em><strong>1.0<\/strong><\/em><\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Create a Deployment File<\/strong><\/h4>\n<p>Inside the resources directory, create a file named deployment.yaml. The content is as follows:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: springboot-kubernetes\nspec:\n  selector:\n    matchLabels:\n      app: springboot-kubernetes\n  replicas: 3\n  template:\n    metadata:\n      labels:\n        app: springboot-kubernetes\n    spec:\n      containers:\n        - name: springboot-kubernetes\n          image: springboot-kubernetes:1.0\n          imagePullPolicy: IfNotPresent\n          ports:\n            - containerPort: 8080\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. Create the Deployment Using the Apply Command<\/strong><\/h4>\n<p>Now that we have created the deployment file, we need to apply it.<\/p>\n<p><strong>Step 1<\/strong> \u2013 Start minikube using the command minikube start.<\/p>\n<p><strong>Step 2<\/strong>\u00a0\u2013 Navigate to the resources directory containing the deployment<\/p>\n<p><strong>Step 3<\/strong>\u00a0\u2013 Run the command\u00a0 below to apply the deployment<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl apply -f deployment.yaml\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4<\/strong> \u2013 You can check the status of the deployment using the command:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl get deployment\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 5<\/strong> \u2013 Use the command below to view the pods and their statuses:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl kubectl get pods\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 6<\/strong> \u2013 Check the status of the pods using the command<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"> kubectl logs \n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. Create and Test the Service<\/strong><\/h4>\n<p>We would need to be able to access the application from outside the Kubernetes cluster. For this, we need to create a service object.<\/p>\n<p><strong>Step 1<\/strong> \u2013 Create a service.yaml file inside the resources directory. This is the content of the service.yaml file<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">apiVersion: v1\nkind: Service\nmetadata:\n  name: springboot-kubernetes-service\nspec:\n  ports:\n    - protocol: \"TCP\"\n      port: 8080        # The port inside the cluster\n      targetPort: 8080  # The port exposed by the service\n  type: NodePort        # Type of service\n  selector:\n    app: springboot-kubernetes\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2<\/strong> \u2013 Apply the service using the command below<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl apply -f service.yaml\n<\/pre>\n<p>The service would then be created<\/p>\n<p>You can then use <em><strong>kubectl get services<\/strong><\/em> command to check that the services is created.<\/p>\n<p>To access the application, you can can use a combination of the internal-ip and the node port. The internal ip and the minikube ip are the same. To get these details, use the command below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl get nodes -o wide\n<\/pre>\n<p>&nbsp;<\/p>\n<p>I do recommend you watch the video on my <a href=\"https:\/\/www.youtube.com\/c\/KindsonTheTechPro\" target=\"_blank\" rel=\"noopener\">YouTube Channel<\/a> for more details.<\/p>\n<h3>FAQs<\/h3>\n<p><strong>How do I deploy a SpringBoot application to Kubernetes?<\/strong><\/p>\n<p>Create a Docker image for the application, define a Kubernetes Deployment in a YAML file, apply the deployment with <code>kubectl apply<\/code>, and expose the application using a Kubernetes Service.<\/p>\n<p><strong>How do I create a Docker image for a SpringBoot application?<\/strong><\/p>\n<p>After configuring Minikube to use the Docker environment, run <code>docker build -t springboot-kubernetes:1.0 .<\/code> to create the Docker image.<\/p>\n<p><strong>How do I create a Kubernetes Deployment YAML file?<\/strong><\/p>\n<p>Create a <code>deployment.yaml<\/code> file that defines the Deployment, application image, number of replicas, container port, and pod labels.<\/p>\n<p><strong>How do I expose a SpringBoot application running in Kubernetes?<\/strong><\/p>\n<p>Create a Kubernetes Service using the <code>NodePort<\/code> service type, configure it to target port 8080, and apply the service YAML file.<\/p>\n<p><strong>How do I access a SpringBoot application deployed to Minikube?<\/strong><\/p>\n<p>Use <code>kubectl get nodes -o wide<\/code> to obtain the node&#8217;s internal IP, then combine the IP with the NodePort assigned to the service to access the application.<\/p>\n<h3>Final Thoughts<\/h3>\n<p>Deploying a SpringBoot application to Kubernetes using Minikube provides a practical introduction to Kubernetes Deployments, Pods, Services, and Docker images.<\/p>\n<p>Once the application image is created, the Deployment YAML can be applied to create multiple application pods. A NodePort Service then makes the application accessible from outside the cluster. From here, you can build on this setup by adding databases, persistent storage, configuration, security, and more advanced Kubernetes deployment features.<\/p>","protected":false},"excerpt":{"rendered":"<p>Learn how to deploy SpringBoot Application to Kubernetes using Minikube and a deployment YAML file, create a Docker image, configure a service, and test the &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[414],"tags":[],"class_list":["post-1996","post","type-post","status-publish","format-standard","hentry","category-programming"],"acf":[],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1996","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=1996"}],"version-history":[{"count":3,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1996\/revisions"}],"predecessor-version":[{"id":2586,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1996\/revisions\/2586"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=1996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=1996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=1996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}