My objetive is to see logs from pods belonging to other namespaces, in order to diagnose problems.
Here are the permissions I’ve configured:
apiVersion: v1
kind: ServiceAccount
metadata:
name: default
namespace: jenkins
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: listar-recursos
rules:
- apiGroups: [""]
resources: ["pods", "pods/log"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: asgina-lista-recursos
namespace: jenkins
subjects:
- kind: ServiceAccount
name: default
namespace: jenkins
roleRef:
kind: ClusterRole
name: listar-recursos
apiGroup: rbac.authorization.k8s.io
Here is the result after running:
kubectl logs -l name=myapp -n anothernamespace
Error from server (Forbidden): pods is forbidden: User "system:serviceaccount:jenkins:default" cannot list resource "pods" in API group "" in the namespace "anothernamespace"