<p>I'm new to kubernetes. I'm trying to list all the pods in a namespace from inside a pod/container via the javascript client.  </p>

<pre><code>import k8s = require('@kubernetes/client-node');

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

const k8sApi = kc.makeApiClient(k8s.Core_v1Api);

k8sApi.listNamespacedPod('development')
    .then((res) =&gt; {
        console.log(res.body);
    }).catch((err) =&gt; {
        console.log(err);
    });
</code></pre>

<p>The response error when I look at my pod logs:</p>

<pre><code>{ kind: 'Status',
 apiVersion: 'v1',
 metadata: {},
 status: 'Failure',
 message:
  'pods is forbidden: User "system:serviceaccount:default:default" cannot list pods in the namespace "development"',
 reason: 'Forbidden',
 details: { kind: 'pods' },
 code: 403 } } 
</code></pre>

<p>I believe I need to create a new User or add some permissions to a Role but I'm not sure where and how. Thanks</p>

cmar
<p>As @<a href="https://stackoverflow.com/users/2779488/robert-panzer">Robert Panzer</a> suggested in <a href="https://stackoverflow.com/questions/47813698/access-kubernetes-api-without-kubectl">Access Kubernetes API without kubectl</a>, you can create a role and a rolebinding to enable listing of pods with:</p>

<pre><code>apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: pod-reader
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "watch", "list"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: pod-reader
subjects:
- kind: ServiceAccount
  name: default
  namespace: default
roleRef:
  kind: ClusterRole
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io
</code></pre>
