Spring Boot + Kubernetes Tutorial - Service Hello World Example

In this tutorial we will be developing a Nodeport service using which the external client will be able to access the deployed application.

Video
This tutorial is explained in the below Youtube Video.Spring Boot + Kubernetes Tutorial
What is Kubernetes? Need for it? Install Ubuntu on Windows using WSL Installing Kubectl, Minikube and Docker on Ubuntu Create Docker Image Deploy to Minikube Pods Difference between ClusterIP, NodePort and LoadBalancer Service Service Hello World Example
Implementation
In previous tutorial we had created the nodeport service configuration file as follows-apiVersion: v1 kind: Service metadata: name: employee-producer-service spec: selector: app: boot-jar ports: - protocol: TCP port: 80 targetPort: 8080 nodePort: 30080 type: NodePort

Start Minikube
minikube start --force

If we list the docker images, we can see the images we created previously
docker image ls

To use docker with minikube we will need to switch the docker context to using minikube.
eval $(minikube docker-env)
kubectl apply -f service.yml

In previous tutorial we had created a pod.yml for deploying spring boot application to kupernetes pods. For this we will be modifying the pod.yml to have the same label as the service.

apiVersion: v1 kind: Pod metadata: name: boot-jar labels: app: boot-jar spec: containers: - name: boot-jar-container image: javainuse/employee-producer-kubernetes:latest
kubectl delete pod boot-jar

Next we will again create the pod as follows -
kubectl apply -f pod.yml

We can check the pod logs as follows
kubectl logs boot-jar

As the pod is showing that the application has started successfully, we will test the application running in pod. For this we first need to get the minikube ip address as follows -
minikube ip

curl 192.168.49.2:30080/employee
