Search code examples
node.jskuberneteskubectl

how i may connect to API kube with server account (@kubernetes/client-node)


i can to connect to API kube with kubectl and file config (library is @kubernetes/client-node). i want to run my application in conteiner without kubectl. How i may connect to API kube with server account without file config?


Solution

  • if you are running your code inside the container you can directly use the default config using

    const kc = new k8s.KubeConfig();
    kc.loadFromDefault();
    

    with this method, there is no requirement to pass the config and inside container, it will auto adjust the config you can use the API directly.

    for service account access your can check this document : https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/

    how to generate the service account & secret token that will call the API server : https://cloudhedge.io/setting-up-kubernetes-api-access-using-service-account/