<p>As of now what i did is that, Created kubernetes cluster and enabled RBAC in web UI while creating the cluster.Inside the cluster i created a namespace named as <strong>development1</strong>.Now i wanted to give access to a user on some kubernetes resources which are belongs to development1 namespace.For that i created a role and add a 
user for a particular namespace.</p>

<p>Here is my configuration files:</p>

<p>deployment.yaml</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: hellonode
  namespace: development1
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: samplenodeapp
    spec:
      containers:
      - name: hellonode
        image: hellonode.azurecr.io/aks-deployments:latest
        ports:
        - containerPort: 3000
      imagePullSecrets:
      - name: webinar
</code></pre>

<p>service.yaml</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: hellonode
  namespace: development1
  labels:
    app: samplenodeapp
spec:
  type: LoadBalancer
  ports:
  - port: 3000
  selector:
    app: samplenodeapp
</code></pre>

<p>role.yaml</p>

<pre><code>kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  namespace: development1
  name: developer-role
rules:
- apiGroups: ["", "extensions", "apps"]
  resources: ["deployments", "replicasets"]
  verbs: ["*"]
rules:
- apiGroups: [""]
  resources: ["pods","pods/log","pods/exec"]
  verbs: ["get", "list", "watch", "create", "update", "patch"]
</code></pre>

<p>rolebinding.yaml</p>

<pre><code>kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: developer-rb
  namespace: development1
subjects:
- kind: User
  name: &lt; Azure_AD_user_object-id&gt;
  apiGroup: "rbac.authorization.k8s.io"
roleRef:
  kind: Role
  name: developer-role
  apiGroup: "rbac.authorization.k8s.io"
</code></pre>

<p>Now i am trying to list the pods in deveploment1(namespace) using the command <code>kubectl get pods -n development --user=&lt;Azure _AD_username&gt;</code>. Instead of list the pods, getting the error like</p>

<blockquote>
  <p>error: You must be logged in to the server (Unauthorized).</p>
</blockquote>

<p>Here my doubts are, Is there any necessity to create context for that namespace? and shall i add role in deployment.yaml and service.yaml?</p>

<p>I don't know something which i missed. Could any anybody suggest me, how can i give the permissions for a user on kubernetes resources in Azure?</p>

BSG
<p>you need to login to Azure Cli as that Azure AD user and pull the k8s config as that user (az aks get-credentials -n xxx -g xxx) and run <code>kubectl get po -n development</code>. I'm not sure what <code>--user</code> parameter means, but I would expect it to try and use that user from your kubeconfig (which you dont have). I cant find any references to allowing user impersonalisation using kubectl.</p>

<p>Dont forget to purge your kubeconfig before hand.</p>
