Last active
December 19, 2017 22:58
-
-
Save sandipchitale/f130081f9eff88dd0998fcd466d044d6 to your computer and use it in GitHub Desktop.
Get Pods from minikube kubernetes
This file contains hidden or 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 k8s --save | |
// npm install js-yaml --save | |
import { Observable } from 'rxjs'; | |
import * as fs from 'fs'; | |
import * as os from 'os'; | |
import * as K8s from 'k8s'; | |
import * as jsyaml from 'js-yaml'; | |
const config = jsyaml.safeLoad(fs.readFileSync(`${os.homedir()}/.kube/config`, 'utf8')); | |
const kubeapi = K8s.api({ | |
endpoint: config.clusters[0].cluster.server, | |
version: '/api/v1', | |
auth: { | |
clientCert: fs.readFileSync(`${os.homedir()}/.minikube/apiserver.crt`).toString(), | |
clientKey: fs.readFileSync(`${os.homedir()}/.minikube/apiserver.key`).toString() , | |
caCert: fs.readFileSync(`${config.clusters[0].cluster['certificate-authority']}`).toString() | |
} | |
}); | |
const pods = Observable.fromPromise(kubeapi.get('namespaces/default/pods')); | |
pods.subscribe( | |
(data) => { console.dir(data) }, | |
(err) => { console.error(err) } | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment