Home > Software design >  Kubectl Unknown apiVersionKind batch/v1/Job is it registered?
Kubectl Unknown apiVersionKind batch/v1/Job is it registered?

Time:07-14

I am trying to create a job from pod in minikube. Below is my job.yaml. I am using client-java-11.0.0 API. When I run the application from IDE, it creates the job. I load the file using Yaml.load(file)

apiVersion: batch/v1
kind: Job
metadata:
  name: mansoor-hello-world-job
spec:
  template:
    spec:
      containers:
        - name: mansoor-hello-world-job-image
          image: job/mansoor-hello-world-job
          imagePullPolicy: Never
          ports:
            - containerPort: 8080
      #          command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
  backoffLimit: 4

Now this application I am running in a container. When I do Yaml.load(file) I get below error Unknown apiVersionKind batch/v1/Job is it registered?. Any idea?

Below is my deployment.yaml for the app

apiVersion: apps/v1
kind: Deployment
metadata:
  name: job-runner-pod
spec:
  selector:
    matchLabels:
      app: job-runner-pod-app
  template:
    metadata:
      labels:
        app: job-runner-pod-app
    spec:
      containers:
        - name: job-runner-pod
          image: pods/job-runner-pod
          imagePullPolicy: Never
          ports:
            - containerPort: 8080
#          command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]

CodePudding user response:

Somehow, your Job object is not being correctly "detected" as Job kind by the client library. According to this issue on the GitHub issue board of the java-client, you can specify the model of the object before loading it as a file.

Yaml.addModelMap("batch/v1/Job", V1Job.class)

Afterwards, when you load your YAML, it will be interpreted appropriately.

CodePudding user response:

When I try to craete docker image, the jar had issues. I was able to fix the issue like below:

<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
               <configuration>
                    <layout>ZIP</layout>
                    <includes>
                        <include>
                            <groupId>non-exists</groupId>
                            <artifactId>non-exists</artifactId>
                        </include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/lib</outputDirectory>
                            <excludeTransitive>false</excludeTransitive>
                            <stripVersion>false</stripVersion>
                            <includeScope>runtime</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

And in Dockerfile used command like CMD ["java","-Dloader.path=/app/lib","-jar","/app/app.jar"]

Dockerfile

FROM openjdk
RUN mkdir -p /app
COPY target/lib /app/lib
COPY target/*.jar /app/app.jar
CMD ["java","-Dloader.path=/app/lib","-jar","/app/app.jar"]
EXPOSE 8080
  • Related