首页 > 其他分享 >Jenkins Pipeline 流水线 - 使用代理节点,Remote SSH 对 K8S 进行升级

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

时间:2022-11-02 17:15:50浏览次数:65  
标签:Pipeline remote SSH Remote password root

Jenkins Pipeline 流水线 - 使用代理节点、Remote SSH 进行 K8S kubectl 升级

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

标签:Pipeline,remote,SSH,Remote,password,root
From: https://www.cnblogs.com/vipsoft/p/16851605.html

相关文章