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                                                          

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值