How to restrict the privilege of kubectl command

12/21/2021

I would like to grant one user only the "get" privilege of "kubectl" command. I suppose it should be done with RBAC, anyone can advise it, thanks.

-- James Pei
kubernetes

1 Answer

12/21/2021

Create a allow-get.yaml file with the next content and change my-user by your user, and run kubectl apply -f allow-get.yaml

apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: allow-get
rules:
- apiGroups:
  - ""
  resources:
  - "*"
  verbs:
  - get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: allow-get-bind
subjects:
  - kind: User
    name: my-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: allow-get
-- TlmaK0
Source: StackOverflow