基于k8s的微服务一键部署解决方案

父项目msagd配置

  1. 编写pom.xml的属性标签<properties></properties>

     <properties>
    	  <!--私有docker仓库地址:ip:port-->
     	  <docker.image.host>docker.io</docker.image.host>
          <!--镜像前缀,随便取(命名空间)-->
          <docker.image.prefix>13711919653</docker.image.prefix>
     </properties>
     
    
  2. 编写pom.xml的构建标签<pluginManagement></pluginManagement>

    在父项目中编写dockerfile插件的配置管理,子项目按需引入插件依赖即可

     <build>
          <pluginManagement>
                <plugins>
                    <plugin>
                        <!--插件依赖-->
                        <groupId>com.spotify</groupId>
                        <artifactId>dockerfile-maven-plugin</artifactId>
                        <version>1.4.13</version>
                        <executions>
                            <!--通过mvn package 将会执行docker构建、tag、推送功能-->
                            <execution>
                                <id>tag-version</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>build</goal>
                                    <goal>tag</goal>
                                   <goal>push</goal>
                                </goals>
                                <configuration>
                                    <!--项目版本号作镜像标签号-->
                                    <tag>${project.version}</tag>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <!--使用maven的setting.xml方式配置授权-->
                            <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
                            <googleContainerRegistryEnabled>false</googleContainerRegistryEnabled>
                            <!--授权的账号密码,经测试不起作用-->
                            <!--<username>myname</username>-->
                            <!--<password>mypassword</password>-->
                            <!--docker私有仓库地址-->
                            <repository>${docker.image.host}/${docker.image.prefix}/${project.artifactId}</repository>
                            <!--上下文中dockerfile名称-->
                            <dockerfile>Dockerfile</dockerfile>
                            <!--dockerfile上下文路径-->
                            <contextDirectory>${project.basedir}</contextDirectory>
                            <!--项目版本号作镜像标签号-->
                            <tag>${project.version}</tag>
                            <!--构建参数-->
                            <buildArgs>
                                <!--传递到Dockerfile中的参数:jar包名称-->
                                <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
                            </buildArgs>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
     </build>
    

子项目msa-xxx配置

  1. 编写pom.xml的构建标签<plugin></plugin>

    <!--docker插件依赖-->
    <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>dockerfile-maven-plugin</artifactId>
    </plugin>
    
  2. 项目根目录上编写Dockerfile文件

    FROM openjdk:8-jre-stretch
    #配置文件上传递过来的jar包名称
    ARG JAR_FILE
    COPY  ${JAR_FILE} app.jar
    #端口暴露
    EXPOSE 1000
    ENTRYPOINT ["java", "-jar","-Xms1024m","-Xmx1024m","-Xss1024K","-XX:MetaspaceSize=512m","-XX:MaxMetaspaceSize=512m","app.jar"]
    #active
    CMD ["--spring.profiles.active=k8s"]
    

    Dockerfile上下文环境如图所示
    在这里插入图片描述

使用mvn一键部署docker镜像

  1. 离线环境安装apache-maven3.6.2

    #安装wget命令
    yum -y install wget
    #下载maven安装包
    wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz
    #解压缩
    tar -zxvf apache-maven-3.6.2-bin.tar.gz 
    #配置maven环境变量
    vi /etc/profile
    export MAVEN_HOME=/var/local/apache-maven-3.6.2
    export MAVEN_HOME
    export PATH=$PATH:$MAVEN_HOME/bin
    #环境变量立即生效
    source /etc/profile
    
  2. 编写maven的setting.xml的server标签<server></server>

    <servers>
    	 <server>
    	 	<!--私有docker仓库地址:ip:port-->
    	    <id>docker-repo.example.com:8080</id>
    	    <!--docker仓库用户名-->
    	    <username>me</username>
    	    <!--docker仓库密码-->
    	    <password>mypassword</password>
    	  </server>
     <servers>
    
  3. 设置版本编号 mvn versions:set -DnewVersion=x.x.x(不需要可不运行)

  4. 开始一键部署 mvn package

编写k8s部署文件

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值