Class not found: io.kubernetes.client.openapi.models.V1Service

Viewed 6320

I get the following error when trying to use the YAML file from my GitRepo to deploy to kube cluster. Console errors

Here is the content of my .yaml file:

apiVersion: v1
kind: Service
metadata:
  name: ts-service
spec:
  type: NodePort
  selector:
    app: ts
  ports:
  - protocol: TCP
    port: 8080
    nodePort: 8080

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ts-deployment
  labels:
    app: ts
spec:
  replicas: 2
  selector:
    matchLabels:
      app: ts
  template:
    metadata:
      labels:
        app: ts
    spec:
      containers:
      - name: ts
        image: $DOCKER_IMAGE_NAME:$BUILD_NUMBER
        ports:
        - containerPort: 8080

I've already tried changing the ports, the API version to apps/v1, etc. What seems weird to me is that no matter which line goes foirst in the file, it always shows me the same issue. What can be causing this?

9 Answers

I found the root cause of this behaviour. Jackson 2 API plugin version 2.11.1 is breaking kube deployments; you can find more info by the link below:
https://issues.jenkins-ci.org/browse/JENKINS-62995

Downgrading the following plugins worked for me: 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

As those plugins are default, you would need to find the relevant version source files in https://plugins.jenkins.io/, and upload them to your Jenkins server by going
Manage Jenkins --> Manage Plugins --> Advanced --> Upload Plugin section

According to @hardway-studio ’s answer #4648446, Jackson 2 API plugin version 2.11.1 breaks our deployment. To be precise, this commit: https://github.com/jenkinsci/jackson2-api-plugin/commit/cbbdf36843505efd5d2d7cd4769018e4cc09f450

But if we downgrade the plugin directly, it will cause failure to load many other plugin.

My ugly way is to fork the plugin source code from GitHub, revert this commit and compile it. (Maybe this operation would break some other plugins?)

Manually upload the artifact(jackson2-api.hpi) to Jenkins and finally everything is fine, hope this problem can be fixed as soon as possible.

I have found the solution to this problem. I have tried many times and it's working perfectly. Kubernetes CD plugin should be Version 1.0. No need to downgrade other plugins.

Kindly hit this link to download the version 1.0.0 .hpi file of the Kubernetes cd plugin from the official Jenkins plugin site.

Reference - https://plugins.jenkins.io/kubernetes-cd/#releases

I got the same error with the following versions

  1. Kubernetes Continuous Deploy v2.3.0,

  2. Jackson 2 API v2.11.1

    ERROR: ERROR: Can't construct a java object for tag:yaml.org,2002:io.kubernetes.client.openapi.models.V1Service; exception=Class not found: io.kubernetes.client.openapi.models.V1Service in 'reader', line 1, column 1: kind: Service ^

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

But when I tried to use the following versions:

  1. Kubernetes Continuous Deploy v2.3.0,
  2. Jackson 2 API v2.9.10

Things worked as expected. Here is my pipeline code for reference

Same issue. This is probably for the ACG course Deploying to Kubernetes with Jenkins Pipelines

The issue is with the plugin Kubernetes Continuous Deploy

You can find more details in this GitHub Jenkins CI thread

Solution

  1. Upgrade all you Jenkins plugins first
  2. Jenkins > Manage Jenkins > Manage Plugins
  3. Installed
  4. Find the plugin Kubernetes Continuous Deploy
  5. Downgrade to 1.0 > Restart Jenkins

Just before you deploy again make sure you validate your Kubernetes YAML files with kubeyaml Once the instance is restarted you can deploy again.

enter image description here

As there are many relevant answers and thanks to @HardWay Studio's answer, I resolved this issue.

But I was running Jenkins 2.249.3 and I needed Docker Pipeline, Kubernetes Continues Deploy plugins.


For me the worked plugin versions were,

  • Jackson 2 API: 2.10.2
  • Kubernetes Continues Deploy: 2.1.2
  • Docker Pipeline: 1.23

I didn't need to manually downgrade Kubernetes, Kubernetes Client API, Kubernetes Credentials for my task. In fact, Kubernetes Credentials plugin automatically gets installed with Kubernetes Continues Deploy


You can download them in official Jenkins Plugins Index.

Manually Upload them as @HardWay Studio's answer, by going to Manage Jenkins => Manage Plugins => Advanced => Upload Plugin.

You may have to restart Jenkins every time you upload each file, otherwise it may not install the plugins correctly.

Downgrading didnt fix my issue as I have been running the deployment in the master jenkins node. I had to create a separate agent to run the deployment.

For more info on how to create the new agent refer this

If you do face an issue where you cant launch tha agent through the web app, download the agent.jar. upload it to your jenkins pod and run the given command there.

This issue is generated by the Kubernetes Continuous Deploy plugin. To solve this issue, what you can do is:

  1. Go to this link and download the .hpi file (Link for V1.0.0)
  2. Then go to Jenkins > Manage Jenkins > Manage Plugins > Advanced
  3. Then go to upload plugin section and insert the downloaded .hpi file & save it
  4. Finally restart the Jenkins

The issue is fixed:

I have followed the below steps:

To completely disable jobs from executing on the master and to solely utilize slave, the executors count on the master needs to be set to 0. This value is set on the Jenkins system configuration page which can be accessed by selecting Manage Jenkins on the lefthand size of the master landing page and selecting Configure System. Next to # of executors, enter 0 and then hit Save to apply the changes.

I have added the complete fix here.

https://issues.jenkins-ci.org/browse/JENKINS-62954

Related