![](/img/trans.png)
[英]Deployment of Virtual Service using @kubernetes/client-node nodejs api
[英]What API client is recommended for Kubernetes for NodeJS?
我正在使用 AKS(Azure k8),此選項需要 k8s node.js 客戶端
按名稱殺死 pod
更改部署 pod 計數
重新啟動所有部署 pod
我只需要這個功能,女巫 lib 最適合這個?
還請提供一些使用 lib 的示例。
謝謝
更新
我喜歡這個Node.js (TypeScript) github.com/Goyoo/node-k8s-client
,你能提供更多關於服務帳戶和訪問的信息嗎?
這是所有客戶端庫的完整列表。
https://kubernetes.io/docs/reference/using-api/client-libraries/
您將需要創建一個服務帳戶和角色綁定,以配置適當的權限以從客戶端庫執行這些操作。
node.js 特定庫:
Node.js (TypeScript) github.com/Goyoo/node-k8s-client
Node.js github.com/tenxcloud/node-kubernetes-client
Node.js github.com/godaddy/kubernetes-client
基本示例(使用godaddy客戶端)
/* eslint no-console:0 */
//
// Demonstrate some of the basics.
//
const Client = require('kubernetes-client').Client;
const config = require('kubernetes-client').config;
const deploymentManifest = require('./nginx-deployment.json');
async function main() {
try {
const client = new Client({ config: config.fromKubeconfig(), version: '1.9' });
//
// Get all the Namespaces.
//
const namespaces = await client.api.v1.namespaces.get();
console.log('Namespaces: ', namespaces);
//
// Create a new Deployment.
//
const create = await client.apis.apps.v1.namespaces('default').deployments.post({ body: deploymentManifest });
console.log('Create: ', create);
//
// Fetch the Deployment we just created.
//
const deployment = await client.apis.apps.v1.namespaces('default').deployments(deploymentManifest.metadata.name).get();
console.log('Deployment: ', deployment);
//
// Change the Deployment Replica count to 10
//
const replica = {
spec: {
replicas: 10
}
};
const replicaModify = await client.apis.apps.v1.namespaces('default').deployments(deploymentManifest.metadata.name).patch({ body: replica });
console.log('Replica Modification: ', replicaModify);
//
// Modify the image tag
//
const newImage = {
spec: {
template: {
spec: {
containers: [{
name: 'nginx',
image: 'nginx:1.8.1'
}]
}
}
}
};
const imageSet = await client.apis.apps.v1.namespaces('default').deployments(deploymentManifest.metadata.name).patch({ body: newImage });
console.log('New Image: ', imageSet);
//
// Remove the Deployment we created.
//
const removed = await client.apis.apps.v1.namespaces('default').deployments(deploymentManifest.metadata.name).delete();
console.log('Removed: ', removed);
} catch (err) {
console.error('Error: ', err);
}
}
main();
我推薦kubernetes-client/javascript 。 在我最喜歡原始 API 方法的所有 API 中,您可以在此處查看示例。 原因是
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.