2 ms·
Kubernetes – Deploy spring boot microservice on K8s cluster
- rahulwagh17 6y agoStep 1: Setting up the spring boot application - Goto https://start.spring.io/ https://start.spring.io/ and fill in the following details for spring boot application – Group – com.jhooq Artifacts – Jhooq-k8s Project – Gradle Project Packaging – Jar Java – 11 Step 2: Import the spring boot project into your intellij or any other IDE(eclipse or netbeans...) Step 3: Build your microservice package com.jhooq.Jhooqk8s.ws; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class JhooqController { @GetMapping("/hello") public String hello() { return "Hello - Jhooq-k8s"; } } Gradle build $ ./gradlew build BUILD SUCCESSFUL in 6s 5 actionable tasks: 5 executed Step 4: Test the rest webserive - $ curl http://localhost:8080/hello http://localhost:8080/hello Hello - Jhooq-k8s Step 5: Create Dockerfile for spring boot application FROM openjdk:8-jdk-alpine ARG JAR_FILE=build/libs/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["java","-jar","/app.jar"] Step 6: Create Docker registry at “https://hub.docker.com/“ https://hub.docker.com/“ Step 7: “docker build” && “docker push image” $ docker build -t jhooq-k8s-springboot . $ docker tag jhooq-k8s-springboot rahulwagh17/kubernetes:jhooq-k8s-springboot $ docker push rahulwagh17/kubernetes:jhooq-k8s-springboot Step 8: Start kubernetes cluster - https://jhooq.com/kubespray-12-steps-for-installing-a-production-ready-kubernetes-cluster/ https://jhooq.com/kubespray-12-steps-for-installing-a-produc... Step 9: Deploy Spring Boot microservices on kubernetes $ kubectl create deployment demo --image=rahulwagh17/kubernetes:jhooq-k8s-springboot $ kubectl expose deployment demo --type=LoadBalancer --name=demo-service --external-ip=1.1.1.1 --port=8080 $ kubectl get service $ curl http://100.0.0.2:31901/hello http://100.0.0.2:31901/hello