I am using AKS(Azure k8),need k8s node.js client for this options
Kill pod by name
Change deployments pods count
Restart all deployments pods
I need only for this functions, witch lib is best for this?
Please also provide examples using lib for some of this functions.
Thank you
UPDATE
I liked this one Node.js (TypeScript) github.com/Goyoo/node-k8s-client
,can you provide more information about service account and access ?
For node.js there are two clients:
Here is the full list of all the client libraries.
https://kubernetes.io/docs/reference/using-api/client-libraries/
You will need to create a service account , and role binding to configure the proper permissions to do these operations from the client library.
node.js specific libraries:
Node.js (TypeScript) github.com/Goyoo/node-k8s-client
Node.js github.com/tenxcloud/node-kubernetes-client
Node.js github.com/godaddy/kubernetes-client
Basic Example ( Using godaddy client)
/* 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();