发布部署应用

字数 481阅读 13

jenkins新建立一个new Item ,点击构建一个maven项目

勾选Discard old builds后填入如下:

勾选This project is parameterized后填入如下:

配置GIT地址

https://github.com/ruanch/SpringBootDemo.git


配置MAVEN脚本命令

clean package

增加构建后的配置脚本:

#!/bin/sh

jarName=spring-boot-demo-0.0.1-SNAPSHOT.jar

jarFolder=ph

projectName=ph

docker_path=${WORKSPACE}

cp ${WORKSPACE}/target/${javName} ${docker_path}

sh /root/docker_dir/deploy_docker.sh ${projectName} ${docker_path} ${jarName}


在/root/docker_dir/deploy_docker.sh中写入:

#!/bin/sh

#maven01 $workspace $jarname

#${projectName} ${docker_path} ${jarName}

set -e

projectName=$1

docker_path=$2

appName=$3

#user_name=

#password=

tag=$(date +%s)

server_path=10.20.16.146:5000

target_image=${projectName}:${tag}

#${BUILD_NUMBER}

echo ${target_image}

cd ${docker_path}

docker build --build-arg app=${appName} -t ${target_image} .

docker tag ${target_image} ${server_path}/${projectName}

echo The name of image is "${server_path}\/${target_image}"

docker push ${server_path}/${projectName}:latest

docker rmi -f $(docker images | grep ${projectName} | grep ${tag} |awk '{print $3}' | head -n 1)


NODE服务器免密登录到Master机器上:

ssh-keygen -t rsa

ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.20.17.177

如果出现root无法登录执行以下命令

apt-get install -y openssh-server

vim /etc/ssh/sshd_config

将PermitRootLogin 的值改为yes

PermitEmptyPasswords为 no

systemctl restart ssh.service



在jenkins项目中增加shell脚本.

把jar包中的yaml文件传到master服务器并启动

set -e

echo ok

echo ${WORKSPACE}

docker_path=${WORKSPACE}

scp ${WORKSPACE}/*.yaml 10.20.17.177:/root/

ssh 10.20.17.177 '/opt/bin/kubectl apply -f /root/kube.yaml'

ssh 10.20.17.177 'opt/bin/kubectl get svc|grep maven'

会报

Step 1/4 : FROM registry-scu.cloudtogo.cn/ubuntu:jdk

Gethttps://registry-scu.cloudtogo.cn/v2/: dial tcp 106.75.145.94:443: connect: connection refusedBuild step 'Execute shell' marked build as failure

写入vim /etc/docker/daemon.json

加入registry-scu.cloudtogo.cn

然后执行重启一下docker

systemctl daemon-reload

systemctl restart docker

查看master结点状态情况:

swapoff -a (NODE没有ready的情况结点上面关掉)

sudo kubectl get node

kubectl get po --all-namespaces|grep maven

kubectl describe po maven-deployment-d974b777-9kdk5 -n default



最后发布成功了。访问31002端口即可: