touk@k8smaster:~/k8s-users$ kubectl --kubeconfig taki.config version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.1", GitCommit:"4c9411232e10168d7b050c49a1b59f6df9d7ea4b", GitTreeState:"clean", BuildDate:"2023-04-14T13:21:19Z", GoVersion:"go1.20.3", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v5.0.1
Server Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.1", GitCommit:"4c9411232e10168d7b050c49a1b59f6df9d7ea4b", GitTreeState:"clean", BuildDate:"2023-04-14T13:14:42Z", GoVersion:"go1.20.3", Compiler:"gc", Platform:"linux/amd64"}
**Create Role and RoleBinding
kubectl --namespace databases create role databasemanager --verb=list,get,create,delete --resource=pods
touk@k8smaster:~/k8s-users$ k get roles
NAME CREATED AT
databasemanager 2023-09-09T14:34:30Z
touk@k8smaster:~/k8s-users$ kubectl --namespace databases describe rolebinding
Name: databasemanagerbinding
Labels: <none>
Annotations: <none>
Role:
Kind: Role
Name: databasemanager
Subjects:
Kind Name Namespace
---- ---- ---------
User taki
And now the user will be able to use the cluster with it’s permission:
touk@k8smaster:~/k8s-users$ kubectl --kubeconfig taki.config --namespace databases get pods
No resources found in databases namespace.
And if i try to interact with something else than pods:
kubectl --kubeconfig taki.config --namespace databases get services
This error show: Error from server (Forbidden): services is forbidden: User "taki" cannot list resource "services" in API group "" in the namespace "databases"
Let’s create a pod:
kubectl --kubeconfig taki.config --namespace databases run --image=mysql --port=3306 mysqldb
touk@k8smaster:~/k8s-users$ kubectl --kubeconfig taki.config --namespace databases run --image=mysql --port=3306 mysqldb
pod/mysqldb created
From kodecloud lab:
How to creat a context for a specifi user
kubectl config set-credentials martin --client-certificate=martin.crt --client-key=martin.key