DevOps/CKA Test 준비

13.CKA-Volume mount

치킨맛코드 2023. 3. 7. 08:45

<문제-emptyDir volume을 공유하는 multy-pod 운영>
아래의 조건에 맞는 nginx web server pod가 생성된 logfile을 받아 STDOUT(Standard out)으로 출력하는 busybox container를 운영하시오
작업 클러스터 : k8s
pod name: weblog
web container:
    images: nginx1.17
    volume mount: /var/log/nginx
    readwrite
Log container:
    image: busybox
    Command: /bin/sh, -c "tail -n+1 -f /data/access.log"
    Volume mount: /data
    readonly
emptyDir volume을 통한 데이터 공유

1. 작업 클러스터로 이동
==> kubectl config use-context k8s

2. weblog yaml 생성하기
==> kubeclt run weblog --image=nginx:1.17 --dry-run=cleint -o yaml > weblog.yaml

apiVersion : v1
kind: Pod
metadata:
    name: weblog
spec:
    containers:
    - image: nginx:1.17
      name: web
      volumeMounts:
      -  mountPath: /var/log/nginx
          name: log-volume
==> web이라는 컨테이너의 이미지는 nginx1.17, 볼륨 마운트는 /var/log/nginx아래에 한다.
    - image: busybox
      name: Log
      args: [/bin/sh, -c "tail -n+1 -f /data/access.log"]
      volumeMounts:
      -  mountPath: /data
          name: log-volume
          readOnly: true
==>log container에 대한 스팩을 설정한다. readwrite는 기본값이다. readOnly를 기입한다.
    volumes:
    - name: log-volume
      emptyDir: {}
==> 문제에서 특별히 emptyDir에 대한 이름이 지정되지 않았다면, 임의로 지정한다.

3. 생성된 pod 실행하기
==> kubectl apply -f weblog.yaml

4.접근 및 확인하기
==> kubectl get pods -o wide
==> ssh k8s-worker1
==> curl "pod ip"
==> kubectl logs weblog -c log





주어진 파일을 아래 조건에 맞게 볼륨 마운트설정 하시오.
<조건>
worker node의 docker container directory를 동일 directory로 pod에 마운트 하시오.
worker node의 /var/log directory를 flouentd pod 에 동일 이름의 directory로 마운트 하시오
작업 클러스터 : k8s
파일 위치 및 이름 : /data/cka/fluentd.yaml

작업클러스터 확인하기
kubectl config use-context k8s

실제로 fluentd.yaml이 있는지 확인하기
cat /data/cka/fluentd.yaml

제시한 조건으로 pod 마운트 하기(fluentd.yaml)
apiVersion: app/V1
kind: DaemonSet
metadata:
    name: fluentd
spec:
  selector:
    matchLabels:
      name: fluentd
  templates:
    metadata:
      labels:
        name: fluentd
    spec:
      volumes:
      - name: dockercontainerdir
==> 이름은 자유롭게 서술
        hostPath:
          path: /var/lib/docker/containers
==> 도커 컨테이너 디렉토리의 위치(host)
      volumes:
      - name: varlogdir
==> 이름은 자유롭게 서술
        hostPath:
          path: /var/log
==> 도커 컨테이너 디렉토리의 위치(host)
      containers:
      - naem: fluentd
        images: fluentd
        volumeMounts:
        - mountPath: /var/lib/docker/containers
          name: dockercontainerdir
        - mountPath: /var/log
          name: varlogdir
==> 상단의 volumes에서 지정한 위치와 이름으로 지정