Advertisement
Guest User

Untitled

a guest
Jun 29th, 2020
1,775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. const k8s = require('@kubernetes/client-node'); //https://github.com/kubernetes-client/javascript
  2.  
  3. const kc = new k8s.KubeConfig(); //Creation of the Kubeconfig , wich is a file containing all info related to communication with a cluster : Auth methode , ID , adress of cluster, ect...
  4.  
  5.  
  6. kc.loadFromCluster(); //Since we are in the cluster we need to load the kubeconfig from the data provided by the cluster at the creation of the pod , luckily , the SDK manage that for us
  7.  
  8. const k8sCoreV1Api = kc.makeApiClient(k8s.CoreV1Api); // we call the CoreV1Api that will be used for the creation of the secrets
  9. const k8sBatchV1Api = kc.makeApiClient(k8s.BatchV1Api); //we call the BatchV1Api that will be used for the creation of the jobs
  10.  
  11. //Creation of the Secret
  12. k8sCoreV1Api.createNamespacedSecret('dev', {
  13. apiVersion:'v1',
  14. kind:'Secret',
  15. metadata: {
  16. ...
  17. }
  18. }).catch(e => console.log(e))
  19.  
  20. //creation of the job
  21. k8sBatchV1Api.createNamespacedJob('dev', {
  22. apiVersion: 'batch/v1',
  23. kind: 'Job',
  24. metadata: {
  25. ...
  26. }
  27. },
  28. spec: {
  29. ...
  30. }
  31. }
  32. }}).catch(e => console.log(e))
  33.  
  34. k8sCoreV1Api.deleteNamespacedSecret('secret','dev')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement