Issue
I need to deploy a spring boot application on google Kubernetes. The application depends on Optaplanner which need to compile some Java classes into bytecode on the fly at runtime, so JDK is needed.
How to deploy on a JDK-provided Kubernetes engine, instead of JRE?
Solution
You can create the Docker file and docker image with the JDK so that your application can use the JDK from the docker.
For spring boot example you can check out: https://github.com/spring-guides/gs-spring-boot-docker
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class Application {
@RequestMapping("/")
public String home() {
return "<h1>Spring Boot Hello World!</h1>";
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Example dockerfile
FROM openjdk:8-jdk
RUN addgroup --system spring && adduser --system spring -ingroup spring
USER spring:spring
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
You can refer this official Oracle example : https://docs.oracle.com/en-us/iaas/developer-tutorials/tutorials/spring-on-k8s/01oci-spring-k8s-summary.htm
Answered By - Harsh Manvar