Popopame
Popopame

Reputation: 532

How to create a Job and a secret from Kubernetes Javascript Client

I am trying to work my way into the kubernetes javascript client.

My goal is to create a Job and a secret from inside the cluster.

The kubernetes javascript client provide examples on how to create a in-cluster config and make simples API calls , but the generated documentation is no big help if you want to interact with other kubernetes objects (Jobs and Secret in my case)...

The documentation reference all the classes , but that's all.

So , do you have already worked with the Kubernetes javascript client ? Is there a more precise documentation or more examples ? (I wasn't succesful in my reshearsh)

Or , do you know how to create Jobs/Secret from the Client?

I Won't post my code here , because I only made the in-cluster config , it's only a copy from the repo example.

Thanks a Lot in advance! :)

Upvotes: 2

Views: 2063

Answers (1)

Popopame
Popopame

Reputation: 532

So , after a little meddling with the Kubernetes Javascript Client and with the help of the commentary of @François I found what I was looking to achieve.

The documentation of the K8s javascript client is very "minimal" , an the best way to see what is possible is using a good Code Editor (Code for me).

Based on this example you see the createNamespacedIngress , and all the other K8s object linked with the CoreV1Api are created with the same nomenclature.

If you want to create an object that is not managed by the CoreV1Api , you need to use the makeApiClient method on the Api you need to interacy with.

So , for creating a Job , I needed to use the BatchV1Api.

I'll try to upload an example on the Javasript client repo , to maybe , help more poor lost souls like me. Snippet of the code:

const k8sCoreV1Api = kc.makeApiClient(k8s.CoreV1Api); // we call the CoreV1Api that will be used for the creation of the secrets

const k8sBatchV1Api = kc.makeApiClient(k8s.BatchV1Api); //we call the BatchV1Api that will be used for the creation of the jobs

Here is the whole sample here : https://pastebin.com/FXWA17RQ

Upvotes: 4

Related Questions