目录
应用springbootdemo.yaml创建deployment
前提条件
- 拥有Kubernetes集群环境,可参考:Kubernetes集群搭建
- 掌握Docker镜像知识,可参考:Docker镜像的使用
- 理解Kubernetes基本部署知识,可参考:使用Kubernetes部署第一个应用
- 有一定的Java、Spring Boot编程基础
新建Spring Boot项目并编写一个接口
新建Spring Boot项目及编写相关功能,这里编写一个Hello World接口。
环境说明:jdk8+, maven3+, IDEA2022
新建Maven工程
打开IDEA,File–>New,新建Maven项目,项目名称例如springbootdemo
导入 Spring Boot 相关的依赖
在该 Maven 项目的 pom.xml 中添加以下配置,在 一行之前添加Spring Boot 相关的依赖及打包插件。
<!-- 打包格式 -->
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<!-- 打包插件 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
<layout>JAR</layout>
</configuration>
<executions>
<execution>