使用Kubernetes JavaScript客户端的createDeployment()

时间:2020-10-10 18:58:16

标签: javascript kubernetes kubectl

我正在尝试使用Kubernetes Javascript客户端创建一个部署或副本集。 Kubernetes javascript客户端文档实际上不存在。

有什么办法可以做到这一点?

1 个答案:

答案 0 :(得分:1)

假设是:

  • SELECT substr(firstname || ' ' || lastname, 1, 4) --> note 4
  • 您指的是:createDeployment()

您可以使用以下代码段通过Javascript客户端库创建createNamespacedDeployment()

Deployment

免责声明!

此代码假定您已经配置了const k8s = require('@kubernetes/client-node'); const kc = new k8s.KubeConfig(); kc.loadFromDefault(); const k8sApi = kc.makeApiClient(k8s.AppsV1Api); // <-- notice the AppsV1Api // Definition of the deployment var amazingDeployment = { metadata: { name: 'nginx-deployment' }, spec: { selector: { matchLabels: { app: 'nginx' } }, replicas: 3, template: { metadata: { labels: { app: 'nginx' } }, spec: { containers: [ { name: 'nginx', image: 'nginx' } ] } } } }; // Sending the request to the API k8sApi.createNamespacedDeployment('default', amazingDeployment).then( (response) => { console.log('Yay! \nYou spawned: ' + amazingDeployment.metadata.name); }, (err) => { console.log('Oh no. Something went wrong :('); // console.log(err) <-- Get the full output! } );

第一次使用以下代码运行此代码:

  • ~/.kube/config

应输出:

$ node deploy.js

您可以通过以下方式检查Yay! You spawned: nginx-deployment 是否存在:

  • Deployment
$ kubectl get deployment nginx-deployment

再次运行此代码将输出(已存在部署!):

NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3/3     3            3           6m57s

其他资源: