Home > Mobile >  How to check if I have enough permission to start a cron job
How to check if I have enough permission to start a cron job

Time:10-30

I have two applications running in K8s, 1 application run as deployment, the other application run as cronjob. Suppose that this application will trigger the cronjob run in some situation. However, it works before but now it fails. I suspect may because the K8s admin has some permission / role restriction apply.

try {
    v2alpha1CronJob = batchV2alpha1Api.readNamespacedCronJob('A-CRONJOB-NAME', 'A-NAMESPACE', null, null, null);
} catch (Exception e) {
    // Here I get error, it promot me error as following
}

Error is:

Error trying to manipulate k8s CronJob {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"the server could not find the requested resource","reason":"NotFound","details":{},"code":404}

Would I know what I should do now? My k8s server version is 1.21.5

CodePudding user response:

The error that shows specifies that it is not finding the resource, 404 error. If it were a problem with the permissions you would have the 403 error.

"message":"the server could not find the requested resource"

You should check if the requested resource is the correct one or if it really exists.

CodePudding user response:

The description for the CronJob in the question contains batchV2alpha1Api. This means that the version of the API group is batch/v2alpha1.

But in the error description there is another version of the API group "apiVersion":"v1" - batch/v1.

Due to this difference, the CronJob cannot be created, as there is no required version of the Kubernetes API to create this object.

To fix this problem you can:

  1. Change the apiVersion in the description for CronJob with the version currently used by Kubernetes

or

  1. Enable required API group and don't change the description.
  • Related