The rest API to get logs of a pod is
GET /api/v1/namespaces/{namespace}/pods/{name}/log
You can pass container as a query param to above API to get logs of a particular container
GET /api/v1/namespaces/{namespace}/pods/{name}/log?container=containername
When you hit above APIs from code using a service account or a user you need to have below RBAC Role
and RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: pod-logs-reader
rules:
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get", "list"]
The API is documented here