今天搞了一下Jenkins和Docker的结合,我在想几个问题:

  • 构建是经常的,构建最大的目标还是生成一个包或者应用
  • 发布应用也是频繁的,发布本质上是把这个包放到可运行的环境中便于测试
  • 如果每次构建我们都需要去Build一个环境,包括配置连接池等和应用相关的资源的话,那就太消耗时间和CPU了
  • 在日常项目中更多的变动应该还是在代码上,因此考虑的就是把针对某个项目的环境发布成一个images,然后基于这个images进行应用代码的发布。

基于这种考虑就没必要每次构建通过Jenkins基于Dockfile去build image,而应该尽量采用事先构建的images模板。

把Jenkins作为kubernetes pod来用今天也尝试了一下,无奈虚拟环境性能不行放弃,我个人感觉放在kubernetes集群外运行就可以了,没必要放进去作为Pod来统一管理。

Kubernetes还是专门作为一个应用运行环境,而不是发布构建持续集成的环境比较好点 :)

基于上次的maven project,改造了一下把应用部署到kubernetes环境中的WebLogic Pod。当然只能做功能测试,如果性能测试的话,我还要考虑考虑。

项目的脚本部分改动

project=easy-springmvc-maven
war_name=easy-springmvc-maven.war
war_path=http://192.168.0.104:8080/jenkins/job/jeekins-test/ws/target
file_path=/home/ericnie/.jenkins/workspace/jenkins_test/target/ now=$(date +"%Y%m%d%H%M%S")
echo "============begin weblogic pod check========"
echo "the shell execute time is ${now}" weblogic_num=`kubectl get pods | grep helloworld-service | wc -l` if [ "${weblogic_num}" == "" ]; then
kubectl delete -f /home/ericnie/rc.yaml
echo "delete the weblogic pod"
fi sleep 20s
echo "==========create weblogc pod==========="
kubectl create -f /home/ericnie/rc.yaml
sleep 10s
weblogic_ip=`kubectl get pods -o wide | grep helloworld-service | grep Running | awk '{for(i =1; i <=NF; i++){ if($i~/[0-9]\.[0-9]/) print $i}}'`
echo "weblogic ip is ${weblogic_ip}" sleep 60s
echo "==========deploy the application========"
java -cp /home/ericnie/Middleware/wlserver/server/lib/weblogic.jar weblogic.Deployer -adminurl t3://${weblogic_ip}:7001 -user weblogic -password welcome1 -name ${war_name} -targets AdminServer -deploy -upload -source ${file_path}/${war_name} echo "=========job finish,you can acess!======"

jenkins console输出

[jenkins_test] $ /bin/sh -xe /tmp/jenkins7532164656453389066.sh
+ project=easy-springmvc-maven
+ war_name=easy-springmvc-maven.war
+ war_path=http://192.168.0.104:8080/jenkins/job/jeekins-test/ws/target
+ file_path=/home/ericnie/.jenkins/workspace/jenkins_test/target/
++ date +%Y%m%d%H%M%S
+ now=
+ echo '============begin weblogic pod check========'
============begin weblogic pod check========
+ echo 'the shell execute time is 20171031153657'
the shell execute time is
++ kubectl get pods
++ grep helloworld-service
++ wc -l
+ weblogic_num=
+ '[' == ']'
+ kubectl delete -f /home/ericnie/rc.yaml
replicationcontroller "helloworld-service" deleted
service "helloworldsvc" deleted
+ echo 'delete the weblogic pod'
delete the weblogic pod
+ sleep 20s
+ echo '==========create weblogc pod==========='
==========create weblogc pod===========
+ kubectl create -f /home/ericnie/rc.yaml
replicationcontroller "helloworld-service" created
service "helloworldsvc" created
+ sleep 10s
++ kubectl get pods -o wide
++ grep helloworld-service
++ grep Running
++ awk '{for(i =1; i <=NF; i++){ if($i~/[0-9]\.[0-9]/) print $i}}'
+ weblogic_ip=10.0.35.3
+ echo 'weblogic ip is 10.0.35.3'
weblogic ip is 10.0.35.3
+ sleep 60s
+ echo '==========deploy the application========'
==========deploy the application========
+ java -cp /home/ericnie/Middleware/wlserver/server/lib/weblogic.jar weblogic.Deployer -adminurl t3://10.0.35.3:7001 -user weblogic -password welcome1 -name easy-springmvc-maven.war -targets AdminServer -deploy -upload -source /home/ericnie/.jenkins/workspace/jenkins_test/target//easy-springmvc-maven.war
weblogic.Deployer invoked with options: -adminurl t3://10.0.35.3:7001 -user weblogic -name easy-springmvc-maven.war -targets AdminServer -deploy -upload -source /home/ericnie/.jenkins/workspace/jenkins_test/target//easy-springmvc-maven.war
<Oct , :: PM CST> <Info> <J2EE Deployment SPI> <BEA-> <Initiating deploy operation for application, easy-springmvc-maven.war [archive: /home/ericnie/.jenkins/workspace/jenkins_test/target/easy-springmvc-maven.war], to AdminServer .>
Task initiated: [Deployer:]deploy application easy-springmvc-maven.war on AdminServer.
Task completed: [Deployer:]deploy application easy-springmvc-maven.war on AdminServer.
Target state: deploy completed on Server AdminServer + echo '=========job finish,you can acess!======'
=========job finish,you can acess!======
Finished: SUCCESS

欢迎提出意见探讨。

Jenkins和Docker以及Kubernetes结合考虑的更多相关文章

  1. Jenkins+GitLab+Docker+SpringCloud+Kubernetes实现可持续自动化微服务

    现有混合云平台的场景下,即有线下和线上的环境,又有测试与正式的场景,而且结合了Docker,导致打包内容有所区分,且服务的发布流程复杂起来,手工打包需要在编译阶段就要根据环境到处更改配置,因此纯手工发 ...

  2. jenkins构建docker镜像上传到harbor并发布到kubernetes

    很早之前写过一篇jenkins集成docker的文章,使用的是CloudBees Docker Build and Publish plugin插件.这篇文章是直接使用shell脚本做的,主要是这次有 ...

  3. Jenkins 与Docker/Kubernetes的自动化CI流水(笔记)

    一.CI/CD 持续集成(continuous Integration,CI):代码合并.构建.部署.测试都在一起.不断执行这个过程,并对结果反馈. 持续部署(Continuous Deploymen ...

  4. Kubernetes笔记(三):Gitlab+Jenkins Pipeline+Docker+k8s+Helm自动化部署实践(干货分享!)

    通过前面两篇文章,我们已经有了一个"嗷嗷待哺"的K8s集群环境,也对相关的概念与组件有了一个基本了解(前期对概念有个印象即可,因为只有实践了才能对其有深入理解,所谓"纸上 ...

  5. Jenkins与Docker相关的Plugin使用

    原文地址:http://blog.csdn.net/ztsinghua/article/details/52128140 Jenkins与Docker相关的Plugin 在Jenkins Plugin ...

  6. Jenkins+Git+Docker+K8s部署

    准备工作 Jenkins已安装 Docker和K8s部署运行成功 代码管理工具使用Git 最近公司项目使用Jenkins+Git+Docker+K8s进行持续化构建部署,这里笔者整理了一下构建部署的相 ...

  7. Docker vs. Kubernetes vs. Apache Mesos: Why What You Think You Know is Probably Wrong

    Docker vs. Kubernetes vs. Apache Mesos: Why What You Think You Know is Probably Wrong - Mesosphere h ...

  8. 【k8s实战一】Jenkins 部署应用到 Kubernetes

    [k8s实战一]Jenkins 部署应用到 Kubernetes 01 本文主旨 目标是演示整个Jenkins从源码构建镜像到部署镜像到Kubernetes集群过程. 为了简化流程与容易重现文中效果, ...

  9. jenkins和docker 使用docker作为slave

    使用docker作为jenkins slave. 文章来自:http://www.ciandcd.com文中的代码来自可以从github下载: https://github.com/ciandcd 参 ...

随机推荐

  1. html5重力感应事件之DeviceMotionEvent

    前言 今天主要介绍一下html5重力感应事件之DeviceMotionEvent,之前我的一篇文章http://www.haorooms.com/post/jquery_jGestures, 介绍了第 ...

  2. 【python】时间戳、字典列表排序

    记录一下昨天学到的知识: 一.文件相关 文件追加:f = open("fname","a")    文件不存在时创建 二.时间戳相关 http://www.jb ...

  3. 【C++】C++11的auto和decltype关键字

    转自: http://www.linuxidc.com/Linux/2015-02/113568.htm 今天要介绍C++11中两个重要的关键字,即auto和decltype.实际上在C++98中,已 ...

  4. centos7.5安装opendesktop

    1.下载地址 http://gnome-look.org/ 2.安装 chmod +x opendesktop-app-3.1.3-1-x86_64.AppImage ./opendesktop-ap ...

  5. Mongo Connector for BI

    官网地址:https://www.mongodb.com/products/bi-connector 它目前包含两个组件: mongosqld:mongosqld接受来自SQL客户端的传入请求,并将这 ...

  6. VS2013 打开项目时提示This project is incompatible with the current edition Visual Studio.

    刚安装完成了Visual Studio 2013后,打开项目时,遇到以下问题 解决方法:在Visual Studio 2013 的菜单中打开“Tools",并打开“Extensions an ...

  7. .net中 Timer定时器

    作者:feiying008 在开发一套视觉系统时,发现系统内存一直不断增加,直至系统内存爆满.一开始还以为是程序内存泄露,是图像操作算法写的有问题,但是,发现如果电机轴如果 不运行的状态下,每隔一秒进 ...

  8. BZOJ 3261: 最大异或和位置-贪心+可持久化01Trie树

    3261: 最大异或和 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 3519  Solved: 1493[Submit][Status][Discu ...

  9. 转:攻击JavaWeb应用[8]-后门篇

    转:http://static.hx99.net/static/drops/tips-662.html 攻击JavaWeb应用[8]-后门篇 园长 · 2013/10/11 19:19 0x00 背景 ...

  10. 安卓 内存泄漏 MemoryAnalyzer

    韩梦飞沙 yue31313 韩亚飞 han_meng_fei_sha 313134555@qq.com 需要 获取 root 权限 步骤: 1,使用eclipse 自带的 DDMS 工具分析各线程的内 ...