I'm trying to access Kubernetes APIs from NodeJS. Running in environment where no kubectl or gcloud command line tools are available. Using https://github.com/kubernetes-client/javascript client side SDK. The question is how to authenticate and access the remote cluster. I need this for K8s running in GCP.
In other words trying to do what "gcloud container clusters get-credentials" does, but without "gcloud" cli.
I think that you can invoke Kubernetes API from
NodeJS
using this kubernetes-client promoted by GoDaddy.Kubernetes-client
forNodeJS
simplifies a way how to adjust an interface to Kubernetes API.Below example demonstrates a way how to use a small snippet to extract all the
Deployments
in the default KubernetesNamespace
:Here you can find more snippets for using
kubernetes-client
.If you want to use Kubernetes Master API from outside, you need to authorize in one of the ways described here.
In particular, if you want to use username/password and you use GKE (k8 on GCP), then you can do it in the following steps: