29

I have a Kubernetes cluster with following versions:

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.1", GitCommit:"632ed300f2c34f6d6d15ca4cef3d3c7073412212", GitTreeState:"clean", BuildDate:"2021-08-19T15:38:26Z", GoVersion:"go1.16.6", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.13", GitCommit:"aac5f64a5218b0b1d0138a57d273a12db99390c9", GitTreeState:"clean", BuildDate:"2021-01-18T07:43:30Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
WARNING: version difference between client (1.22) and server (1.16) exceeds the supported minor version skew of +/-1

I have a CronJob in my Kubernetes cluster.

apiVersion: batch/v1beta1
kind: CronJob
metadata:
   name: abc-cronjob
   namespace: abc-namespace
...

The Kubernetes cluster recognizes the api resource for the cron job.

$ kubectl -n abc-namespace api-resources
NAME                              SHORTNAMES   APIVERSION                        NAMESPACED   KIND
...
cronjobs                          cj           batch/v1beta1                     true         CronJob
...

I am trying to create a manual job for this, but I am facing this error:

$ kubectl -n abc-namespace create job abc-job --from=cronjob/abc-cronjob
error: unknown object type *v1beta1.CronJob

Can anyone help in this?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135

4 Answers4

20

Got the issue now. The version difference was causing the main problem. Installed the version matching the one in server side and ran the query again without issues.

  • 1
    I didn't think I would need to use multiple versions of kubectl, but this did fix the issue for me. I ended up using asdf version manager with the kubectl plugin and highly recommend it. https://github.com/asdf-community/asdf-kubectl – earlonrails Apr 22 '22 at 05:07
  • Indeed, this should be the accepted answer. Also kubectl outputs a warning when versions' mismatch can potentially cause issues: `WARNING: version difference between client (1.25) and server (1.20) exceeds the supported minor version skew of +/-1` – dimisjim Nov 14 '22 at 11:22
12

downgrade client side "kubectl" to v1.16 or upgrade server side k8s cluster to v1.22

John Jang
  • 2,567
  • 24
  • 28
  • 2
    `curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/darwin/amd64/kubectl` `$./kubectl version` – Vishal K Jan 27 '22 at 06:28
7

The API version which you are using (batch/v1beta1) for CronJobs is not longer valid.

Starting v1.25 of the client version, use the following for the CronJob:

apiVersion: batch/v1

Reference: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#cronjob-v125

The batch/v1beta1 API version of CronJob is no longer served as of v1.25.
...

  • Migrate manifests and API clients to use the batch/v1 API version, available since v1.21.
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Chandra Sekar
  • 637
  • 4
  • 9
2

In my case, the kubernetes server I have to work with is very old. So old that I cannot run a matching version of kubectl on my machine at all. I resorted to using docker instead.

docker run --rm  -v /path/to/.kube/:/.kube/ \
  bitnami/kubectl:1.11.9 \
  <insert kubectl command here>
Alex Grounds
  • 256
  • 2
  • 12