Kubernetes ๋ฒ์ ( kubectl version
): ํด๋ผ์ด์ธํธ ๋ฒ์ : version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1", GitCommit:"82450d03cb057bab0950214ef122b67c83fb11df"," GitTreeState , BuildDate:"2016-12-14T00:57:05Z", GoVersion:"go1.7.4", ์ปดํ์ผ๋ฌ:"gc", ํ๋ซํผ:"darwin/amd64"}
์๋ฒ ๋ฒ์ : version.Info{์ฃผ:"1", ๋ถ:"5+", GitVersion:"v1.5.1-3+10e41f22e4421c", GitCommit:"10e41f22e4421c9a14e9e6782c6375c199"a07a8 -15T10:06:44Z", GoVersion:"go1.7.4", ์ปดํ์ผ๋ฌ:"gc", ํ๋ซํผ:"linux/amd64"}
ํ๊ฒฝ :
uname -a
): 3.10.0-327.36.3.el7.x86_64์ผ์ด๋ ์ผ : RBAC ์ธ์ฆ์ ํ์ฑํํ์ต๋๋ค. ๋ ๊ฐ์ง ์ญํ ๋ฐ์ธ๋ฉ์ด ์์ต๋๋ค.
apiVersion: rbac.authorization.k8s.io/v1alpha1
kind: ClusterRoleBinding
metadata:
name: cluster-admin-custom
subjects:
- kind: ServiceAccount
name: default
namespace: kube-system
- kind: User
name: kubelet
namespace: kube-system
- kind: User
name: clusteradmin
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
๊ทธ๋ฆฌ๊ณ
apiVersion: rbac.authorization.k8s.io/v1alpha1
kind: RoleBinding
metadata:
name: default-admin
namespace: default
subjects:
- kind: ServiceAccount
name: default
- kind: User
name: defaultadmin
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
๋ฐ๋ผ์ kube ํด๋ฌ์คํฐ์ ๋ชจ๋ ํญ๋ชฉ์ ์ก์ธ์คํ ์ ์๋ clusteradmin๊ณผ ๊ธฐ๋ณธ ๋ค์์คํ์ด์ค์ ๋ชจ๋ ๋ฆฌ์์ค์ ์ก์ธ์คํ ์ ์๋ defaultadmin์ด๋ผ๋ ๋ ๊ฐ์ง ์ฌ์ฉ์๊ฐ ์์ต๋๋ค. clusteradmin์ ์ฌ์ฉํ์ฌ PV ๋ช ๋ น์ ์คํํ๋ฉด ์ ์๋ํ์ง๋ง ๊ธฐ๋ณธ ๋ค์์คํ์ด์ค์์ defaultadmin์ ์ฌ์ฉํ๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
kubectl pv ๊ฐ์ ธ์ค๊ธฐ
์๋ฒ ์ค๋ฅ(๊ธ์ง๋จ): ์๋ฒ๊ฐ ์์ฒญ๋ ๋ฆฌ์์ค์ ๋ํ ์ก์ธ์ค๋ฅผ ํ์ฉํ์ง ์์ต๋๋ค(์๊ตฌ ๋ณผ๋ฅจ ๊ฐ์ ธ์ค๊ธฐ).
์๋ฒ ์ค๋ฅ(๊ธ์ง๋จ): "db-pv.yaml" ์์ฑ ์ ์ค๋ฅ: ์๋ฒ๊ฐ ์์ฒญ๋ ๋ฆฌ์์ค์ ๋ํ ์ก์ธ์ค๋ฅผ ํ์ฉํ์ง ์์ต๋๋ค(์๊ตฌ ๋ณผ๋ฅจ ์ดํ).
์์ํ ์ผ : defaultadmin์ ์ ์๋(๋ด ๊ฒฝ์ฐ์๋ ๊ธฐ๋ณธ) ๋ค์์คํ์ด์ค์ PV ๋ฆฌ์์ค์ ์ก์ธ์คํ ์ ์์ด์ผ ํฉ๋๋ค. ์๋ํ๋ฉด cluster-admin clusterrole์ ๋ค์๊ณผ ๊ฐ์ด ๋งํ๊ธฐ ๋๋ฌธ์ ๋๋ค.
- apiGroups:
- '*'
attributeRestrictions: null
resources:
- '*'
verbs:
- '*'
- attributeRestrictions: null
nonResourceURLs:
- '*'
verbs:
- '*'
์ฌ๊ธฐ์ ์ค์ํ ๊ฒ์ ๋ฆฌ์์ค *์ด์ง๋ง PV๊ฐ ์์ผ๋ ์นด๋์ ์ผ๋ถ๊ฐ ์๋ ๊ฒ์ฒ๋ผ ๋๊ปด์ง๋๋ค.
๊ทธ๊ฒ์ ์ฌํํ๋ ๋ฐฉ๋ฒ (๊ฐ๋ฅํ ํ ์ต์ํ์ผ๋ก ๊ทธ๋ฆฌ๊ณ ์ ํํ๊ฒ):
dev
๋ฐ default
ํฌํจํ ๋ช ๊ฐ์ง ๋ค์์คํ์ด์ค๊ฐ ์๋ ๋น์ทํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. "dev ์ฌ์ฉ์"๋ก์ PVC๋ฅผ ํฌํจํ์ฌ dev
๋ค์์คํ์ด์ค์ ๋ง์ ๋ฆฌ์์ค๋ฅผ ์์ฑํ ์ ์์ง๋ง dev
๋ค์์คํ์ด์ค์ "dev user"๋ก PV๋ฅผ ์์ฑํ๋ฉด ๋์ผํ ๊ฒฐ๊ณผ๊ฐ ๋ํ๋ฉ๋๋ค. ์์ ๊ฐ์ ์ค๋ฅ:
Error from server (Forbidden): error when creating "db-pv.yaml": the server does not allow access to the requested resource (post persistentvolumes)
default
๋ค์์คํ์ด์ค์์ ๊ด๋ฆฌ์๋ก PV๋ฅผ ์์ฑํ๋ฉด ๋ชจ๋ ๊ฒ์ด ์ ์์
๋๋ค.
PV๊ฐ ๋ค์์คํ์ด์ค์ ์ฐ๊ฒฐ๋์ง ์์์ต๋๋ค.
PV๋ ํด๋ฌ์คํฐ ๋ฒ์ ๊ฐ์ฒด์ ๋๋ค. ๋ค์์คํ์ด์ค์ ์กด์ฌํ์ง ์์ต๋๋ค. RBAC์ ํจ๊ป ํ์ ๊ด ๋ฐ์ API๋ฅผ ์ฌ์ฉํ ์์๋ ๊ถํ์ ์ป์ผ๋ ค๋ฉด ๋น์ ์ ClusterRole๊ฐ ClusterRoleBindingํ์ฌ ํด๋ฌ์คํฐ ๋ฒ์์์ ๋ฐ์ธ๋ฉ์ด ํ์ํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
PV๋ ํด๋ฌ์คํฐ ๋ฒ์ ๊ฐ์ฒด์ ๋๋ค. ๋ค์์คํ์ด์ค์ ์กด์ฌํ์ง ์์ต๋๋ค. RBAC์ ํจ๊ป ํ์ ๊ด ๋ฐ์ API๋ฅผ ์ฌ์ฉํ ์์๋ ๊ถํ์ ์ป์ผ๋ ค๋ฉด ๋น์ ์ ClusterRole๊ฐ ClusterRoleBindingํ์ฌ ํด๋ฌ์คํฐ ๋ฒ์์์ ๋ฐ์ธ๋ฉ์ด ํ์ํฉ๋๋ค.