Contents
打包部署service-sysmanage服务镜像
新建分支与仓库
新建本地分支
git checkout develop
git checkout -b jtest
新建远程仓库
gitee新建私有仓库service-sysmanage
上传分支
git remote add jingmin https://gitee.com/ole12138/service-sysmanage.git
git push -u jingmin "jtest"
git push -u jingmin master:master
git push -u jingmin develop:develop
调整springcloud的bootstrap.yml
# 服务名
spring.application.name=SERVICE-SYSMANAGE
# 端口
server.port=5000
#spring.cloud.nacos.server-addr=nacos.c253e0c129d8f453a82dfb1ae4ba19613.cn-shenzhen.alicontainer.com:80
spring.cloud.nacos.server-addr=nacos-headless.nacos.svc.cluster.local:8848
spring.cloud.nacos.discovery.group=woyun
spring.cloud.nacos.discovery.namespace=765fa359-2e1b-41f3-a4b2-17c3856764fe
spring.cloud.nacos.config.namespace=765fa359-2e1b-41f3-a4b2-17c3856764fe
spring.cloud.nacos.config.group=woyun
spring.cloud.nacos.config.shared-configs[0].data-id=application.properties
spring.cloud.nacos.config.shared-configs[0].group=woyun
spring.cloud.nacos.config.shared-configs[1].data-id=mysql-sysmanage.properties
spring.cloud.nacos.config.shared-configs[1].group=woyun
spring.cloud.nacos.config.shared-configs[2].data-id=rabbitmq.properties
spring.cloud.nacos.config.shared-configs[2].group=woyun
spring.cloud.nacos.config.shared-configs[3].data-id=redis.properties
spring.cloud.nacos.config.shared-configs[3].group=woyun
spring.cloud.config.profile=${config.profile:dev}
# 每个节点的workerId不同,datacenterId示集群而定
# 即:同一服务的不同节点,workerId不同;不同服务的节点workerId也不相同
application.workerId=0
application.datacenterId=0
#阿里云 ACM
spring.application.group=com.bmp.cloud.acm
alibaba.acm.endpoint=acm.aliyun.com
alibaba.acm.namespace=xxx
alibaba.acm.accessKey=xxx
alibaba.acm.secretKey=xxx
alibaba.acm.group=com.bmp.cloud.acm
提交git
调整nacos中相应配置文件
确保相应组件已经安装(mysql,rabbitmq,redis)
数据库账号
根据nacos中的配置添加数据库和数据库账号
GRANT ALL PRIVILEGES ON *.* TO 'bmp'@'%' IDENTIFIED BY 'xxx' WITH GRANT OPTION;
telepresence连接k8s本地调试(要先配好kubectl,安装telepresence工具)
telepresence connect
ide中调试通过
Jenkins中配置镜像发布
配置pipeline
新建pipeline,名称service-sysmanage
通用选项:
Discard old builds: Max of builds to keep: 2
Project is parameterized: Choice Parameter: branchName **/jtest
Pipeline定义:
Pipeline script from SCM
SCM: Git
SCM-Repositories-Repository URL: https://gitee.com/ole12138/delopy-k8s.git
SCM-Repositories-Credentials: 18306849443/******
SCM-Branches to build: */jtest
SCM-Additional Behaviours-Sparse Checkout paths: service/jtest/Jenkinsfile
SCM-Additional Behaviours-Check out to a sub-directory: jenkins
Script Path: service/jtest/Jenkinsfile
保存,应用
Dashbord->service-sysmanage->Build with Parameters, 尝试构建与部署。
配置k8s.yaml模板
Config File Provider插件配置
Dashboard->Mange Jenkins->Managed Files->Add a new Config->Custom file
随机生成了一个id bad53479-629f-40c9-af73-713a09515afe
Name k8s.yaml
k8s.yaml
apiVersion: apps/v1
kind: Deployment
##元数据信息
metadata:
name: <PROJECT_NAME>
##命名空间
namespace: <NAME_SPACE>
labels:
app: <PROJECT_NAME>
spec:
selector:
matchLabels:
app : <PROJECT_NAME>
##设置历史版本数量
revisionHistoryLimit: 2
##滚动升级策略
##Kubernetes在等待设置的时间后才进行升级
minReadySeconds: 5
strategy:
# type: Recreate
type: RollingUpdate
rollingUpdate:
## 升级过程最多可以比原先设置多出的POD数量 Kubernetes会先启动1一个新的Pod后才删掉一个旧的
maxSurge: 1
## 升级过程中最多有多少个POD处于无法提供服务的状态
maxUnavailable: 1
##代表2个副本
replicas: 1
template:
metadata:
labels:
app: <PROJECT_NAME>
spec:
#affinity:
# nodeAffinity:
# requiredDuringSchedulingIgnoredDuringExecution:
# nodeSelectorTerms:
# - matchExpressions:
# - key: node_env
# operator: In
# values:
# - jtest
##重启策略
# Always:当容器失效时,由kubelet自动重启该容器。
# OnFailure:当容器终止运行且退出码不为0时,由kubelet自动重启该容器。
# Never:不论容器运行状态如何,kubelet都不会重启该容器。
restartPolicy: Always
##挂载容器外面
# volumes:
# - name: <PROJECT_NAME>-log
# hostPath:
## type: Directory
# path: /applogs/<NAME_SPACE>
#volumes:
# - name: pay-cert
# configMap:
# name: pay-cert
containers:
##容器名称
- name: <PROJECT_NAME>-container
##镜像拉取策略
imagePullPolicy: Always
##容器镜像地址
image: harbor.ole121238.cn/<repoNamespace>/<PROJECT_NAME>:<BUILD_TAG>
## 环境变量设置
env:
- name: TZ
value: Asia/Shanghai
##元数据获取POD名称到环境变量
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: SRV_NAME
value: <PROJECT_NAME>
# lifecycle:
# postStart:
# exec:
# command:
# - /bin/sh
# - '-c'
# - >-
# rm -rf /applogs &&
# mkdir -p /home/mount/<NAME_SPACE>/${POD_NAME} && ln -s
# /home/mount/<NAME_SPACE>/${POD_NAME}
# /applogs
## containerPort 容器监听端口 、hostPort 容器所在主机监听端口
ports:
- name: <PORT_NAME>-con-port
containerPort: <projectPort>
##挂载容器
# volumeMounts:
# - mountPath: /home/mount/<NAME_SPACE>
## subPath: server-zuul.log
# name: <PROJECT_NAME>-log
#volumeMounts:
# - mountPath: /mnt/bmpapps/service-pay
# name: pay-cert
##资源限制和请求限制
resources:
##请求限制容器启动的初始可用CPU/内存
requests:
memory: <REQUEST_MEMORY>
cpu: <REQUEST_CPU>
##资源请求限制
limits:
memory: <LIMIT_MEMORY>
cpu: <LIMIT_CPU>
##健康检查
#(就绪检查)可读探针会去连接容器的8067端,如果连接成功,则该 Pod 将被标记为就绪状态。
#然后Kubelet将每隔10秒钟执行一次该检查
readinessProbe:
tcpSocket:
port: <projectPort>
##指定kubelet在该执行第一要等待5秒钟。
initialDelaySeconds: 30
periodSeconds: 20
timeoutSeconds: 5
##(存活检查)存活探针容器启动15秒后,去尝试连接容器的8067端,如果liveness probe失败,容器将重新启动
livenessProbe:
tcpSocket:
port: <projectPort>
initialDelaySeconds: 360
periodSeconds: 30
timeoutSeconds: 5
---
#添加自动弹性扩缩容
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: <PROJECT_NAME>-autoscal
namespace: <NAME_SPACE>
spec:
maxReplicas: 2
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: <PROJECT_NAME>
targetCPUUtilizationPercentage: 80
deploy-k8s项目中,调整 service/jtest/Jenkinsfile
中对应位置的文件id为上面得到的 bad53479-629f-40c9-af73-713a09515afe
提交git。
上传依赖
显然,前面的jenkins 构建部署会失败。 因为有些依赖jar还没上传到nexus。
本地mvn deploy配置
前面配过maven的settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!--
<proxies>
<proxy>
<id>local-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>127.0.0.1</host>
<port>10809</port>
<!--
<username>***</username>
<password>***</password>
-->
<nonProxyHosts>
*.ole12138.cn|localhost</nonProxyHosts>
</proxy>
</proxies>
-->
<servers>
<server>
<id>ole12138-maven-public</id>
<username>java</username>
<password>Java12345</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-public-mirror</id>
<name>public Repository</name>
<url>https://nexus.ole12138.cn/repository/maven-public/</url>
<mirrorOf>nexus-public</mirrorOf>
</mirror>
<mirror>
<id>nexus-thirdparty-mirror</id>
<name>Third Party Repository</name>
<url>https://nexus.ole12138.cn/repository/thirdparty/</url>
<mirrorOf>nexus-thirdparty</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>repo-ole12138-maven-public</id>
<!--
这里的 repositories 如果不配置的话,默认会有一个 Maven 中央仓库的配置,
同样 pluginRepositories 中如果没有配置的话,默认也是有一个 Maven 中央仓库的配置。
所以如果只配置了私服的 repository 情况下,就会先去私服中下载,私服中下载不到时再去追加上来的 Maven 中央仓库中下载
-->
<!-- 配置的顺序决定了下载 jar 包的顺序 -->
<repositories>
<repository>
<id>ole12138-maven-public</id>
<url>https://nexus.ole12138.cn/repository/maven-public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>ole12138-maven-public</id>
<url>https://nexus.ole12138.cn/repository/maven-public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
<!-- 默认上传artifact的仓库位置 -->
<!-- how-to-specify-mavens-distributionmanagement-organisation-wide -->
<!-- https://stackoverflow.com/questions/3298135/how-to-specify-mavens-distributionmanagement-organisation-wide -->
<!-- https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html#optional-parameters -->
<properties>
<altSnapshotDeploymentRepository>ole12138-maven-public::default::https://nexus.ole12138.cn/repository/maven-snapshots/</altSnapshotDeploymentRepository>
<altReleaseDeploymentRepository>ole12138-maven-public::default::https://nexus.ole12138.cn/repository/maven-releases/</altReleaseDeploymentRepository>
</properties>
</profile>
</profiles>
<activeProfiles>
<!-- 激活环境配置 ,使上面的配置生效 -->
<activeProfile>repo-ole12138-maven-public</activeProfile>
</activeProfiles>
</settings>
主要注意下,profile中altSnapshotDeploymentRepository和altReleaseDeploymentRepository的配置。
以及对应id的server账号配置。
上传源码和javadoc配置(可选)
如果想要上传源码与Javadoc
参考: https://developer.aliyun.com/article/585151
修改xframework-parent的pom文件
<!-- 所有服务的父工程: -->
<!-- 1-继承spring-boot-starter-parent; -->
<!-- 2-引入所有工程都需要的包,如:spring-boot-starter-test; -->
<!-- 3-管理所有依赖的版本,子工程只需要指定所需依赖的artifactId; -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- ... -->
<build>
<!-- ... -->
<!--配置生成Javadoc包-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<!--<aggregate>true</aggregate>-->
<charset>UTF-8</charset>
<docencoding>UTF-8</docencoding>
<!-- https://stackoverflow.com/questions/52547306/maven-javadoc-plugin-not-accepting-additionalparam-xdoclintnone-additionalpa -->
<doclint>none</doclint>
<!--<doclint>all,-missing,-syntax,-reference,-accessibility</doclint>-->
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!--配置生成源码包-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
可能遇到idea无法立即发现source的问题
这种情况手动执行一下:
mvn dependency:resolve -Dclassifier=sources
手动选一下源码位置
上传xframework-localmessage依赖
前面jenkins 构建部署失败了。 console output中有相关提示:
...
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project service-sysmanage: Could not resolve dependencies for project com.x.bmp:service-sysmanage:jar:2.0.0-RELEASE: Failed to collect dependencies at xframework:xframework-localmessage:jar:2.0.1-RELEASE
...
显然,需要打包上传xframework:xframework-localmessage:jar:2.0.1-RELEASE
到nexus。
新建分支与仓库
本地新建分支jtest
git checkout -b jtest master
gitee新建仓库,创建好的仓库地址为
https://gitee.com/ole12138/xframework-localmessage.git
本地分支jtest设置上游分支,并push到新仓库
# 添加远程地址
git remote add jingmin https://gitee.com/ole12138/xframework-localmessage.git
# jtest分支设置上游分支,并推送
git push -u jingmin jtest
# 推送所有(本地)分支到新仓库
#git push --all jingmin
# 推送所有分支到新仓库(会多个HEAD临时分支)
git push jingmin +refs/remotes/origin/*:refs/heads/*
参考链接:https://blog.csdn.net/bingyu9875/article/details/84841521
Git 一次性 pull push 所有的分支 /********************************************************************************* Git 一次性 pull push 所有的分支
说明: 使用Git一次性推送所有的分支,之前一般都是单独推送一个分支,现在是多分支操作,可能涉及到多分支推送,得找个办法解决。 ********************************************************************************/
一、参考文档:
Push local Git repo to new remote including all branches and tags http://stackoverflow.com/questions/6865302/push-local-git-repo-to-new-remote-including-all-branches-and-tags
Set up git to pull and push all branches http://stackoverflow.com/questions/1914579/set-up-git-to-pull-and-push-all-branches
二、解决办法:
push
git push REMOTE '*:*'
git push REMOTE --all
git push --all origin
根据需要使用以上命令
pull
- git fetch –all
- git pull –all
部署到nexus
调整一下parent
<parent>
<groupId>xframework</groupId>
<artifactId>xframework-parent</artifactId>
<version>2.0.2</version>
</parent>
最新的parent版本已经是2.0.2了
打包并上传依赖到nexus
mvn deploy -U -X
上传xframework-datapermission依赖
jenkins项目还是构建失败。 console output 有相关内容:
...
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project service-sysmanage: Could not resolve dependencies for project com.x.bmp:service-sysmanage:jar:2.0.0-RELEASE: Failed to collect dependencies at xframework:xframework-datapermission:jar:2.0.1-RELEASE
...
新建分支与仓库
本地新建分支jtest
git checkout -b jtest master
gitee新建仓库,创建好的仓库地址为
https://gitee.com/ole12138/xframework-datapermission.git
本地分支jtest设置上游分支,并push到新仓库
# 添加远程地址
git remote add jingmin https://gitee.com/ole12138/xframework-datapermission.git
# jtest分支设置上游分支,并推送
git push -u jingmin jtest
# 推送所有(本地)分支到新仓库
#git push --all jingmin
# 推送所有分支到新仓库(会多个HEAD临时分支)
git push jingmin +refs/remotes/origin/*:refs/heads/*
参考链接:https://blog.csdn.net/bingyu9875/article/details/84841521
部署到nexus
调整一下parent
<parent>
<groupId>xframework</groupId>
<artifactId>xframework-parent</artifactId>
<version>2.0.2</version>
</parent>
最新的parent版本已经是2.0.2了
打包并上传依赖到nexus
mvn deploy -U -X
删除依赖com.x.bmp:ali-api
jenkins部署还是有报错。如下所示
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project service-sysmanage: Could not resolve dependencies for project com.x.bmp:service-sysmanage:jar:2.0.0-RELEASE: Failed to collect dependencies at com.x.bmp:ali-api:jar:1.0.0
需要打包com.x.bmp:ali-api:jar:1.0.0
上传到nexus
看了下,是为了调用一个第三方的实名认证接口https://market.aliyun.com/products/57000002/cmapi026109.html?spm=5176.2020520132.101.1.2ff87218yGCZTl#sku=yuncode2010900004
在IdCardCheckHttpsApiClient中用到了这个jar。
实际上,完全没必要,直接用其他http工具重写一下这个接口,也可以暂且注掉相关逻辑。
目前是直接删除了依赖,注掉了相关逻辑。
重新触发jenkins构建,成功
发表回复