zoukankan      html  css  js  c++  java
  • Jenkins和Docker以及Kubernetes结合考虑

    今天搞了一下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}" == "1" ]; 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=20171031153657
    + echo '============begin weblogic pod check========'
    ============begin weblogic pod check========
    + echo 'the shell execute time is 20171031153657'
    the shell execute time is 20171031153657
    ++ kubectl get pods
    ++ grep helloworld-service
    ++ wc -l
    + weblogic_num=1
    + '[' 1 == 1 ']'
    + 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 31, 2017 3:38:35 PM CST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, easy-springmvc-maven.war [archive: /home/ericnie/.jenkins/workspace/jenkins_test/target/easy-springmvc-maven.war], to AdminServer .> 
    Task 0 initiated: [Deployer:149026]deploy application easy-springmvc-maven.war on AdminServer.
    Task 0 completed: [Deployer:149026]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

    欢迎提出意见探讨。

  • 相关阅读:
    【转】SpringCloud学习
    Springboot中配置druid
    阿里云sql监控配置-druid
    Linux中Java开发常用的软件总结:
    java 搞笑注释
    Python之路-pandas包的详解与使用
    Python之路-numpy模块
    Python之路-Python中的线程与进程
    Python之路-Python常用模块-time模块
    Python之路-Python中文件和异常
  • 原文地址:https://www.cnblogs.com/ericnie/p/7761976.html
Copyright © 2011-2022 走看看