title: How to execute command from one pod inside another pod using kubectl exec which are inside a same k8s cluster
body: <p>I have two pods in a cluster. Lets call them A and B. I've installed kubectl inside pod A and I am trying to run a command inside pod B from pod A using <code>kubectl exec -it podB -- bash</code>.
  I am getting the following error </p>
  
  <p><code>Error from server (Forbidden): pods "B" is forbidden: User "system:serviceaccount:default:default" cannot create pods/exec in the namespace "default"</code></p>
  
  <p>I've created the following Role and RoleBinding to get access.
  Role yaml</p>
  
  <pre><code>kind: Role
  apiVersion: rbac.authorization.k8s.io/v1
  metadata:
    name: api-role
    namespace: default
    labels:
      app: tools-rbac
  rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
  </code></pre>
  
  <p>RoleBinding yaml</p>
  
  <pre><code>kind: RoleBinding
  apiVersion: rbac.authorization.k8s.io/v1
  metadata:
    name: global-rolebinding
    namespace: default
    labels:
      app: tools-rbac
  subjects:
  - kind: Group
    name: system:serviceaccounts
    apiGroup: rbac.authorization.k8s.io
  </code></pre>
  
  <p>Any help is greatly appreciated. Thank you</p>