Skip to content

Instantly share code, notes, and snippets.

@ianychoi
Created July 14, 2021 13:04
Show Gist options
  • Save ianychoi/51fbec9deff15be0bde0f4d1f57ae3c1 to your computer and use it in GitHub Desktop.
Save ianychoi/51fbec9deff15be0bde0f4d1f57ae3c1 to your computer and use it in GitHub Desktop.
쿠버네티스 - 볼륨 (기본)
  • hostpath.yaml
apiVersion: v1
kind: Pod
metadata:
  name: hostpath
spec:
  containers:
    - name: hostpath
      image: busybox
      args: [ "tail", "-f", "/dev/null" ]
      volumeMounts:
      - name: hostpath-volume
        mountPath: /etc/data
  volumes:
    - name: hostpath-volume
      hostPath:
        path: /cndk
  • 생성 및 확인
curl -s -O https://raw.githubusercontent.com/gasida/DKOS/main/3/hostpath.yaml
kubectl apply -f hostpath.yaml && watch "kubectl describe pod hostpath | grep Events -A 12"

# 파드가 생성된 워커노드(호스트)에 디렉토리 확인 : 디렉토리가 없을 시 자동으로 생성됨
ls /
root@k8s-w1:~# ls /
bin   cndk  etc   lib    lib64   lost+found  mnt  proc  run   snap  sys  usr
boot  dev   home  lib32  libx32  media       opt  root  sbin  srv   tmp  var

# 파드에 파일 생성
kubectl exec hostpath -- touch /etc/data/test.txt
[root@k8s-m ~ (kube:default)]# kubectl exec hostpath -- touch /etc/data/test.txt
[root@k8s-m ~ (kube:default)]#

# 워커노드(호스트)에 디렉토리 확인
root@k8s-w1:~# ls /cndk
test.txt

# 다음 실습을 위해서 생성된 파드 삭제
kubectl delete pod --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment