Skip to content

Error setting user info form Default config ~/.kube/config. #294

@KiranRamashetty

Description

@KiranRamashetty

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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions