k8s jenkins CICD 流程
首先集群搭好gitlab
jenkins Role-based Authorization Strategy 权限管理。 Multiple SCMs
复制.kube下的config文件
1. gitlab jenkisn 关联webhook配置好在gitlab。
加入jenkisnURL http://112.125.24.208:8098/project/spic
和 Secret Token 做webhook关联。
jenkins配置
2. 拉取代码
http://112.125.24.208:8099/wangyao/np_asset.git
3. 编译jar包
mvn clean
mvn package -Pprod
4. dockerfile 加入代码包,制作镜像。打标签
5. 推镜像到harbor
6. 下载yaml项目
7. sed 修改yaml 参数
8. 复制.kube文件下的config文件,kubectl apply -f 执行文件
9. commit push 改变的yaml
#!/bin/bash
sj=$(date +"%Y%m%d-%H%M%S")
docker build -t 172.17.250.186/asset-app/user-server:"${sj}" /mnt/dockerfile/asset-app/user-server
docker push 172.17.250.186/asset-app/user-server:"${sj}"
docker build -t 172.17.250.186/asset-app/sms-server:"${sj}" /mnt/dockerfile/asset-app/sms-server
docker push 172.17.250.186/asset-app/sms-server:"${sj}"
docker build -t 172.17.250.186/asset-app/app-product:"${sj}" /mnt/dockerfile/asset-app/business-product
docker push 172.17.250.186/asset-app/app-product:"${sj}"
docker build -t 172.17.250.186/asset-app/app-discover:"${sj}" /mnt/dockerfile/asset-app/business-discover
docker push 172.17.250.186/asset-app/app-discover:"${sj}"
docker build -t 172.17.250.186/asset-app/app-home:"${sj}" /mnt/dockerfile/asset-app/business-home
docker push 172.17.250.186/asset-app/app-home:"${sj}"
docker build -t 172.17.250.186/asset-app/app-h5:"${sj}" /mnt/dockerfile/asset-app/h5
docker push 172.17.250.186/asset-app/app-h5:"${sj}"
docker build -t 172.17.250.186/asset-app/seal-sign:"${sj}" /mnt/dockerfile/asset-app/seal-sign
docker push 172.17.250.186/asset-app/seal-sign:"${sj}"
/opt/kubernetes/bin/kubectl delete -f /root/yaml-k8s/
sed -i "s#$(egrep 172.17.250.186 /root/yaml-k8s/app-deploy-discover.yaml)# image: 172.17.250.186/asset-app/app-discover:${sj}#g" /root/yaml-k8s/app-deploy-discover.yaml
sed -i "s#$(egrep 172.17.250.186 /root/yaml-k8s/app-deploy-home.yaml)# image: 172.17.250.186/asset-app/app-home:${sj}#g" /root/yaml-k8s/app-deploy-home.yaml
sed -i "s#$(egrep 172.17.250.186 /root/yaml-k8s/app-deploy-product.yaml)# image: 172.17.250.186/asset-app/app-product:${sj}#g" /root/yaml-k8s/app-deploy-product.yaml
sed -i "s#$(egrep 172.17.250.186 /root/yaml-k8s/app-deploy-sms.yaml)# image: 172.17.250.186/asset-app/sms-server:${sj}#g" /root/yaml-k8s/app-deploy-sms.yaml
sed -i "s#$(egrep 172.17.250.186 /root/yaml-k8s/app-deploy-user.yaml)# image: 172.17.250.186/asset-app/user-server:${sj}#g" /root/yaml-k8s/app-deploy-user.yaml
sed -i "s#$(egrep 172.17.250.186 /root/yaml-k8s/app-h5.yaml)# image: 172.17.250.186/asset-app/app-h5:${sj}#g" /root/yaml-k8s/app-h5.yaml
sed -i "s#$(egrep 172.17.250.186 /root/yaml-k8s/seal-sign.yaml)# image: 172.17.250.186/asset-app/seal-sign:${sj}#g" /root/yaml-k8s/seal-sign.yaml
/opt/kubernetes/bin/kubectl apply -f /root/yaml-k8s/
[root@scandev /mnt/np_asset_test/np_asset/src/app/business/home/entry]# cat /etc/systemd/system/asset.service [Unit] #此部分主要用于描述 Description=jar Server After=network.target #描述服务类别 [Service] #关键部分 Type=forking #代表后台运行 #Restart=on-failure #程序pid文件 ExecStart=/mnt/zc/jarStart.sh ExecStop=`/usr/bin/pkill java;sleep 1;pkill java` #启动命令 #停止命令 RestartSec=10s
[root@iZ2zeh7i9iup2cks04jfa3Z system]# cat logstash.service
[Unit]
Description=logstash
[Service]
Type=simple
User=root
Group=root
# Load env vars from /etc/default/ and /etc/sysconfig/ if they exist.
# Prefixing the path with '-' makes it try to load, but if the file doesn't
# exist, it continues onward.
EnvironmentFile=-/etc/default/logstash
EnvironmentFile=-/etc/sysconfig/logstash
ExecStart=/usr/share/logstash/bin/logstash "--path.settings" "/etc/logstash"
Restart=always
WorkingDirectory=/
Nice=19
LimitNOFILE=16384
# When stopping, how long to wait before giving up and sending SIGKILL?
# Keep in mind that SIGKILL on a process can cause data loss.
TimeoutStopSec=infinity
[Install]
WantedBy=multi-user.target