前言

目前公司的生产环境部署都是由我来完成,其实步骤也很简单。
一.使用skopeo把镜像同步至idc机房机器上
二.使用k8s脚本做到一键部署升级
这里不得不说AI的强大,我一个开发都可以轻松做运维的事情。之前都是在服务器上去运行,所以这次就只是简单的用jenkins组合一下步骤然后配置下定时执行(免得升级当晚等到晚上11点去手工执行)

步骤

step1

安装Publish Over SSH,Dashboard ->系统管理 ->System中配置SSH Servers。如下图
image-1706163473788

step2 (编写pipeline)

传入所需要的镜像,执行测试环境的镜像同步.然后执行生产环境的k8s批量升级脚本

pipeline {
    agent any
    
    parameters {
      text defaultValue: '''jll/e3plus-basebiz-system:jll-release_011817''', description: '镜像内容', name: 'image_list'
      booleanParam description: '是否部署到生产环境', name: 'deploy_prod'
    }

    
    stages {
        stage('write_imageFile') {
            steps {
                 script {
                    // 假设文件名为 "example.txt"
                    def textContent = params.image_list
                    writeFile file: 'images-list.txt', text: textContent
                }
            }
        }
        
        stage('sync_images') {
            steps {
                script {
                    // 替换下面的 "your-remote-host" 和 "your-shell-command" 为实际的远程主机和Shell命令
                    sshPublisher(publishers: [sshPublisherDesc(configName: '114', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: './skopeo_copy.sh', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'images-list.txt')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)])
                }
            }
        }
        
        stage('升级生产环境') {
             steps {
                    script {
                        def deploy_prod = params.deploy_prod
                    if (deploy_prod) {
                        // 替换下面的 "your-remote-host" 和 "your-shell-command" 为实际的远程主机和Shell命令
                        sshPublisher(publishers: [sshPublisherDesc(configName: '生产环境', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: './update_pod.sh prod', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'images-list.txt')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)])
                    }
                }
            }
        }
    }
}