show k8s rbac usage
$ openssl genrsa -out jwang.key 2048
$ openssl req -new -key jwang.key -out jwang.csr -subj "/CN=jwang/O=intelssp"
$ sudo openssl x509 -req -in jwang.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.ke
y -CAcreateserial -out jwang.crt -days 500
# print certificate content
$ openssl x509 -in jwang.crt -text -noout
$ kubectl config set-credentials jwang --client-certificate=jwang.crt --client-key=jwang.key
$ kubectl config set-context jwang-context --cluster=kubernetes --namespace=kube-system --user=jwang
# check config status
$ kubectl config view
$ kubectl get pods --context=jwang-context
It is forbidden as new user not grant any role
$ kubectl apply -f jwang-role.yml
$ kubectl create -f jwang-rolebindingl.yml
$$ kubectl get pods --context=jwang-context
you can see right result of pod, however get service still forbidden
$ kubectl get svc --context=jwang-context
$ kubectl create sa haimaxy-sa -n kube-system
$ kubectl apply -f jwang-sa-role.yml
$ kubectl create -f jwang-sa-rolebindingl.yml
$ kubectl get secret -n kube-system |grep jwang-sa
haimay-sa-token-nxgqx kubernetes.io/service-account-token 3 47m
# get base64 token
$ kubectl get secret jwang-sa-token-nxgqx -o jsonpath={.data.token} -n kube-system |base64 -d