brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Jul 11. 2021

쿠버1탄-24. 쿠버네티스 - 스토리지 NFS(선택)

다음은 쿠버네티스 스터디 자료를 참고해  정리한 내용입니다.



<1>  마스터 노드 : NFS 서버 역할

<2>  생성

<3>  삭제


쿠버네티스-도메인 없이 kops로 aws쿠버설치

https://brunch.co.kr/@topasvga/1681


alias k=kubectl

complete -F __start_kubectl k



<1>  마스터 노드 : NFS 서버 역할


1

sudo su -

apt install -y nfs-kernel-server

mkdir /nfs4-share

echo '/nfs4-share *(rw,sync,no_root_squash)' >> /etc/exports

systemctl restart nfs-server


nfs 설정 정상 확인

exportfs -v


root@ip-172-20-60-135:~# exportfs -v

/nfs4-share     <world>(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)



3

워커 노드에 NFS Client 설치 - 미설치 시 컨테이너(NFS Client) 실행 시 에러 발생

apt install nfs-common -y



4

 k get nodes

ubuntu@ip-172-20-60-135:~$ k get nodes

NAME                                               STATUS   ROLES                  AGE   VERSION

ip-172-20-56-239.ap-northeast-1.compute.internal   Ready    node                   17h   v1.20.8

ip-172-20-60-135.ap-northeast-1.compute.internal   Ready    control-plane,master   17h   v1.20.8

ip-172-20-62-175.ap-northeast-1.compute.internal   Ready    node                   17h   v1.20.8


dig +short ip-172-20-60-135.ap-northeast-1.compute.internal

ubuntu@ip-172-20-60-135:~$ dig +short ip-172-20-60-135.ap-northeast-1.compute.internal

172.20.60.135



cat << EOF >  nfs-pod.yaml

apiVersion: v1

kind: Pod

metadata:

  name: nfs-pod

spec:

  containers:

    - name: nfs-mount-container

      image: busybox

      args: [ "tail", "-f", "/dev/null" ]

      volumeMounts:

      - name: nfs-volume

        mountPath: /nfs4           

  volumes:

  - name : nfs-volume

    nfs:                         

      path: /nfs4-share

      server: 172.20.60.135      # {NFS_SERVICE_IP, 마스터 노드의 IP}

EOF



<2>  생성


1

sed -i 's/192.168.100.10/<각자 자신의 마스터 노드의 IP>/g' nfs-pod.yaml

sed -i 's/192.168.100.10/172.20.60.135>/g' nfs-pod.yaml

kubectl apply -f nfs-pod.yaml


NAME          READY   STATUS    RESTARTS   AGE

pod/nfs-pod   1/1     R


2

# 파드 2개 더 생성

cat nfs-pod.yaml | sed -e "s/nfs-pod/nfs-pod2/" | kubectl apply -f -

cat nfs-pod.yaml | sed -e "s/nfs-pod/nfs-pod3/" | kubectl apply -f -


NAME           READY   STATUS    RESTARTS   AGE

pod/nfs-pod    1/1     Running   0          41s

pod/nfs-pod2   1/1     Running   0          9s

pod/nfs-pod3   1/1     Running   0          7s



# NFS서버 공유 디렉터리에 파일 생성 후 파드들에서 확인


# 마스터 노드에서 아래 실행

for i in {1..100}; do touch /nfs4-share/deleteme.$i; done;

ls /nfs4-share/


sudo su -

ubuntu@ip-172-20-60-135:~$ sudo su -

root@ip-172-20-60-135:~# for i in {1..100}; do touch /nfs4-share/deleteme.$i; done;

root@ip-172-20-60-135:~# ls /nfs4-share/

deleteme.1    deleteme.16  deleteme.23  deleteme.30  deleteme.38  deleteme.45  deleteme.52  deleteme.6   deleteme.67  deleteme.74  deleteme.81  deleteme.89  deleteme.96

deleteme.10   deleteme.17  deleteme.24  deleteme.31  deleteme.39  deleteme.46  deleteme.53  deleteme.60  deleteme.68  deleteme.75  deleteme.82  deleteme.9   deleteme.97

deleteme.100  deleteme.18  deleteme.25  deleteme.32  deleteme.4   deleteme.47  deleteme.54  deleteme.61  deleteme.69  deleteme.76  deleteme.83  deleteme.90  deleteme.98

deleteme.11   deleteme.19  deleteme.26  deleteme.33  deleteme.40  deleteme.48  deleteme.55  deleteme.62  deleteme.7   deleteme.77  deleteme.84  deleteme.91  deleteme.99

deleteme.12   deleteme.2   deleteme.27  deleteme.34  deleteme.41  deleteme.49  deleteme.56  deleteme.63  deleteme.70  deleteme.78  deleteme.85  deleteme.92

deleteme.13   deleteme.20  deleteme.28  deleteme.35  deleteme.42  deleteme.5   deleteme.57  deleteme.64  deleteme.71  deleteme.79  deleteme.86  deleteme.93

deleteme.14   deleteme.21  deleteme.29  deleteme.36  deleteme.43  deleteme.50  deleteme.58  deleteme.65  deleteme.72  deleteme.8   deleteme.87  deleteme.94

deleteme.15   deleteme.22  deleteme.3   deleteme.37  deleteme.44  deleteme.51  deleteme.59  deleteme.66  deleteme.73  deleteme.80  deleteme.88  deleteme.95

exit




# 파드1~3에서 확인

kubectl exec -it nfs-pod -- /bin/sh -c "df -hT -T nfs4"


ubuntu@ip-172-20-60-135:~$ kubectl exec -it nfs-pod -- /bin/sh -c "df -hT -T nfs4"

Filesystem                              Type            Size      Used Available Use% Mounted on

172.20.60.135:/nfs4-share   nfs4           62.0G      6.1G     55.8G  10% /nfs4


kubectl exec -it nfs-pod -- ls /nfs4

kubectl exec -it nfs-pod2 -- ls /nfs4

kubectl exec -it nfs-pod3 -- ls /nfs4

kubectl exec -it nfs-pod -- /bin/sh -c "rm /nfs4/*"

kubectl exec -it nfs-pod -- /bin/sh -c "touch /nfs4/test.txt"

ls /nfs4-share/

kubectl exec -it nfs-pod2 -- ls /nfs4



<3> 삭제


kubectl delete pod --all


ubuntu@ip-172-20-60-135:~$ kubectl delete pod --all

pod "nfs-pod" deleted

pod "nfs-pod2" deleted

pod "nfs-pod3" deleted




다음과정

https://brunch.co.kr/@topasvga/1713


https://brunch.co.kr/@topasvga/1656

감사합니다.


브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari