<hr />
<p>So like you said I created a another pod which is of kind:job and included the script.sh.</p>
<p>In the script.sh file, I run &quot;kubectl exec&quot; to the main pod to run few commands</p>
<p>The script gets executed, but I get the error &quot;cannot create resource &quot;pods/exec in API group&quot;</p>
<p>So I created a clusterrole with resources: [&quot;pods/exec&quot;] and bind it to the default service account using ClusterRoleBinding</p>
<pre><code>kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: pod-reader
rules:
- apiGroups: [&quot;&quot;]
  resources: [&quot;pods&quot;, &quot;pods/log&quot;]
  verbs: [&quot;get&quot;, &quot;list&quot;]
- apiGroups: [&quot;&quot;]
  resources: [&quot;pods/exec&quot;]
  verbs: [&quot;create&quot;]

--- 

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: service-account-role-binding
  namespace: default
subjects:
  - kind: ServiceAccount
    name: default
    namespace: default
roleRef:
  kind: ClusterRole
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

---

apiVersion: v1
kind: ServiceAccount
metadata:
  name: default
  namespace: default


In the pod which is of kind:job, I include the service account like shown below

restartPolicy: Never
serviceAccountName: default

but I still get the same error. What am I doing wrong here ?

</code></pre>
<pre><code>Error from server (Forbidden): pods &quot;mongo-0&quot; is forbidden: User &quot;system:serviceaccount:default:default&quot; cannot create resource &quot;pods/exec&quot; in API group &quot;&quot; in the namespace &quot;default&quot;
</code></pre>
<pre><code></code></pre>

jeril
<p>If this is something that needs to be regularly run for maintenance look into Kubernetes daemon set object.</p>
