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.
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) => {
console.log(res.body);
}).catch((err) => {
console.log(err);
});
The response error when I look at my pod logs:
{ 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 } }
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