엔지니어링/Kubernetes

[AKS] POD 볼륨 마운트

joon95 2022. 8. 1. 17:48
반응형

오늘은 간단히 nginx pod 에 볼륨을 장착하는 테스트를 할 것이다.

이전에 포스팅한 동적 스토리지클래스를 통해 자동으로 PV 프로비저닝이 되있는 상태이며, 테스트 환경은 AKS에 AzureFile 로 스토리지를 붙여놓았다.

 

pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc001
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: joon-azurefile
  resources:
    requests:
      storage: 1Gi

nginx deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: docker.io/nginx:latest
          ports:
            - name: http-port
              containerPort: 80
          volumeMounts:
            - name: pvc001-test
              mountPath: /var/log/nginx
      volumes:
        - name: pvc001-test
          persistentVolumeClaim:
            claimName: pvc001

등록

$ kubectl apply -f .\pvc.yml
persistentvolumeclaim/pvc001 created

$ kubectl apply -f .\nginx.yml
deployment.apps/nginx configured

확인

생성된 pod 이름을 확인하고 컨테이너에 접속한 뒤 df로 디스크 상태를 확인하자.

$ kubectl get po
NAME                     READY   STATUS    RESTARTS   AGE
nginx-748ff85c76-6szsz   1/1     Running   0          7s

$ kubectl exec -it nginx-748ff85c76-6szsz bash

root@nginx-748ff85c76-6szsz:/# df
Filesystem                                                                               1K-blocks     Used Available Use% Mounted on
overlay                                                                                  129900528 26494540 103389604  21% /
tmpfs                                                                                        65536        0     65536   0% /dev
tmpfs                                                                                      3558124        0   3558124   0% /sys/fs/cgroup
shm                                                                                          65536        0     65536   0% /dev/shm
/dev/sda1                                                                                129900528 26494540 103389604  21% /etc/hosts
//f43e19f34ae6944ae8f4361.file.core.windows.net/pvc-d62b6366-9dec-4677-aab3-826d24ae9aba   1048576       64   1048512   1% /var/log/nginx
tmpfs                                                                                      4670936       12   4670924   1% /run/secrets/kubernetes.io/serviceaccount
tmpfs                                                                                      3558124        0   3558124   0% /proc/acpi
tmpfs                                                                                      3558124        0   3558124   0% /proc/scsi
tmpfs                                                                                      3558124        0   3558124   0% /sys/firmware

//f43e19f34ae6944ae8f4361.file.core.windows.net/pvc-d62b6366-9dec-4677-aab3-826d24ae9aba

라는 볼륨이 마운트 되어있는 것을 확인할 수 있다.

 

/var/log/nginx 폴더 안에는 nginx 로그가 있고 애저 포탈에서도 확인해보자.

root@nginx-748ff85c76-6szsz:/var/log/nginx# ls -l
total 0
-rwxrwxrwx 1 root root   0 Aug  1 08:27 access.log
-rwxrwxrwx 1 root root 504 Aug  1 08:27 error.log

 

 

끝!

반응형