kubectl create -f myapp.yaml
kubectl get pods -n engineering
kubectl get pods -n engineering --as bob
cat >> eng_role.yaml <<EOF
heredoc> kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: engineering
name: eng-reader
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["pods", "services", "nodes"]
verbs: ["get", "watch", "list"]
heredoc> EOF
kubectl create -f eng_role.yaml
kubectl get roles --namespace=engineering
cat >> role_binding_bob.yaml <<EOF
heredoc> kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: eng-read-access
namespace: engineering
subjects:
- kind: User
name: bob # Name is case sensitive
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role #this must be Role or ClusterRole
name: eng-reader # this must match the name of the Role or ClusterRole you wish to bind to
apiGroup: rbac.authorization.k8s.io
heredoc> EOF
kubectl apply -f role_binding_bob.yaml
kubectl get rolebindings -n engineering