sudo systemctl restart nfs-fernel-server
sudo mkdir /nfsvolume
sudo cd /nfsvolume
rm /nfsvolume/* #안에 파일이 있다면 다 지워줌
https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner
git clone https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner.git
cd nfs-subdir-external-provisioner/deploy
kubectl create -f rbac.yaml
vi deployment.yaml
...
env:
- name: PROVISIONER_NAME
value: k8s-sigs.io/nfs-subdir-external-provisioner
- name: NFS_SERVER
value: 192.168.100.100
- name: NFS_PATH
value: /nfsvolume
volumes:
- name: nfs-client-root
nfs:
server: 192.168.100.100
path: /nfsvolume
kubectl create -f deployment.yaml
kubectl create -f class.yaml
vi mypvc-dynamic.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypvc-dynamic
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1G
storageClassName: 'nfs-client'
kubectl create -f mypvc-dynamic.yaml
이렇게 pvc만 만들어도 pvclass에 의해서 자동으로 만들어지는 것을 볼 수 있다.
echo "<h1> Hello NFS Dynamic Provision </h1>" | sudo tee /nfsvolume/XXX/index.html
vi myweb-rs-dynamic.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myweb-rs
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: myweb
image: httpd
volumeMounts:
- name: myvol
mountPath: /usr/local/apache2/htdocs
volumes:
- name: myvol
persistentVolumeClaim:
claimName: mypvc-dynamic
kubectl create -f myweb-rs-dynamic.yaml
kubectl delete -f . #서비스 삭제
kubectl get pv,pvc
### pvc를 지우면 pv가 같이 지워지는 것을 확인할 수 있다.
vi ~/nfs-subdir-external-provisioner/deploy/class.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs-client
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: k8s-sigs.io/nfs-subdir-external-provisioner # or choose another name, must match deployment's env PROVISIONER_NAME'
parameters:
archiveOnDelete: "false"
kubectl apply -f class.yaml
kubectl get sc
NAME ...
nfs-client (default) ...
### 이름 뒤에 default가 붙는 것을 default 스토리지 클래스라고 한다.
vi mypvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypvc-dynamic
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1G
kubectl create -f mypvc.yaml
진짜 도움됐어요 감사합니다!!