使用gitlab的ci/cd自动将应用部署到rancher中
本文主要介绍如何使用gitlab的ci/cd自动发布应用到rancher
rancher 2.0的安装,请参考官方文档
本文中使用的rancher版本必须是2.0以上, 需要获取集群下某个项目的id, 用户的token,集群的地址三个参数。
获取rancher集群下某个项目的id
创建一个key用于登录到rancher集群中
获取rancher里面集群的地址
Gitlab 的runner的安装,请自行解决
下面讲述两种方式部署,任选一种即可
前置说明
本文介绍的应用项目均为java应用,使用maven作为依赖管理,构建镜像使用的是com.google.cloud.tools插件通过maven命令自动构建镜像到远程镜像仓库,
pom.xml文件的jib-maven-plugin插件配置
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<from>
<image>来源镜像,基于哪个镜像打包,比如JDK8</image>
</from>
<to>
<!-- 构建的镜像名称含私有仓库的地址,后续需要这个镜像名称,一般tag建议使用gitlab的CI_PIPELINE_ID作为镜像的tag,方便后续的处理 -->
<image>127.0.0.1:4000/demo/demo:${image_tag}</image>
<auth>
<!-- 私有镜像仓库的用户名和密码 -->
<username>${registry_username}</username>
<password>${registry_password}</password>
</auth>
</to>
<allowInsecureRegistries>true</allowInsecureRegistries>
<container>
<jvmFlags>
<jvmFlag>-Djava.security.edg=file:/dev/./urandom</jvmFlag>
</jvmFlags>