简体   繁体   English

Jenkins - 将 Yaml 文件从管道错误部署到 Kubernetes

[英]Jenkins - Deploy a Yaml file to Kubernetes from Pipeline Error

I cannot resolve an issue that I was stuck with in my beginner tutorial.我无法解决我在初学者教程中遇到的问题。 When I try to create just a deployment on Kubernetes from Jenkins, I got the error message.当我尝试从 Jenkins 在 Kubernetes 上创建一个部署时,我收到了错误消息。

According to my research, Jackson 2 API v2.10.0, Kubernetes v1.21.3, Kubernetes Client API v4.6.3-1, Kubernetes Continuous Deploy v2.1.2, and I need to use Kubernetes Credentials v0.5.0 plug-ins.根据我的研究,Jackson 2 API v2.10.0、Kubernetes v1.21.3、Kubernetes Client API v4.6.3-1、Kubernetes Continuous Deploy v2.1.2,我需要使用Kubernetes Credentials v0.5.0插件。 I don't know how can I do this?我不知道我该怎么做?

How can I solve this problem?我怎么解决这个问题? Could anyone pls help me?任何人都可以帮助我吗?

Error错误

Starting Kubernetes deployment
Loading configuration: /var/lib/jenkins/workspace/k8sdeploy/k8sdeploy.yml
ERROR: ERROR: Can't construct a java object for tag:yaml.org,2002:io.kubernetes.client.openapi.models.V1Deployment; exception=Class not found: io.kubernetes.client.openapi.models.V1Deployment
 in 'reader', line 1, column 1:
    apiVersion: apps/v1
    ^

hudson.remoting.ProxyException: Can't construct a java object for tag:yaml.org,2002:io.kubernetes.client.openapi.models.V1Deployment; exception=Class not found: io.kubernetes.client.openapi.models.V1Deployment
 in 'reader', line 1, column 1:
    apiVersion: apps/v1
    ^

My Pipeline我的管道

pipeline {
  agent any
  stages {
    stage('Clone App from Github') {
      steps {
         git credentialsId: 'github', url: 'https://github.com/eneslanpir/k8sdeploy'
      }
    }
    stage("Wait For 5 Seconds"){
      steps {
        sleep 5
      }
    }
    stage("Kubernetes Create Deployment"){
      steps{
        script {
           kubernetesDeploy(configs: "k8sdeploy.yml", kubeconfigId: "kubeconfig")
        }
      }
    }
  }
}

My Deployment yaml from Github (Tested - Working on Kuberentes)我的 Github 部署 yaml(已测试 - 在 Kuberentes 上工作)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment-jenkins
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx-jenkins
        image: nginx:1.16.1
        ports:
        - containerPort: 80

When downgrade to Jackson 2 API v2.10.0, everythings are going wrong.当降级到 Jackson 2 API v2.10.0 时,一切都会出错。

在此处输入图片说明

I solved the problem by trying the plugins in the links below.我通过尝试下面链接中的插件解决了这个问题。

https://updates.jenkins.io/download/plugins/ https://updates.jenkins.io/download/plugins/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM