0


K8S 部署 SpringBoot 项目(一篇够用)


首先我们需要搭建一个简单的SpringBoot应用:

引入dependency依赖

org.springframework.boot

spring-boot-starter-web

打包docker镜像的配置:

打包出来的镜像名称

org.springframework.boot

spring-boot-maven-plugin

2.2.5.RELEASE

com.spotify

docker-maven-plugin

1.0.0

${project.artifactId}

1.0.1

src/main/docker

/

${project.build.directory}

${project.build.finalName}.jar

接着是简单的controller和启动类:

@RestController

@RequestMapping(value = “/test”)

public class TestController {

@GetMapping(value = “/do-test”)

public String doTest(){

System.out.println(“this is a test”);

return “success”;

}

}

@SpringBootApplication

public class WebApplication {

public static void main(String[] args) {

SpringApplication.run(WebApplication.class);

}

}

编写Dockerfile的脚本:

FROM openjdk:8-jdk-alpine

VOLUME /tmp

#将springboot-k8s-template.jar复制到容器内部 并且别名叫springboot-k8s-template-v1.jar

ADD springboot-k8s-template.jar springboot-k8s-template-v1.jar

#相当于在容器中用cmd命令执行jar包 指定外部配置文件

ENTRYPOINT [“java”,“-Djava.security.egd=file:/dev/./urandom”,“-jar”,“/springboot-k8s-template-v1.jar”]

然后进入到Dockerfile的目录底下,进行镜像的构建:

【idea @ Mac】>>>>>>docker build -t springboot-k8s-template:1.0 .

[+] Building 0.5s (7/7) FINISHED

=> [internal] load build definition from Dockerfile 0.0s

=> => transferring dockerfile: 419B 0.0s

=> [internal] load .dockerignore 0.0s

=> => transferring context: 2B


本文转载自: https://blog.csdn.net/2301_79835671/article/details/137268979
版权归原作者 quwdjasd 所有, 如有侵权,请联系我们删除。

“K8S 部署 SpringBoot 项目(一篇够用)”的评论:

还没有评论