Jenkins - Deploy a Yaml file to Kubernetes from Pipeline Error

10/7/2020

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.

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. 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)

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.

enter image description here

-- Lampej
css
html
javascript
jenkins
kubernetes

1 Answer

10/14/2020

I solved the problem by trying the plugins in the links below.

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

-- Lampej
Source: StackOverflow