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

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

Jenkins Pipeline 流水线 - K8S kubectl 升级

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

Remote SSH 方式

安装插件

  • SSH Pipeline Steps

Pipeline SSH 脚本

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

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

代理方式

新增K8S节点

注意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]#

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 '构建完成'
            }
        }
    }
}

相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
目录
打赏
0
0
0
0
54
分享
相关文章
当node节点kubectl 命令无法连接到 Kubernetes API 服务器
当Node节点上的 `kubectl`无法连接到Kubernetes API服务器时,可以通过以上步骤逐步排查和解决问题。首先确保网络连接正常,验证 `kubeconfig`文件配置正确,检查API服务器和Node节点的状态,最后排除防火墙或网络策略的干扰,并通过重启服务恢复正常连接。通过这些措施,可以有效解决与Kubernetes API服务器通信的常见问题,从而保障集群的正常运行。
282 17
|
9月前
|
k8s中节点无法启动Pod
【10月更文挑战第3天】
299 6
【Azure K8S | AKS】在AKS的节点中抓取目标POD的网络包方法分享
在AKS中遇到复杂网络问题时,可通过以下步骤进入特定POD抓取网络包进行分析:1. 使用`kubectl get pods`确认Pod所在Node;2. 通过`kubectl node-shell`登录Node;3. 使用`crictl ps`找到Pod的Container ID;4. 获取PID并使用`nsenter`进入Pod的网络空间;5. 在`/var/tmp`目录下使用`tcpdump`抓包。完成后按Ctrl+C停止抓包。
145 12
jenkins学习笔记之一:流水线基础语法
jenkins学习笔记之一:流水线基础语法
Kubernetes节点资源耗尽状态的处理
Kubernetes节点资源耗尽状态的处理
Curl error (60): SSL peer certificate or SSH remote key was not OK for https://update.cs2c.com.cn/NS/V10/V10SP2/os/adv/lic/base/x86_64/repodata/repomd.xml [SSL: no alternative certificate subject name matches target host name 'update.cs2c.com.cn']
【10月更文挑战第30天】在尝试从麒麟软件仓库(ks10-adv-os)下载元数据时,遇到 SSL 证书验证问题。错误提示为:`Curl error (60): SSL peer certificate or SSH remote key was not OK`。可能原因包括证书不被信任、证书与域名不匹配或网络问题。解决方法包括检查网络连接、导入 SSL 证书、禁用 SSL 证书验证(不推荐)、联系仓库管理员、检查系统时间和尝试其他镜像。
2233 1
大数据-03-Hadoop集群 免密登录 超详细 3节点云 分发脚本 踩坑笔记 SSH免密 集群搭建(一)
大数据-03-Hadoop集群 免密登录 超详细 3节点云 分发脚本 踩坑笔记 SSH免密 集群搭建(一)
182 5
大数据-03-Hadoop集群 免密登录 超详细 3节点云 分发脚本 踩坑笔记 SSH免密 集群搭建(二)
大数据-03-Hadoop集群 免密登录 超详细 3节点云 分发脚本 踩坑笔记 SSH免密 集群搭建(二)
312 5
jenkins学习笔记之二十一:k8s部署jenkins及动态slave
jenkins学习笔记之二十一:k8s部署jenkins及动态slave

推荐镜像

更多
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问