• Jenkins Pipeline 流水线 使用代理节点,Remote SSH 对 K8S 进行升级


    Jenkins Pipeline 流水线 - K8S kubectl 升级

    • 使用代理节点
    • Remote SSH 远程执行命令进行升级

    Remote SSH 方式

    安装插件

    • SSH Pipeline Steps

    Pipeline SSH 脚本

    image
    credentialsId: 'K8SMaster'

    pipeline {
        agent any
    
        stages {
            stage('Remote SSH') {
                steps {
                    script {                 
                        def remote = [:]
                        remote.name = 'Test'
                        remote.host = '172.16.3.181'
                        remote.allowAnyHosts = true
                        withCredentials([usernamePassword(credentialsId: 'K8SMaster', passwordVariable: 'password', usernameVariable: 'username')]) {
                            remote.user = "${username}"
                            remote.password = "${password}"
                        }
                        sshCommand remote: remote, command: "kubectl version" 
                    }
                }
            }
        }
    }
    
    

    image

    Pipeline Remote SSH K8S 升级

    pipeline {
        agent any
    
        stages {
            stage('Remote SSH') {
                steps {
                    script {                 
                        def remote = [:]
                        remote.name = 'Test'
                        remote.host = '172.16.3.181'
                        remote.allowAnyHosts = true
                        withCredentials([usernamePassword(credentialsId: 'K8SMaster', passwordVariable: 'password', usernameVariable: 'username')]) {
                            remote.user = "${username}"
                            remote.password = "${password}"
                        }
                        sshCommand remote: remote, command: "kubectl set image deployment/javademo1 vipsoft=registry.cn-shanghai.aliyuncs.com/vipsoft/vipsoft:4.0" 
                    }
                }
            }
        }
    }
    
    

    image
    image

    代理方式

    新增K8S节点

    image
    image
    image
    image
    注意JDK

    [root@k8smaster k8s]# tar -zxvf /opt/k8s/jdk-11.0.17_linux-x64_bin.tar.gz -C /opt/k8s 
    [root@k8smaster k8s]# mv jdk-11.0.17 jdk
    [root@k8smaster k8s]# ll
    总用量 166600
    drwxr-xr-x. 9 root root       126 11月  2 15:54 jdk
    -rw-r--r--. 1 root root 169251172 11月  1 16:39 jdk-11.0.17_linux-x64_bin.tar.gz
    -rw-r--r--. 1 root root   1339992 11月  2 15:50 remoting.jar
    [root@k8smaster k8s]#
    

    image

    Pipeline Script

    pipeline {
        agent none
     
        stages { 
            stage('代理节点运行') {
                agent {	label 'K8SAgent' }  //这边使用节点名称或节点标签,都可以运行
                steps {
                    sh 'kubectl set image deployment/javademo1 vipsoft=registry.cn-shanghai.aliyuncs.com/vipsoft/vipsoft:4.0' 
                    echo '构建完成'
                }
            }
        }
    }
    

    image
    image

  • 相关阅读:
    使用DevExpress 控件开发通用查询控件(Winform)
    SQL 排序函数
    SQL Server 消除科学计数法
    Excel VBA 的GetOpenFilename 方法
    分布式定时任务利用分布式定时任务框架xxljob实现任务动态发布
    java 同时启动多个项目
    Jooq配置与使用
    java 线上诊断工具arthas使用记录及k8s使用
    k8s脚本
    输入汉字获得拼音(VB.net)
  • 原文地址:https://www.cnblogs.com/vipsoft/p/16851605.html
Copyright © 2020-2023  润新知