Search code examples
node.jskuberneteskubectl

how i may get name of all namespaces (@kubernetes/client-node)


I work with API kuberneteswith (library is @kubernetes/client-node). I can to get a list of pods of specigic namespace, but i don`t understand to get a list of name all namespaces How i may code with @kubernetes/client-node?


Solution

  • In the corev1 API, it's listNamespace.

    const k8s = require('@kubernetes/client-node');
    
    const kc = new k8s.KubeConfig();
    kc.loadFromDefault();
    
    const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
    
    k8sApi.listNamespace().then((res) => {
        console.log(res.body);
    });