zoukankan      html  css  js  c++  java
  • 实战交付一套dubbo微服务到k8s集群(5)之使用Jenkins进行持续构建交付dubo服务的提供者

    1.登录到jenkins,新建一个项目

    image-20200612154505028

    2.新建流水线

    image-20200612154754170

    3.设置保留的天数及份数

    image-20200612154922999

    4.添加第一个参数:设置项目的名称

    image-20200612155449864

    5.添加第二个参数:docker镜像名称

    image-20200612155722147

    6.添加第三个参数:项目所在的git中央仓库地址

    image-20200612155922204

    7.添加第四个参数:项目在git仓库的对应分支或版本号

    image-20200612160034910

    8.添加第五个参数:添加镜像标签

    image-20200612160201130

    9.添加第六个参数:编译项目的位置

    image-20200612160259851

    10.添加第七个参数:项目编译完成后,产生jar/war包的位置

    image-20200612165449663

    11.添加第八个参数:编译所要使用的命令

    image-20200612170305822

    12.添加第九个参数:使用哪个底包

    image-20200612172754115

    13.添加第十个参数:使用哪个maven版本编译项目

    image-20200612174015026

    14.设置流水线构建脚本

    脚本代码如下:

    pipeline {
      agent any 
        stages {
          stage('pull') { //get project code from repo 
            steps {
              sh "git clone ${params.git_repo} ${params.app_name}/${env.BUILD_NUMBER} && cd ${params.app_name}/${env.BUILD_NUMBER} && git checkout ${params.git_ver}"
            }
          }
          stage('build') { //exec mvn cmd
            steps {
              sh "cd ${params.app_name}/${env.BUILD_NUMBER}  && /var/jenkins_home/maven-${params.maven}/bin/${params.mvn_cmd}"
            }
          }
          stage('package') { //move jar file into project_dir
            steps {
              sh "cd ${params.app_name}/${env.BUILD_NUMBER} && cd ${params.target_dir} && mkdir project_dir && mv *.jar ./project_dir"
            }
          }
          stage('image') { //build image and push to registry
            steps {
              writeFile file: "${params.app_name}/${env.BUILD_NUMBER}/Dockerfile", text: """FROM harbor.od.com/${params.base_image}
    ADD ${params.target_dir}/project_dir /opt/project_dir"""
              sh "cd  ${params.app_name}/${env.BUILD_NUMBER} && docker build -t harbor.od.com/${params.image_name}:${params.git_ver}_${params.add_tag} . && docker push harbor.od.com/${params.image_name}:${params.git_ver}_${params.add_tag}"
            }
          }
        }
    }
    

    image-20200612171718471

    15.最后保存所有设置的

    image-20200612170949876

    16.在私有仓库创建一个名称为app的项目,属性为私有

    image-20200612172044763

    17.执行流水线

    image-20200612172157153

    18.输入相关的参数,执行build

    image-20200613192937161

    19.构建成功

    image-20200613193256391

    20.查看私有仓库的app项目是否已经有docker镜像

    image-20200612181253309

    21.准备dubbo-demo-service的k8s资源配置清单文件

    在运维主机mfyxw50.mfyxw.com上操作

    [root@mfyxw50 ~]# mkdir -p /data/k8s-yaml/dubbo-demo-service
    [root@mfyxw50 ~]# cat > /data/k8s-yaml/dubbo-demo-service/deployment.yaml << EOF
    kind: Deployment
    apiVersion: extensions/v1beta1
    metadata:
      name: dubbo-demo-service
      namespace: app
      labels: 
        name: dubbo-demo-service
    spec:
      replicas: 1
      selector:
        matchLabels: 
          name: dubbo-demo-service
      template:
        metadata:
          labels: 
            app: dubbo-demo-service
            name: dubbo-demo-service
        spec:
          containers:
          - name: dubbo-demo-service
            image: harbor.od.com/app/dubbo-demo-service:master_20200613_1929
            ports:
            - containerPort: 20880
              protocol: TCP
            env:
            - name: JAR_BALL
              value: dubbo-server.jar
            imagePullPolicy: IfNotPresent
          imagePullSecrets:
          - name: harbor
          restartPolicy: Always
          terminationGracePeriodSeconds: 30
          securityContext: 
            runAsUser: 0
          schedulerName: default-scheduler
      strategy:
        type: RollingUpdate
        rollingUpdate: 
          maxUnavailable: 1
          maxSurge: 1
      revisionHistoryLimit: 7
      progressDeadlineSeconds: 600
    EOF
    

    在安装有zookeeper的主机(mfyxw10或mfyxw20或mfyxw30)上任意一台执行

    查看zookeeper的状态

    [root@mfyxw30 bin]# ./zkServer.sh status
    ZooKeeper JMX enabled by default
    Using config: /opt/zookeeper/bin/../conf/zoo.cfg
    Client port found: 2181. Client address: localhost.
    Mode: follower
    
    

    连接进入zookeeper查看

    [root@mfyxw30 bin]# ./zkCli.sh -server localhost:2181
    [zk: localhost:2181(CONNECTED) 0] ls /
    [zookeeper]
    [zk: localhost:2181(CONNECTED) 1] 
    

    23.应用dubbo-demo-service的k8s的资源配置清单

    在master节点(mfyxw30.mfyxw.com或mfyxw40.mfyxw.com)任意一台执行即可

    [root@mfyxw30 ~]# kubectl create namespace app
    [root@mfyxw30 ~]# kubectl create secret docker-registry harbor --docker-server=harbor.od.com --docker-username=admin --docker-password=Harbor12345 -n app
    [root@mfyxw30 ~]# kubectl apply -f http://k8s-yaml.od.com/dubbo-demo-service/deployment.yaml
    

    image-20200612212715671

    再次查看zookeeper

    [zk: localhost:2181(CONNECTED) 1] ls /
    [dubbo, zookeeper]
    [zk: localhost:2181(CONNECTED) 2] ls /dubbo
    

    image-20200613194323898

    24.打开 Blue Ocean可以查看到构建的步骤

    image-20200613194429319

  • 相关阅读:
    oracle过期备份未删除导致磁盘撑爆
    数据文件、监听日志、告警日志、redo日志、归档日志的迁移
    linux软件卸载命令
    Nginx版本平滑升级方案
    rsync 服务搭建
    在node节点部署kubectl管理k8s集群
    源码编译安装nginx及设置开机启动项
    K8S日常运维中关于“ImagePullBackOff”报错的处理思路分析
    查看所有日志命令:journalctl
    Docker编排工具Docker Compose的使用
  • 原文地址:https://www.cnblogs.com/Heroge/p/13121534.html
Copyright © 2011-2022 走看看