• <menu id="sssag"></menu>
  • <menu id="sssag"></menu>
  • 基于kubernetes平臺微服務的部署

    基于kubernetes平臺微服務的部署

    首先下載插件:

    kubernetes Continuous Deploy

    然后去找 .kube/ 里的config 復制里面的內容

     

    去添加憑據:

     

     

     

     

     

     

    然后就是腳本更新:

    def git_address = "http://20.0.0.20:82/root/tensquare_back.git" 
    def git_auth = "904eff5d-41c8-44ad-ba24-7f539a0edb96"
    //構建版本的名稱
    def tag = "latest"
    //Harbor私服地址
    def harbor_url = "20.0.0.50:85"
    //Harbor的項目名稱
    def harbor_project_name = "tensquare"
    //Harbor的憑證
    def harbor_auth = "427399a8-db35-48e8-b5cf-a1ea63f10cc5"
    //k8s的憑證
    def k8s_auth="4f3c9e60-da07-49b3-89ae-d708516e8071"
    //定義k8s-barbor的憑證
    def secret_name="registry-auth-secret"
    
    
    
    podTemplate(label: 'jenkins-slave', cloud: 'kubernetes', containers: [ 
            containerTemplate(
                name: 'jnlp',
                image: "20.0.0.50:85/library/jenkins-slave-maven:latest"
            ),
            containerTemplate( 
                name: 'docker',
                image: "docker:stable",
                ttyEnabled: true,
                command: 'cat'
            ),
        ],
        volumes: [
            hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
            nfsVolume(mountPath: '/usr/local/apache-maven/repo', serverAddress: '20.0.0.10' , serverPath: '/opt/nfs/maven'),
        ],
    )
    {
    node("jenkins-slave"){
        // 第一步
        stage('pull code'){
            checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_address}"]]])
        }
        // 第二步
        stage('make public sub project'){
            //編譯并安裝公共工程
            sh "mvn -f tensquare_common clean install"
        }
        // 第三步
        stage('make image'){
            //把選擇的項目信息轉為數組
            def selectedProjects = "${project_name}".split(',')
    
    
            for(int i=0;i<selectedProjects.size();i++){
                //取出每個項目的名稱和端口
                def currentProject = selectedProjects[i];
                //項目名稱
                def currentProjectName = currentProject.split('@')[0]
                //項目啟動端口
                def currentProjectPort = currentProject.split('@')[1]
    
                //定義鏡像名稱
                def imageName = "${currentProjectName}:${tag}"
    
                //編譯,構建本地鏡像
                sh "mvn -f ${currentProjectName} clean package dockerfile:build"
                container('docker') {
    
                    //給鏡像打標簽
                    sh "docker tag ${imageName} ${harbor_url}/${harbor_project_name}/${imageName}"
    
                    //登錄Harbor,并上傳鏡像
                    withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')])
                    {
                        //登錄
                        sh "docker login -u ${username} -p ${password} ${harbor_url}"
                        //上傳鏡像
                        sh "docker push ${harbor_url}/${harbor_project_name}/${imageName}"
                    }
    
                //刪除本地鏡像
                sh "docker rmi -f ${imageName}" 
                sh "docker rmi -f ${harbor_url}/${harbor_project_name}/${imageName}"
                }
                def deploy_image_name = "${harbor_url}/${harbor_project_name}/${imageName}"
                //部署到K8S 
                sh """
                    sed -i 's#\$IMAGE_NAME#${deploy_image_name}#' ${currentProjectName}/deploy.yml
                    sed -i 's#\$SECRET_NAME#${secret_name}#' ${currentProjectName}/deploy.yml
                """
                kubernetesDeploy configs: "${currentProjectName}/deploy.yml", kubeconfigId: "${k8s_auth}"
            }
        }
    }
    }
    

      

    要更改的就是:

    添加k8s的憑證:

     

     

     

    然后在eureka 目錄下創建deploy文件:

    metadata:
      name: eureka
    spec:
      serviceName: "eureka"
      replicas: 2
      selector:
        matchLabels:
          app: eureka
      template:
        metadata:
          labels:
            app: eureka
        spec:
          imagePullSecrets:
            - name: $SECRET_NAME
          containers:
            - name: eureka
              image: $IMAGE_NAME
              ports:
                - containerPort: 10086
              env:
                - name: MY_POD_NAME
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.name
                - name: EUREKA_SERVER
                  value: "http://eureka-0.eureka:10086/eureka/,http://eureka- 1.eureka:10086/eureka/"
                - name: EUREKA_INSTANCE_HOSTNAME
                  value: ${MY_POD_NAME}.eureka
      podManagementPolicy: "Parallel"
    

      

    里面的application.yml配置文件更改如下:

     

    server:
      port: ${PORT:10086}
    spring:
      application:
        name: eureka
    
    eureka:
      server:
        # 續期時間,即掃描失效服務的間隔時間(缺省為60*1000ms)
        eviction-interval-timer-in-ms: 5000
        enable-self-preservation: false
        use-read-only-response-cache: false
      client:
        # eureka client間隔多久去拉取服務注冊信息 默認30s
        registry-fetch-interval-seconds: 5
        serviceUrl:
          defaultZone: ${EUREKA_SERVER:http://127.0.0.1:${server.port}/eureka/}
      instance:
        # 心跳間隔時間,即發送一次心跳之后,多久在發起下一次(缺省為30s)
        lease-renewal-interval-in-seconds: 5
        #  在收到一次心跳之后,等待下一次心跳的空檔時間,大于心跳間隔即可,即服務續約到期時間(缺省為90s)
        lease-expiration-duration-in-seconds: 10
        instance-id: ${EUREKA_INSTANCE_HOSTNAME:${spring.application.name}}:${server.port}@${random.l ong(1000000,9999999)}
        hostname: ${EUREKA_INSTANCE_HOSTNAME:${spring.application.name}}
    

     

     

     

    然后在提交前在k8s所有主機上操作

    docker login -u lvbu -p Lvbu1234 20.0.0.50:85
    
    kubectl create secret docker-registry registry-auth-secret --docker-server=20.0.0.50:85 --docker-username=lvbu --docker-password=Lvbu1234 -- docker-email=lbu@qq.com
    

      

    然后去提交之前的修改的配置

     

    提交完之后就可以構建了!

    然后去查看:

    kubectl get secrets
    
    kubectl get pods
    
    kubectl get servicef  查看能看到端口 訪問node節點的端口  就會發現注冊中心有了 

     

     

    然后部署服務網關:

    同理更改配置文件中的eureka集群地址:

    http://eureka-0.eureka:10086/eureka/,http://eureka- 1.eureka:10086/eureka/ 

    所有的都要更改!

     

    然后一樣的操作在網關低下創建deploy.yml文件:

    內容如下:

    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: zuul
      labels:
        app: zuul
    spec:
      type: NodePort
      ports:
        - port: 10020
          name: zuul
          targetPort: 10020
      selector:
        app: zuul
    ---
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: zuul
    spec:
      serviceName: "zuul"
      replicas: 2
      selector:
        matchLabels:
          app: zuul
      template:
        metadata:
          labels:
            app: zuul
        spec:
          imagePullSecrets:
            - name: $SECRET_NAME
          containers:
            - name: zuul
              image: $IMAGE_NAME
              ports:
                - containerPort: 10020
      podManagementPolicy: "Parallel"
    

      

    在提交前先去手動上傳父工程依賴到NFS的maven共享倉庫目錄中:

     

     

      

    然后在構建!

     

     

     

    然后就是部署admin_service:

    也是創建deploy.yml:

    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: admin
      labels:
        app: admin
    spec:
      type: NodePort
      ports:
        - port: 9001
          name: admin
          targetPort: 9001
      selector:
        app: admin
    ---
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: admin
    spec:
      serviceName: "admin"
      replicas: 2
      selector:
        matchLabels:
          app: admin
      template:
        metadata:
          labels:
            app: admin
        spec:
          imagePullSecrets:
            - name: $SECRET_NAME
          containers:
            - name: admin
              image: $IMAGE_NAME
              ports:
                - containerPort: 9001
      podManagementPolicy: "Parallel"
    

      

    然后 集群地址也要更改!

     

    接下來的部署gatjering  也是如此:

    deploy.yml文件如下:

    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: gathering
      labels:
        app: gathering
    spec:
      type: NodePort
      ports:
        - port: 9002
          name: gathering
          targetPort: 9002
      selector:
        app: gathering
    ---
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: gathering
    spec:
      serviceName: "gathering"
      replicas: 2
      selector:
        matchLabels:
          app: gathering
      template:
        metadata:
          labels:
            app: gathering
        spec:
          imagePullSecrets:
            - name: $SECRET_NAME
          containers:
            - name: gathering
              image: $IMAGE_NAME
              ports:
                - containerPort: 9002
      podManagementPolicy: "Parallel"
    

      

    也要修改集群地址eureka!

     

    然后就可以一次性提交代碼然后一次性構建!

    結果如下:

     

     

    posted @ 2022-03-11 19:29  隱姓埋名4869  閱讀(101)  評論(0編輯  收藏  舉報
    国产在线码观看超清无码视频,人妻精品动漫H无码,十大看黄台高清视频,国产在线无码视频一区二区三区,国产男女乱婬真视频免费,免费看女人的隐私超爽,狠狠色狠狠色综合久久蜜芽