-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard-adminuser.yaml
More file actions
56 lines (45 loc) · 2 KB
/
dashboard-adminuser.yaml
File metadata and controls
56 lines (45 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# This yaml helps to create a new user using the Service Account mechanism of Kubernetes,
# grant this user admin permissions and login to Dashboard using a bearer token tied to this user.
# Note: he sample user created in the tutorial
# will have administrative privileges and is for educational purposes only.
# We are creating Service Account with the name admin-user in namespace kubernetes-dashboard first.
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
---
# In most cases after provisioning the cluster using kops, kubeadm or any other popular tool,
# the ClusterRole cluster-admin already exists in the cluster.
# We can use it and create only a ClusterRoleBinding for our ServiceAccount.
# If it does not exist then you need to create this role first and grant required privileges manually.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
---
# //Once apply is done follow below as:
#kubectl get svc -n kubernetes-dashboard kubernetes-dashboard
#kubectl edit svc -n kubernetes-dashboard kubernetes-dashboard //as: NP/LB
# //Now we need to find the token we can use to log in. as:
# kubectl -n kubernetes-dashboard create token admin-user >~/k8s-bootstrap/dashboard-user.token
# kubectl get svc -A
# cat ~/dashboard-user.token
# //Kubectl will make Dashboard available at
# host/vm-ip:<svc-random-port>
# OR
# http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
# //Now copy the token and paste it into the Enter token field on the login screen.
# //We can Remove the admin ServiceAccount and ClusterRoleBinding.
# kubectl -n kubernetes-dashboard delete serviceaccount admin-user
# kubectl -n kubernetes-dashboard delete clusterrolebinding admin-user
# OR
# kubectl delete -f dashboard-adminuser.yaml