1

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! :)

Popopame
  • 492
  • 4
  • 18
  • 2
    Hello, I thing based on this example https://github.com/kubernetes-client/javascript/blob/master/examples/ingress.js and the documentation of kubernetes https://kubernetes.io/docs/concepts/workloads/controllers/job/#running-an-example-job, You should be able to create easily what you are looking for :) Best – François Jun 29 '20 at 06:53
  • Thanks a lot ! I'm new to javascript and Kubernetes I didn't tic when i saw that example ! I'll do some testing , and come close this issue if this worked :) – Popopame Jun 29 '20 at 06:59
  • Sadly , I still need to know the name of the functions to create the Jobs and Namespace Object. With a little meddling with Code , I found the name of the function to create a secret : "createNamespacedSecret" , but I didn't found the name of the function to create Jobs – Popopame Jun 29 '20 at 08:01
  • Have a look to this issue https://github.com/kubernetes-client/javascript/issues/117, createNamespacedJob should do the trick? – François Jun 29 '20 at 13:00

1 Answers1

3

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

Popopame
  • 492
  • 4
  • 18