K8S-持续集成实践

镜像:

vi  dockerfile
FROM 10.0.0.11:5000/nginx:1.13
ADD . /usr/share/nginx/html

vi  .dockerignore 
dockerfile

docker build -t xiaoniao:v1 .
docker run -d -p 88:80 xiaoniao:v1

jenkins:

使用jenkins环境变量
BUILD_ID

修改构建后脚本为
docker build  -t 10.0.0.11:5000/xiaoniao:v$BUILD_ID  .
docker push 10.0.0.11:5000/xiaoniao:v$BUILD_ID 

构建一个deployment命令:

kubectl run xiaoniao --image=10.0.0.11:5000/xiaoniao:v1 --replicas=2 --record 

提供一个端口访问,即创建一个svc,执行对应deployment:

kubectl expose deployment xiaoniao --port=80 --type=NodePort

版本更新,更新镜像:

kubectl set image deploy xiaoniao xiaoniao=10.0.0.11:5000/xiaoniao:v3

查看历史版本:

kubectl rollout history deployment xiaoniao 

版本回滚:

kubectl rollout undo deploy xiaoniao    #回退到上一版本

 kubectl rollout undo deploy nginx --to-revision=1    #回退到指定1记录

jenkins实现版本升级:

if [ $GIT_PREVIOUS_SUCCESSFUL_COMMIT == $GIT_COMMIT ];then
     echo "no change,skip build"
     exit 0
else
     echo "git pull commmit id not equals to current commit id trigger build"
     docker build  -t 10.0.0.11:5000/xiaoniao:v$BUILD_ID  .
     docker push 10.0.0.11:5000/xiaoniao:v$BUILD_ID
     kubectl -s 10.0.0.11:8080 set image deploy xiaoniao xiaoniao=10.0.0.11:5000/v$BUILD_ID 
fi

你可能感兴趣的:(ci,docker,nginx)