Jenkins在Kubernetes中持续部署遇到的问题

大佬们好,我是一个jenkins新手,目前遇到一个问题困扰我几天了,希望大家能够提供下帮助。
pipeline代码参考如下:
。。。。
stage(‘部署到K8s’){
sh “”"
sed -i ‘s#$IMAGE_NAME#${image_name}#’ deploy.yaml
sed -i ‘s#$SECRET_NAME#${harbor_registry_secret}#’ deploy.yaml
sed -i ‘s#$NODE_PORT#${nodePort}#’ deploy.yaml
“”"
sh “cat deploy.yaml”
kubernetesDeploy configs: ‘deploy.yaml’, kubeconfigId: “${k8s_auth}”
}
代码执行到这里报错了日志如下:
[Pipeline] kubernetesDeploy
Starting Kubernetes deployment
Loading configuration: /home/jenkins/agent/workspace/gitlab-pipe/deploy.yaml
ERROR: ERROR: java.lang.RuntimeException: io.kubernetes.client.openapi.ApiException: okhttp3.internal.http2.ConnectionShutdownException
hudson.remoting.ProxyException: java.lang.RuntimeException: io.kubernetes.client.openapi.ApiException: okhttp3.internal.http2.ConnectionShutdownException
at com.microsoft.jenkins.kubernetes.wrapper.ResourceManager.handleApiExceptionExceptNotFound(ResourceManager.java:180)
at com.microsoft.jenkins.kubernetes.wrapper.V1ResourceManager$DeploymentUpdater.getCurrentResource(V1ResourceManager.java:213)
at com.microsoft.jenkins.kubernetes.wrapper.V1ResourceManager$DeploymentUpdater.getCurrentResource(V1ResourceManager.java:201)
at com.microsoft.jenkins.kubernetes.wrapper.ResourceManager$ResourceUpdater.createOrApply(ResourceManager.java:93)
at com.microsoft.jenkins.kubernetes.wrapper.KubernetesClientWrapper.handleResource(KubernetesClientWrapper.java:289)
at com.microsoft.jenkins.kubernetes.wrapper.KubernetesClientWrapper.apply(KubernetesClientWrapper.java:256)
at com.microsoft.jenkins.kubernetes.command.DeploymentCommand$DeploymentTask.doCall(DeploymentCommand.java:172)
at com.microsoft.jenkins.kubernetes.command.DeploymentCommand$DeploymentTask.call(DeploymentCommand.java:124)
at com.microsoft.jenkins.kubernetes.command.DeploymentCommand$DeploymentTask.call(DeploymentCommand.java:106)
at hudson.remoting.UserRequest.perform(UserRequest.java:211)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request$2.run(Request.java:369)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:117)
at java.lang.Thread.run(Thread.java:748)
Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from 10.244.1.1/10.244.1.1:10996
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1788)
at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
at hudson.remoting.Channel.call(Channel.java:998)
at hudson.FilePath.act(FilePath.java:1159)
at com.microsoft.jenkins.kubernetes.command.DeploymentCommand.execute(DeploymentCommand.java:68)
at com.microsoft.jenkins.kubernetes.command.DeploymentCommand.execute(DeploymentCommand.java:45)
at com.microsoft.jenkins.azurecommons.command.CommandService.runCommand(CommandService.java:88)
at com.microsoft.jenkins.azurecommons.command.CommandService.execute(CommandService.java:96)
at com.microsoft.jenkins.azurecommons.command.CommandService.executeCommands(CommandService.java:75)
at com.microsoft.jenkins.azurecommons.command.BaseCommandContext.executeCommands(BaseCommandContext.java:77)
at com.microsoft.jenkins.kubernetes.KubernetesDeploy.perform(KubernetesDeploy.java:42)
at com.microsoft.jenkins.azurecommons.command.SimpleBuildStepExecution.run(SimpleBuildStepExecution.java:54)
at com.microsoft.jenkins.azurecommons.command.SimpleBuildStepExecution.run(SimpleBuildStepExecution.java:35)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
… 1 more
Caused by: hudson.remoting.ProxyException: io.kubernetes.client.openapi.ApiException: okhttp3.internal.http2.ConnectionShutdownException
at io.kubernetes.client.openapi.ApiClient.execute(ApiClient.java:898)
at io.kubernetes.client.openapi.apis.AppsV1Api.readNamespacedDeploymentWithHttpInfo(AppsV1Api.java:7299)
at io.kubernetes.client.openapi.apis.AppsV1Api.readNamespacedDeployment(AppsV1Api.java:7275)
at com.microsoft.jenkins.kubernetes.wrapper.V1ResourceManager$DeploymentUpdater.getCurrentResource(V1ResourceManager.java:210)
… 16 more
Caused by: hudson.remoting.ProxyException: okhttp3.internal.http2.ConnectionShutdownException
at okhttp3.internal.http2.Http2Connection.newStream(Http2Connection.java:242)
at okhttp3.internal.http2.Http2Connection.newStream(Http2Connection.java:225)
at okhttp3.internal.http2.Http2ExchangeCodec.writeRequestHeaders(Http2ExchangeCodec.java:116)
at okhttp3.internal.connection.Exchange.writeRequestHeaders(Exchange.java:72)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:43)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at io.kubernetes.client.openapi.ApiClient$2.intercept(ApiClient.java:1232)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:43)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:221)
at okhttp3.RealCall.execute(RealCall.java:81)
at io.kubernetes.client.openapi.ApiClient.execute(ApiClient.java:894)
… 19 more
Api call failed with code 0, detailed message: null

有什么问题直接提问题,尽量把问题要描述说明详细一点,

我在 Jenkins在Kubernetes中持续部署的时候报错了报错信息为:
ERROR: ERROR: java.lang.RuntimeException: io.kubernetes.client.openapi.ApiException: okhttp3.internal.http2.ConnectionShutdownException
hudson.remoting.ProxyException: java.lang.RuntimeException: io.kubernetes.client.openapi.ApiException: okhttp3.internal.http2.ConnectionShutdownException
完整的信息可以看我上面发的完整信息

我的脚本是:
def registry = “jk03.harbor.com
// 镜像仓库项目
def project = “jenkinsci”
// 镜像名称
def app_name = “tomcat”
// 镜像完整名称
def image_name = “${registry}/${project}/${app_name}:${BUILD_NUMBER}”
// git仓库地址
def git_address = “http://192.168.60.176:10080/root/tpro.git
// git登陆名
def username = “root”
// git密码
def password = “Sxq129601”
// K8s认证
def k8s_auth = “fccc3a6a-5707-4dc0-b692-9591b027a4c0”
// harbor认证
def harbor_auth = “2eab6540-6c06-40ad-aa0f-304f73986b1a”
// harbor仓库secret_name
def harbor_registry_secret = “harbor-pull-secret”

// k8s部署后暴露的nodePort
def nodePort = “30666”

podTemplate(label: ‘jenkins-agent’, cloud: ‘kubernetes’,
containers: [
containerTemplate(
name: ‘jnlp’,
image: “${registry}/jenkinsci/jenkins-slave-jdk:1.8”
)],
volumes: [
hostPathVolume(mountPath: ‘/var/run/docker.sock’, hostPath: ‘/var/run/docker.sock’),
hostPathVolume(mountPath: ‘/usr/bin/docker’, hostPath: ‘/usr/bin/docker’)
])
{
node(“jenkins-agent”){

 // stage('代码编译') {
  //      sh "mvn clean package -Dmaven.test.skip=true"
  //      sh "ls"
  //  }
 
   stage('构建镜像') {
        withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')]) {
			sh """
				echo '
					FROM jk03.harbor.com/tools/tomcat:1.8
					LABEL maintainer sunxq
					COPY server.xml /opt/tomcat/conf/
					RUN rm -rf /opt/tomcat/webapps/*
					ADD HelloWorld.war /opt/tomcat/webapps/HelloWorld.war
				' > Dockerfile

				docker build -t ${image_name} .
				docker login ${registry} -u admin -p Sxq129601
				docker push ${image_name}
			"""
		}
	}
	stage('部署到K8s'){
        sh """
            sed -i 's#\$IMAGE_NAME#${image_name}#' deploy.yaml
            sed -i 's#\$SECRET_NAME#${harbor_registry_secret}#' deploy.yaml
            sed -i 's#\$NODE_PORT#${nodePort}#' deploy.yaml
        """
        sh "cat deploy.yaml"
**************************************以下报错********************************
        kubernetesDeploy configs: 'deploy.yaml', kubeconfigId: 'fccc3a6a-5707-4dc0-b692-9591b027a4c0'
	}
}

}

Jenkinsfile中sh里面的 sed替换包含 $ 不生效,即使使用了转义符,所以建议写到脚本中,执行脚本。