Node.js 为节点的Kubernetes推荐什么API客户端?
我正在使用AKS(Azure k8),需要k8s node.js客户端才能使用此选项 按名称杀死吊舱Node.js 为节点的Kubernetes推荐什么API客户端?,node.js,kubernetes,azure-aks,Node.js,Kubernetes,Azure Aks,我正在使用AKS(Azure k8),需要k8s node.js客户端才能使用此选项 按名称杀死吊舱 更改部署播客数量 重新启动所有部署吊舱 我只需要这个函数,witch lib最适合这个 还请提供一些使用lib实现这些函数的示例 多谢各位 更新 我喜欢这个Node.js(TypeScript)github.com/Goyoo/Node-k8s-client,你能提供更多关于服务帐户和访问的信息吗?对于Node.js,有两个客户端: 以下是所有客户端库的完整列表 您需要创建服务帐户和角色
更改部署播客数量
重新启动所有部署吊舱 我只需要这个函数,witch lib最适合这个 还请提供一些使用lib实现这些函数的示例 多谢各位 更新
我喜欢这个
Node.js(TypeScript)github.com/Goyoo/Node-k8s-client
,你能提供更多关于服务帐户和访问的信息吗?对于Node.js,有两个客户端:
- 根据我的经验,大多数时候我都使用kubernetes客户机来完成我可以从运行kubectl命令中获得结果的工作。该命令有一个非常统一的格式和模式来操作不同的资源,如pod、名称空间等。k8s内部提供的RESTAPI也遵循kubectl命令的相同模式。因此,关键代码本质上是高度可重用和组织良好的代码
- 由于上述原因,在使用API时,很容易定义统一的模式。我们可以优雅地处理响应、错误处理、日志等所有事情。代码看起来简洁易懂,因此易于维护
- 以下是所有客户端库的完整列表
您需要创建服务帐户和角色绑定,以配置从客户端库执行这些操作的适当权限
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客户端)
我确实推荐。在我最喜欢原始API方法的所有API中,您可以看到一个示例。原因是
什么代表“部署清单”?YAML?
/* 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();