Created
May 1, 2018 20:22
-
-
Save zhangyuan/fbd813fd08c5d1aa1c396faafe22e24e to your computer and use it in GitHub Desktop.
make api calls to kubernetes cluster with nodejs and explicit configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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