티스토리 뷰
● nfs.yml 생성
# volumeMounts >> 컨테이너 내의 nfs 공유디렉터리 마운트 포인터
# volumes >> 공유디렉터리 와 nfs server 주소
>> 밑에서 수정해서 실행할 예정 [ centos >> httpd ]
#### : set list 로 띄어쓰기 꼭 확인
---
apiVersion: v1
kind: Pod
metadata:
name: nfs-storage-test
spec:
containers:
- name: nfs-container-test
image: centos:7
command: ["sh","-c","/usr/bin/sleep","3600s"]
volumeMounts:
- name: nfs-volume
mountPath: /mnt
volumes:
- name: nfs-volume
nfs:
path: /var/nfs_storage
server: 192.168.98.30
...
● nfs-server 용도의 vagrant 생성
Vagrant.configure("2") do |config|
# docker_server for nfs-storage
config.vm.define "storage-server" do |cfg|
cfg.vm.box = "centos/7"
cfg.vm.provider "virtualbox" do |vb|
vb.name = "storage-server"
vb.cpus = 2
vb.memory = 2048
vb.gui = true
end
cfg.vm.host_name = "storage.example.com"
cfg.vm.network "private_network", ip: "192.168.98.99"
cfg.vm.provision "shell", path: "ssh_conf.sh", privileged: true
cfg.vm.provision "shell", path: "nfs_conf.sh", privileged: true
end
end
● nfs_conf.sh 생성
#! /bin/bash
#nfs를 사용하기 위해서는 nfs-utils 패키지기 설치되어 있어야 합니다.
yum -y install nfs-utils
mkdir /var/nfs_storage
# 아래설정중 ip address 와 괄호사이에 빈칸이 있으면 안됩니다.
echo "/var/nfs_storage 192.168.98.0/24(rw,no_root_squash)" > /etc/exports
systemctl restart nfs-server
systemctl enable nfs-server
systemctl stop firewalld > /dev/null
systemctl disable firewalld > /dev/null
▩ 실행 오류
>> nfs 마운트 할 수 있는 패키지가 각 node 에 필요하다
[vagrant@ms work]$ kubectl apply -f nfs.yml
error: error parsing nfs.yml: error converting YAML to JSON: yaml: line 5: found character that cannot start any token
● 홈페이지를 영구 보존하기 위한 마운트
apiVersion: v1
kind: Pod
metadata:
name: nfs-storage-test
spec:
containers:
- name: nfs-container-test
image: httpd:2.4
volumeMounts:
- name: nfs-volume
mountPath: /usr/local/apache2/htdocs
volumes:
- name: nfs-volume
nfs:
path: /var/nfs_storage
server: 192.168.98.99
▷ 마운트 되는지 확인
>> root 인데도 권한 오류가 뜨는데 >> 컨테이너는 IP 가 10.x.x.x 로 랜덤 생성이 된다
>> nfs_storage 의 IP 는 192.168.98.99 이므로 맞지 않다
>>> 매번 마운트 할 때마다 nfs-utils 를 설치하고 아이피 맞추고 하는 것이 너무 번거롭고 어렵다
kubectl run apache --image httpd:2.4
kubectl exec -it apache -- /bin/bash
해결 방법
● Pod가 있는 Node가 먼저 마운트를 하고, 그것을 pod 가 사용한다 [ 자동 ]
>> wk2 Node 에서 nfs - utils 가 필요하다
# wk1 에도 설치하기
>> 마운트 완료
● wk1 에서 df -ah 를 실행하면 위치가 뜬다
df -ah
192.168.98.99:/var/nfs_storage - - - - /var/lib/kubelet/pods/cc691421-5cf1-4c72-ba45-d152bc4a3571/volumes/kubernetes.io~nfs/nfs-volume
○ 컨테이너 직접 접속하여 마운트 여부 확인
▶ 이게된다고?
>> ssh 로 명령어 입력 출력 가능
[vagrant@ms work]$ ssh wk1.example.com mount |grep 192.168.98.99
Warning: Permanently added 'wk1.example.com' (RSA) to the list of known hosts.
192.168.98.99:/var/nfs_storage on /var/lib/kubelet/pods/cc691421-5cf1-4c72-ba45-d152bc4a3571/volumes/kubernetes.io~nfs/nfs-volume type nfs4 (rw,relatime,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.98.20,local_lock=none,addr=192.168.98.99)
[vagrant@ms work]$ ssh wk1 /var/lib/kubelet/pods/cc691421-5cf1-4c72-ba45-d152bc4a3571/volumes/kubernetes.io~nfs/nfs-volume
wk1 wk1.example.com
[vagrant@ms work]$ ssh wk1.example.com cat /var/lib/kubelet/pods/cc691421-5cf1-4c72-ba45-d152bc4a3571/volumes/kubernetes.io~nfs/nfs-volume/index.html
cat: /var/lib/kubelet/pods/cc691421-5cf1-4c72-ba45-d152bc4a3571/volumes/kubernetes.io~nfs/nfs-volume/index.html: Permission denied
[vagrant@ms work]$ ssh wk1.example.com sudo cat /var/lib/kubelet/pods/cc691421-5cf1-4c72-ba45-d152bc4a3571/volumes/kubernetes.io~nfs/nfs-volume/index.html
eheheheh
'Kubernetes [ 쿠버네티스 ]' 카테고리의 다른 글
Kubernetes - wordpress 배포 실습 (0) | 2024.03.13 |
---|---|
Kubernets - pv / pvc (0) | 2024.03.12 |
Kubernetes emptyDir (0) | 2024.03.12 |
Kubernetes 커맨드 입력 (0) | 2024.03.12 |
Kubernetes - 볼륨 (1) | 2024.03.11 |