<p>I want to access only one pod remotely using kubectl so followed instructions mentiond <a href="https://jeremievallee.com/2018/05/28/kubernetes-rbac-namespace-user.html" rel="nofollow noreferrer">here</a>.</p>
<p>In order to do so, I created a <code>access.yml</code> file in kubernetes:</p>
<pre><code>---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: devops-user
  namespace: default

---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: devops-user-limited-access
  namespace: default
rules:
- apiGroups: [&quot;&quot;, &quot;extensions&quot;, &quot;apps&quot;]
  resources: [&quot;*&quot;]
  verbs: [&quot;*&quot;]

---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: devops-user-view
  namespace: default
subjects:
- kind: ServiceAccount
  name: devops-user
  namespace: default
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: devops-user-limited-access
</code></pre>
<p>In my remote laptop I created a file in <code>~/.kube/config</code> like this:</p>
<pre><code>apiVersion: v1
kind: Config
preferences: {}

# Define the cluster
clusters:
- cluster:
    certificate-authority-data: &lt;my-ca.crt&gt;
    # You'll need the API endpoint of your Cluster here:
    server: https://&lt;server-ip&gt;:6443
  name: kubernetes

# Define the user
users:
- name: devops-user
  user:
    as-user-extra: {}
    client-key-data: &lt;my-ca.crt&gt;
    token: &lt;token-created-by-k8s&gt;

# Define the context: linking a user to a cluster
contexts:
- context:
    cluster: kubernetes
    namespace: default
    user: devops-user
  name: default

# Define current context
current-context: default
</code></pre>
<p>Now I have &quot;full access&quot; to &quot;all pods&quot; but this is not what I want. I just want to have:</p>
<blockquote>
<p>I want &quot;full access&quot; to only &quot;one pod&quot;.</p>
</blockquote>

Vahid F
<p>just add this to your role file</p>
<pre><code>resourceNames: [&quot;POD_NAME&quot;]
</code></pre>
<p>so your role yaml file should be like this</p>
<pre><code>kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: devops-user-limited-access
  namespace: default
rules:
- apiGroups: [&quot;&quot;, &quot;extensions&quot;, &quot;apps&quot;]
  resources: [&quot;pods&quot;, &quot;pods/log&quot;]
  resourceNames: [&quot;POD_NAME&quot;] &lt;-------------------------------here
  verbs: [&quot;get&quot;, &quot;list&quot;]
</code></pre>
