四、idea部署springboot 项目到k8s
1、前提条件
- k8s 集群已搭建好(搭建教程)
- harbor镜像仓库私服已搭建好(搭建教程)
- harbor ssl 配置好了(配置教程)
- 本地配置harbor镜像仓库认证配置(配置教程)
- 本地安装kubectl、skaffold环境(教程)
- 根据项目在idea中配置好相应的skaffold.yml、deployment.yml、service.yml,如图
注意:文件后缀名一定要是yml,不能是yaml,因为idea中高版本google cloud code插件不识别yaml,如图:
2、开始部署
2.1 项目中引入google-jib插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<from>
<image>wp.cxdlczl.cn/wp/jdk:8-jdk-alpine</image>
<auth>
<username>username</username>
<password>password</password>
</auth>
</from>
<!-- 最后生成的镜像配置 -->
<to>
<image>wp.cxdlczl.cn/wp/${project.name}:${project.version}</image>
<auth>
<username>username</username>
<password>password</password>
</auth>
</to>
<container>
<mainClass>cn.talabi.monitor.MonitorApplication</mainClass>
</container>
<allowInsecureRegistries>true</allowInsecureRegistries>
</configuration>
</plugin>
2.2 idea 添加google cloud code 插件
file -> settings -> plugins