Skip to content

Instantly share code, notes, and snippets.

@zhangyuan
Created May 1, 2018 20:22
Show Gist options
  • Save zhangyuan/fbd813fd08c5d1aa1c396faafe22e24e to your computer and use it in GitHub Desktop.
Save zhangyuan/fbd813fd08c5d1aa1c396faafe22e24e to your computer and use it in GitHub Desktop.
make api calls to kubernetes cluster with nodejs and explicit configuration
// npm install @kubernetes/client-node
const clientWrapper = require('@kubernetes/client-node/dist/auth-wrapper');
const ENDPOINT = 'https://x.x.x.x';
const USERNAME = 'admin';
const PASSWORD = '';
const BASE64_ENCODED_CA = '';
const BASE64_ENCODED_CERT = '';
(async () => {
const k8sApi = new clientWrapper.Core_v1Api(ENDPOINT)
k8sApi.setDefaultAuthentication({
'applyToRequest': (opts) => {
opts.auth = {
username: USERNAME, password: PASSWORD
};
opts.ca = Buffer.from(BASE64_ENCODED_CA, 'base64');
opts.key = Buffer.from(BASE64_ENCODED_CERT, 'base64');
}
});
const res = await k8sApi.listNamespacedPod('default')
console.log(res.response.body);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment