当前位置:   article > 正文

K8S实战-交付dubbo服务到k8s集群(四)使用blue ocean流水线构建dubbo-demo-service_k8s dubboservice

k8s dubboservice

使用jenkins创建一个新的项目:dubbo-demo,选择流水线构建

 勾选保存构建历史和指定项目为参数化构建项目:

 

 

添加构建参数:以下配置项,是王导根据多年生产经验总结出来的甩锅大法

 

除了base_image和maven是choice parameter,其他都是string parameter

添加完成后,效果如图:

 

 编写pipeline:仔细查看这个pipeline,里面都是我们上面编写的参数。

复制代码

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}"
        }
      }
    }
}

复制代码

 

 

 完成第一次构建:填写我们刚才配置的参数化构建参数:

 

 

填写完以后执行bulid:第一次构建需要下载很多依赖包,时间很长,抽根烟,喝杯茶~

 

 经过漫长的等待后,已经构建完成了,可以点击open blue ocean 查看构建历史及过程:

 

 检查harbor是否已经有这版镜像:

 

 

已经有了,接下来交付dubbo-demo-service服务到k8s:

准备k8s资源配置清单:7-200  红色部分,需要根据自己构建镜像的tag来进行修改

# mkdir /data/k8s-yaml/dubbo-server/
# cd /data/k8s-yaml/dubbo-server
# vi dp.yaml

复制代码

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_191201_1200
        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

复制代码

由于我们使用的harbor私有镜像的项目是app,是个私有项目,所以需要创建secret资源:

创建 app命名空间:

# kubectl create ns app

创建secret资源:

# kubectl create secret docker-registry harbor --docker-server=harbor.od.com --docker-username=admin --docker-password=Harbor12345 -n app

应用资源配置文件:

# kubectl apply -f http://k8s-yaml.od.com/dubbo-server/dp.yaml

检查pod是否创建:

# kubectl get pod -n app

 

 检查是否启动成功:

# kubectl logs dubbo-demo-service-77b687c6f8-v556v -n app

 

 检查dubbo-server服务是否已经注册到了zookeeper:

# sh /opt/zookeeper/bin/zkCli.sh
# ls /
# ls /dubbo

 

 

至此,dubbo-demo-service就已经交付到k8s中了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/169478
推荐阅读
相关标签
  

闽ICP备14008679号