Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

클라우드 엔지니어 꿈나무

Kubernetes(K8S) Volume - Centos7 본문

kubernetes

Kubernetes(K8S) Volume - Centos7

새싹싹이 2023. 9. 17. 16:33

hostpath 설정

1. 파일 및 디렉토리 mount + nginx 설치 

vi hostpod.yml : nignx 설치와 pod 내 test 디렉토리 및 babo.txt 파일 생성

pod명 : hostvol-nginx

vi hostpod.yml
apiVersion: v1
apiVersion: v1
kind: Pod
metadata:
  name: hostvol-nginx
  labels:
    env: prod
spec:
  containers:
  - name: n1
    image: nginx
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 80
    volumeMounts:
    - mountPath: /test
      name: kang-vol
    - mountPath: /test/babo.txt
      name: kang-file
  volumes:
  - name: kang-vol
    hostPath:
      path: /data
      type: DirectoryOrCreate
  - name: kang-file
    hostPath:
      path: /data/babo.txt
      type: FileOrCreate
  nodeName: node1

node 1로 지정을 하였으니 node 1에 /data 디렉토리와 babo.txt 생성 후 진행 

kubectl apply -f hostpod.yml

kubectl exec hostbol-nginx -- lx /test 

확인하면 하기와 같이 babo.txt가 생긴 것을 볼 수 있다.

 

vi emptydp.ym

apiVersion: apps/v1
kind: Deployment
metadata:
  name: vol-dep
  labels:
    env: prod
spec:
  replicas: 1
  selector:
    matchLabels:
      vol: empty
  template:
    metadata:
      name: temp-vol
      labels:
        vol: empty
    spec:
      containers:
      - name: a1
        image: alpine
        imagePullPolicy: Never
        command: ["tail", "-f", "/home/"]
        volumeMounts:
        - mountPath: /test1
          name: kang-vol
      - name: n1
        image: nginx
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: /test2
          name: kang-vol
      volumes:
      - name: kang-vol
        emptyDir: {}