다음은 쿠버네티스 스터디 자료를 참고해 정리한 내용입니다.
쿠버네티스-도메인 없이 kops로 aws쿠버설치
https://brunch.co.kr/@topasvga/1681
노드1(호스트)에 /dkos-v 디렉터리가 없으면 생성하고 파드 내부에 /dkos-pod-v 볼륨 마운트 공유
<1> hostPath
1
cat << EOF > hostpath.yaml
apiVersion: v1
kind: Pod
metadata:
name: hostpath-pod
spec:
nodeSelector:
kubernetes.io/hostname: k8s-w1
containers:
- name: my-container
image: busybox
args: [ "tail", "-f", "/dev/null" ]
volumeMounts:
- name: hostpath-volume
mountPath: /dkos-pod-v
volumes:
- name: hostpath-volume
hostPath:
path: /dkos-v
type: DirectoryOrCreate
EOF
2
# 터미널1
watch -d 'kubectl get pods,pv,pvc,volumeattachments -o wide'
3
# 생성
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 16h v1.20.8
ip-172-20-60-135.ap-northeast-1.compute.internal Ready control-plane,master 16h v1.20.8
ip-172-20-62-175.ap-northeast-1.compute.internal Ready node 16h v1.20.8
sed -i 's/k8s-w1/<각자 자신의 노드1의 호스트네임>/g' hostpath.yaml
sed -i 's/k8s-w1/ip-172-20-56-239.ap-northeast-1.compute.internal/g' hostpath.yaml
kubectl apply -f hostpath.yaml
생성 된 pod
NAME READY STATUS RESTARTS AGE
pod/hostpath-pod 1/1 Running 0 14s
4
확인
kubectl exec -it hostpath-pod -- sh
/ # ls
bin dkos-pod-v home root tmp var
dev etc proc sys usr
cd dkos-pod-v/
touch 1.txt 2.txt 3.txt
exit
5
kubectl delete pod --all
ubuntu@ip-172-20-60-135:~$ kubectl delete pod --all
pod "hostpath-pod" deleted
다음 과정
https://brunch.co.kr/@topasvga/1712
https://brunch.co.kr/@topasvga/1656
감사합니다.