반응형
쿠버네티스에서는 Container를 생성할때 PV를 마운트할 수 있는데 PV를 일일이 만들어서 할당하는것이 아닌 NFS에서 동적으로 할당 받을수 있다.
아래의 yaml 파일을 순서대로 apply 시켜준다
#class.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs-client
provisioner: k8s-sigs.io/nfs-subdir-external-provisioner # or choose another name, must match deployment's env PROVISIONER_NAME'
parameters:
archiveOnDelete: "true"
#rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: nfs-client-provisioner-runner
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "watch", "create", "delete"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: run-nfs-client-provisioner
subjects:
- kind: ServiceAccount
name: nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
roleRef:
kind: ClusterRole
name: nfs-client-provisioner-runner
apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: leader-locking-nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: leader-locking-nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
subjects:
- kind: ServiceAccount
name: nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
roleRef:
kind: Role
name: leader-locking-nfs-client-provisioner
apiGroup: rbac.authorization.k8s.io
#deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nfs-client-provisioner
labels:
app: nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: nfs-client-provisioner
template:
metadata:
labels:
app: nfs-client-provisioner
spec:
serviceAccountName: nfs-client-provisioner
containers:
- name: nfs-client-provisioner
image: registry.k8s.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: k8s-sigs.io/nfs-subdir-external-provisioner
- name: NFS_SERVER
value: nfs-ip
- name: NFS_PATH
value: nfs-path
volumes:
- name: nfs-client-root
nfs:
server: nfs-ip
path: nfs-path
deploy.yaml 파일의 경우 NFS 서버 아이피와 폴더를 개인환경에 맞게 설정하면된다.
Dynamic provisioning NFS 서버를 구축했으므로 별도의 PV를 만들지 않고 바로 PVC를 만들어 PV를 할당받아오자.
#example
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: example-pvc
namespace: test
spec:
storageClassName: nfs-client
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
metadata와 spec을 개인 환경에 맞추어 셋팅해주고 apply 해준다면 PV를 할당받아온다.
반응형
'쿠버네티스' 카테고리의 다른 글
[Kubernetes] 쿠버네티스 모니터링 시스템 구축 - 1 (0) | 2023.06.22 |
---|---|
[Kubernetes] EFK 구축 (0) | 2023.06.22 |
[Kubernetes] MetricServer 설치 (0) | 2023.06.20 |
[Kubernetes] 쿠버네티스 CNI 설치 -flannel (0) | 2023.06.20 |
[Kubernetes] 쿠버네티스 클러스터 구축 (0) | 2023.06.20 |