javascript: Error setting user info form Default config ~/.kube/config.

Trying to get list of pods using the default config file (set by kubectl). Getting an error setting user info

"pods is forbidden: User “system:anonymous” cannot list resource “pods” in API group “” in the namespace “infra”

Node JS code snippet

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

tried with python and it works as expected

from kubernetes import client, config

# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config()

v1 = client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_namespaced_pod("infra")
for i in ret.items:
    print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 22 (17 by maintainers)

Commits related to this issue

Most upvoted comments

I finished the code and opened a PR @brendandburns @silasbw thanks for your help guys!