{"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-07-05T03:26:24","modified_gmt":"2026-07-05T01:26:24","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":"<p>In the previous tutorial, you learnt<a href=\"https:\/\/www.kindsonthegenius.com\/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:\/\/www.kindsonthegenius.com\/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> &#8211; 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)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2<\/strong> &#8211; Use this command to create a docker image.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">docker build -t springboot-kubernetes:1.0 .\r\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\r\nkind: Deployment\r\nmetadata:\r\n  name: springboot-kubernetes\r\nspec:\r\n  selector:\r\n    matchLabels:\r\n      app: springboot-kubernetes\r\n  replicas: 3\r\n  template:\r\n    metadata:\r\n      labels:\r\n        app: springboot-kubernetes\r\n    spec:\r\n      containers:\r\n        - name: springboot-kubernetes\r\n          image: springboot-kubernetes:1.0\r\n          imagePullPolicy: IfNotPresent\r\n          ports:\r\n            - containerPort: 8080\r\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> &#8211; Start minikube using the command minikube start.<\/p>\n<p><strong>Step 2<\/strong>\u00a0&#8211; Navigate to the resources directory containing the deployment<\/p>\n<p><strong>Step 3<\/strong>\u00a0&#8211; Run the command\u00a0 below to apply the deployment<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl apply -f deployment.yaml\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4<\/strong> &#8211; You can check the status of the deployment using the command:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl get deployment\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 5<\/strong> &#8211; Use the command below to view the pods and their statuses:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl kubectl get pods\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 6<\/strong> &#8211; Check the status of the pods using the command<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"> kubectl logs \r\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> &#8211; 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\r\nkind: Service\r\nmetadata:\r\n  name: springboot-kubernetes-service\r\nspec:\r\n  ports:\r\n    - protocol: \"TCP\"\r\n      port: 8080        # The port inside the cluster\r\n      targetPort: 8080  # The port exposed by the service\r\n  type: NodePort        # Type of service\r\n  selector:\r\n    app: springboot-kubernetes\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2<\/strong> &#8211; Apply the service using the command below<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">kubectl apply -f service.yaml\r\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\r\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","protected":false},"excerpt":{"rendered":"<p>In the previous tutorial, you learnt How to Setup a Local Kubernetes Cluster (Minikube) and deploy a SpringBoot application. You also learn how to access &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-1996","post","type-post","status-publish","format-standard","hentry","category-programming"],"_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":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1996\/revisions"}],"predecessor-version":[{"id":2164,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1996\/revisions\/2164"}],"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}]}}