-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy path02-create-rbac-rules.bash
60 lines (40 loc) · 1.53 KB
/
02-create-rbac-rules.bash
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
57
58
59
60
#!/bin/bash
#
# Online Talk part 2: Setting RBAC rules
#
# At the end of this script, you will create some access rules for your newly created user
## Switch to admin
kubectl config use-context minikube
## Create a namespace for the new user
kubectl create ns test
## Give the user privileges to see pods in the "test" namespace
kubectl apply -f ./yaml/01-pod-access-role.yaml
kubectl apply -f ./yaml/03-devs-read-pods.yaml
## Switch to the new user and try executing these commands now
kubectl config use-context jsalmeron@minikube
kubectl get pods
kubectl get pods -n test
kubectl run -n test nginx --image=nginx --replicas=2
## Switch to admin again
kubectl config use-context minikube
## Now we will grant administrator access in the namespace
kubectl apply -f ./yaml/02-ns-admin-role.yaml
kubectl apply -f ./yaml/04-salme-ns-admin.yaml
## Switch to the user and let's try deploying
kubectl config use-context jsalmeron@minikube
kubectl run -n test nginx --image=nginx --replicas=2
kubectl get pods -n test -w
kubectl expose deployment nginx -n test --type=NodePort --port=80
kubectl get svc -n test
kubectl run nginx --image=nginx --replicas=2
## Finally, we will grant the user full pod read access
kubectl config use-context minikube
kubectl apply -f ./yaml/05-all-pods-access.yaml
kubectl apply -f ./yaml/06-salme-reads-all-pods.yaml
## Test now
kubectl config use-context jsalmeron@minikube
kubectl get pods -n test
kubectl get pods
kubectl get pods -n kube-system
kubectl get svc
kubectl run nginx --image=nginx --replicas=2