Jenkins pipeline error in deployment in Kubernetes

0 votes

Getting the below error while trying to run a Jenkins pipeline for deployment on a Kubernetes cluster.

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:
    apiVersion: v1

I am using Jenkins 2.249, Kubernetes Continuous Deployment Plugin 2.3.0, Kubernetes (Master & Slave) v1.18.5. Please help

Jul 28, 2020 in DevOps & Agile by Pratyay
• 120 points
5,336 views

1 answer to this question.

0 votes

Hi@Pratyay,

Deployment has no apiVersion v1. If you want to create a deployment then add these two lines at the beginning of your code.

apiVersion: apps/v1
kind:Deployment

Make these changes in your code and try once. It will work.

answered Jul 28, 2020 by MD
• 95,460 points

Thanks for the response. My Kubernetes YAML goes as below. Please let me know where am I doing wrong.

  

  

apiVersion: v1
kind: Service
metadata:
name: train-schedule-service
spec:
type: NodePort
selector:
app: train-schedule
ports:
- protocol: TCP
port: 8080
nodePort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: train-schedule-deployment
labels:
app: train-schedule
spec:
replicas: 2
selector:
matchLabels:
app: train-schedule
template:
metadata:
labels:
app: train-schedule
spec:
containers:
- name: train-schedule
image: $DOCKER_IMAGE_NAME:$BUILD_NUMBER
ports:
- containerPort: 8080

Your code is Ok. I found one document related to this issue. I don't know it will work or not. But you can try it once.

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

Yes. I saw that before and tried that. Entire pipeline gets stalled with a message in the Console Output as 

Waiting for next available executor
Did you configure slave node in your Jenkins?
I have a master and a slave on Kubernetes. Do you mean that?

Yes. Configure your Kubernetes slave node as a Jenkins slave node also. I have attached one link below. You can go through that.

https://www.tutorialspoint.com/jenkins/jenkins_distributed_builds.htm

Thank you so much. I shall give it a shot and let you know how did it go.

I am also facing the same issue. Post making changes as per https://issues.jenkins-ci.org/browse/JENKINS-62954 , it was throwing "Waiting fot next avaialble executor" in console output.Added one of the k8s slave node as jenkins node. Changed # of executor to 2 (Default).Restarted jenkins services on master node.Tried to run job again but its still failing with same error


Loading configuration: /var/lib/jenkins/workspace/train-schedule_master/train-schedule-kube.yml
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
    ^


Are your all nodes in running the state? If yes, then restrict your Job in the slave node. You can find the restrict option in your Job configuration.

Thanks a ton for your help.Managed to fix it by restricting the job to run on k8s_slave node. Labeled Jenkins slave node.Made below change in Jenkinsfile to restrict job to run on slave node.

Jenkins File:

pipeline {
//agent any
agent {label 'linux'}

Related Questions In DevOps & Agile

+1 vote
3 answers

Kubernetes can't start due to too many open files in system

Seems like a kernel config issue. If ...READ MORE

answered Oct 25, 2018 in DevOps & Agile by Zaid
5,369 views
0 votes
1 answer

Error: Unable to access elasticsearch in docker for windows

This is simple, just follow the below ...READ MORE

answered Sep 3, 2018 in DevOps & Agile by Sophie may
• 10,620 points
1,710 views
0 votes
1 answer
0 votes
1 answer

Kubernetes on Docker for Windows Error

This issue is with docker for windows ...READ MORE

answered Nov 14, 2018 in DevOps & Agile by Tyrion anex
• 8,700 points
917 views
0 votes
1 answer
0 votes
1 answer

what is api token in jenkins and how to use for github webhook

Hi@Anil, GitHub webhook is used to trigger jenkins ...READ MORE

answered May 27, 2020 in DevOps & Agile by MD
• 95,460 points
2,289 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP