๋ชฉ์ฐจ
ย Resources
ย Namespaced
์ฟ ๋ฒ๋คํฐ์ค์์ ๋ฆฌ์์ค๋ฅผ ๊ทธ๋ฃนํํ๊ฑฐ๋ ๊ฒฉ๋ฆฌํ๋ ๋ฐ Namespace๋ฅผ ์ฌ์ฉํ๋ค. ๋ค์์คํ์ด์ค ๋ฆฌ์์ค๋ ๋ค์๊ณผ ๊ฐ์ ๋ฆฌ์์ค๋ฅผ ํฌํจํ๋ค:
โข
Pods
โข
ReplicaSets
โข
Deployments
โข
Services
โข
Secrets
โข
Roles
โข
Rolebindings
โข
ConfigMaps
โข
PVC
๋ชจ๋ Namespaced resource๋ฅผ ํ์ธํ๋ ค๋ฉด kube api-resources ๋ช
๋ น์ ์คํํ๋ค.
kubectl api-resources --namespaced=true
Bash
๋ณต์ฌ
ย Cluster-Scoped
๋
ธ๋์ ๊ฐ์ ๋ฆฌ์์ค๋ ํด๋ฌ์คํฐ ์ ์ฒด์ ๊ฑธ์ณ ์์ผ๋ฉฐ, ํน์ ๋ค์์คํ์ด์ค์ ์ฐ๊ด๋ ์ ์๋ค. ํด๋ฌ์คํฐ ๋ฒ์ ๋ฆฌ์์ค๋ ๋ค์์คํ์ด์ค๋ฅผ ์ง์ ํ์ง ์๋ ๋ฆฌ์์ค์ด๋ค. ํด๋ฌ์คํฐ ๋ฒ์ ๋ฆฌ์์ค์ ํด๋น๋๋ ๋ฆฌ์์ค๋ ๋ค์๊ณผ ๊ฐ์ ๋ฆฌ์์ค๋ฅผ ํฌํจํ๋ค:
โข
Nodes
โข
Persistent Volumes
โข
ClusterRoles
โข
ClusterRoleBindings
โข
CertificateSigningRequests
โข
Namespaces
๋ชจ๋ Cluster-scoped resource๋ฅผ ํ์ธํ๋ ค๋ฉด kube api-resources ๋ช
๋ น์ ์คํํ๋ค.
kubectl api-resources --namespaced=false
Bash
๋ณต์ฌ
ย ClusterRole
Namespaced์์ ์ฌ์ฉ์์๊ฒ ๋ฆฌ์์ค์ ๊ถํ์ ๋ถ์ฌํ๋ ๊ฒ์ Role๊ณผ RoleBinding์ ์ฌ์ฉํ ๊ฒ์ฒ๋ผ, Cluster-scoped์์๋ ClusterRole๊ณผ ClusterRoleBinding์ ์ฌ์ฉํ๋ฉฐ, ํ์๋ ๋์ผํ๋ค.
ย Create
๋จผ์ ํด๋ฌ์คํฐ ์ญํ ์ ๋ํด ์์ฑํ๋ค. ์๋์ ์ฝ๋๋ node์ ๋ํด ์กฐํ, ์์ฑ, ์ญ์ ๊ฐ ๊ฐ๋ฅํ ClusterRole์ ์์ฑํ๋ ์์์ด๋ค.
# cluster-admin-role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: cluster-administrator
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["list", "get", "create", "delete"]
YAML
๋ณต์ฌ
Core Group์ ํฌํจ๋๋ ๋ฆฌ์์ค๋ apiGroups๋ฅผ ๋น์นธ์ผ๋ก ๋ ์ ์๋ค. ๋น ์นธ ์์ฒด๊ฐ Core Group์ ์๋ฏธํ๋ค.
ย Link User to ClusterRole
ClusterRole์ ์์ฑํ ํ์๋ ์ฌ์ฉ์์ ์ฐ๊ฒฐ์์ผ์ผ ํ๋ค. ์ด๋ ClusterRoleBinding์ ์ฌ์ฉํ์ฌ ์ฐ๊ฒฐ์ํจ๋ค.
# cluster-admin-role-binding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: cluster-admin-role-binding
subjects:
- kind: User
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: cluster-administrator
apiGroup: rbac.authorization.k8s.io
YAML
๋ณต์ฌ
RoleBinding๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ClusterRoleBinding์ subjects์์ ์ฌ์ฉ์์ ๋ํ ์ธ๋ถ์ ๋ณด๋ฅผ ์
๋ ฅํ๋ฉฐ, roleRef์์ ClusterRole์ ๋ํ ์ ๋ณด๋ฅผ ์
๋ ฅํ๋ค. ๋ํ subjects๋ ๋ฆฌ์คํธ ํํ๋ฅผ ๊ฐ์ง๋ค.
ย ClusterRole for Namespaced
Kubernetes์์ ๊ถํ ๊ด๋ฆฌ๋ ๋ฆฌ์์ค์ ๋ฒ์์ ๋ฐ๋ผ ๋ฌ๋ผ์ง๋ค. ์ผ๋ฐ์ ์ผ๋ก ClusterRole๊ณผ ClusterRoleBinding์ ํด๋ฌ์คํฐ ๋ฒ์ ๋ฆฌ์์ค์ ์ฌ์ฉ๋๋ค. ๊ทธ๋ฌ๋ ์ด๋ ์๊ฒฉํ ๊ท์น์ด ์๋๋ค. ClusterRole์ ๋ค์์คํ์ด์ค ๋ฆฌ์์ค์๋ ์ ์ฉํ ์ ์๋ค.
ClusterRole์ ๋ค์์คํ์ด์ค ๋ฆฌ์์ค์ ์์ฑํ๋ฉด, ์ฌ์ฉ์๋ ๋ชจ๋ ๋ค์์คํ์ด์ค์์ ํด๋น ๋ฆฌ์์ค์ ์ ๊ทผํ ์ ์๊ฒ ๋๋ค. ์๋ฅผ๋ค์ด ํน์ ๋ค์์คํ์ด์ค์์๋ง ํ๋์ ์ ๊ทผํ ์ ์๋ ๊ถํ์ ๋ถ์ฌํ๋ ์ญํ ์ด ์๋ค๋ฉด, ์ฌ์ฉ์๋ ํด๋น ๋ค์์คํ์ด์ค์ ํ๋์๋ง ์ ๊ทผํ ์ ์์๋ค. ํ์ง๋ง ClusterRole์ ์ฌ์ฉํ๋ฉด, ์ฌ์ฉ์๋ ํด๋ฌ์คํฐ ๋ด์ ๋ชจ๋ ํ๋์ ์ ๊ทผํ ์ ์๋ค.