Skip to content

Commit 06b1d0f

Browse files
authored
Merge pull request #49720 from NareshKoduru/extra_line
docs(style): embed rolebinding code samples
2 parents b417e36 + 8b78fb8 commit 06b1d0f

File tree

5 files changed

+51
-55
lines changed

5 files changed

+51
-55
lines changed

content/en/docs/reference/access-authn-authz/rbac.md

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,7 @@ Here is an example of a RoleBinding that grants the "pod-reader" Role to the use
123123
within the "default" namespace.
124124
This allows "jane" to read pods in the "default" namespace.
125125

126-
```yaml
127-
apiVersion: rbac.authorization.k8s.io/v1
128-
# This role binding allows "jane" to read pods in the "default" namespace.
129-
# You need to already have a Role named "pod-reader" in that namespace.
130-
kind: RoleBinding
131-
metadata:
132-
name: read-pods
133-
namespace: default
134-
subjects:
135-
# You can specify more than one "subject"
136-
- kind: User
137-
name: jane # "name" is case sensitive
138-
apiGroup: rbac.authorization.k8s.io
139-
roleRef:
140-
# "roleRef" specifies the binding to a Role / ClusterRole
141-
kind: Role #this must be Role or ClusterRole
142-
name: pod-reader # this must match the name of the Role or ClusterRole you wish to bind to
143-
apiGroup: rbac.authorization.k8s.io
144-
```
126+
{{% code_sample file="access/simple-rolebinding-with-role.yaml" %}}
145127

146128
A RoleBinding can also reference a ClusterRole to grant the permissions defined in that
147129
ClusterRole to resources inside the RoleBinding's namespace. This kind of reference
@@ -152,48 +134,15 @@ For instance, even though the following RoleBinding refers to a ClusterRole,
152134
"dave" (the subject, case sensitive) will only be able to read Secrets in the "development"
153135
namespace, because the RoleBinding's namespace (in its metadata) is "development".
154136

155-
```yaml
156-
apiVersion: rbac.authorization.k8s.io/v1
157-
# This role binding allows "dave" to read secrets in the "development" namespace.
158-
# You need to already have a ClusterRole named "secret-reader".
159-
kind: RoleBinding
160-
metadata:
161-
name: read-secrets
162-
#
163-
# The namespace of the RoleBinding determines where the permissions are granted.
164-
# This only grants permissions within the "development" namespace.
165-
namespace: development
166-
subjects:
167-
- kind: User
168-
name: dave # Name is case sensitive
169-
apiGroup: rbac.authorization.k8s.io
170-
roleRef:
171-
kind: ClusterRole
172-
name: secret-reader
173-
apiGroup: rbac.authorization.k8s.io
174-
```
137+
{{% code_sample file="access/simple-rolebinding-with-clusterrole.yaml" %}}
175138

176139
#### ClusterRoleBinding example
177140

178141
To grant permissions across a whole cluster, you can use a ClusterRoleBinding.
179142
The following ClusterRoleBinding allows any user in the group "manager" to read
180143
secrets in any namespace.
181144

182-
```yaml
183-
apiVersion: rbac.authorization.k8s.io/v1
184-
# This cluster role binding allows anyone in the "manager" group to read secrets in any namespace.
185-
kind: ClusterRoleBinding
186-
metadata:
187-
name: read-secrets-global
188-
subjects:
189-
- kind: Group
190-
name: manager # Name is case sensitive
191-
apiGroup: rbac.authorization.k8s.io
192-
roleRef:
193-
kind: ClusterRole
194-
name: secret-reader
195-
apiGroup: rbac.authorization.k8s.io
196-
```
145+
{{% code_sample file="access/simple-clusterrolebinding.yaml" %}}
197146

198147
After you create a binding, you cannot change the Role or ClusterRole that it refers to.
199148
If you try to change a binding's `roleRef`, you get a validation error. If you do want
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
# This cluster role binding allows anyone in the "manager" group to read secrets in any namespace.
3+
kind: ClusterRoleBinding
4+
metadata:
5+
name: read-secrets-global
6+
subjects:
7+
- kind: Group
8+
name: manager # Name is case sensitive
9+
apiGroup: rbac.authorization.k8s.io
10+
roleRef:
11+
kind: ClusterRole
12+
name: secret-reader
13+
apiGroup: rbac.authorization.k8s.io
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
# This role binding allows "dave" to read secrets in the "development" namespace.
3+
# You need to already have a ClusterRole named "secret-reader".
4+
kind: RoleBinding
5+
metadata:
6+
name: read-secrets
7+
#
8+
# The namespace of the RoleBinding determines where the permissions are granted.
9+
# This only grants permissions within the "development" namespace.
10+
namespace: development
11+
subjects:
12+
- kind: User
13+
name: dave # Name is case sensitive
14+
apiGroup: rbac.authorization.k8s.io
15+
roleRef:
16+
kind: ClusterRole
17+
name: secret-reader
18+
apiGroup: rbac.authorization.k8s.io
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
# This role binding allows "jane" to read pods in the "default" namespace.
3+
# You need to already have a Role named "pod-reader" in that namespace.
4+
kind: RoleBinding
5+
metadata:
6+
name: read-pods
7+
namespace: default
8+
subjects:
9+
# You can specify more than one "subject"
10+
- kind: User
11+
name: jane # "name" is case sensitive
12+
apiGroup: rbac.authorization.k8s.io
13+
roleRef:
14+
# "roleRef" specifies the binding to a Role / ClusterRole
15+
kind: Role #this must be Role or ClusterRole
16+
name: pod-reader # this must match the name of the Role or ClusterRole you wish to bind to
17+
apiGroup: rbac.authorization.k8s.io

content/en/examples/controllers/job.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ spec:
1111
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
1212
restartPolicy: Never
1313
backoffLimit: 4
14-

0 commit comments

Comments
 (0)