2020.07.16 스터디

2020. 7. 16. 16:33Study/Study group

반응형

6장 볼륨 : 컨테이너에 디스크 스토리지 연결

볼륨은

  1. pod와 라이프사이클이 같다. 즉, pod가 생성 될 때 볼륨이 생성, 삭제될 때 볼륨이 삭제.
  2. pod 스펙에 정의 된다.
  3. pod의 모든 컨테이너에서 볼륨을 사용할 수 있다.(단, 볼륨에 액세스해야하는 각 컨테이너에 볼륨을 마운트 해야 한다.)
  4. 여러가지 종류가 존재
    1. emptyDir: 일시적인 데이터를 저장하는 비어있는 단순 디렉토리.
    2. hostPath : 워커 노드(물리장비)의 파일 시스템에서 pod로 디렉토리를 마운트 하는데 사용.
    3. gitRepo : git스토리지의 내용을 체크아웃해 초기화된 볼륨.
    4. nfs : pod에 마운트 된 NFS 공유.(Network File System)
    5. gcePersistentDisk(구글 컴퓨트 엔진 영구 디스크)
    6. cinder etc.
  • emptyDir 실습

실습01

1. fortune.sh 만들기

#!/bin/bash
trap "exit" SIGINT
mkdir /var/htdocs
while :
do
  echo $(date) Writing fortune to /var/htdocs/index.html
  /usr/games/fortune > /var/htdocs/index.html
  sleep 10
done

※ shell script의 권한 체크 필요!

 

2. Dockerfile 만들기

FROM ubuntu:latest
RUN apt-get update ; apt-get -y install fortune
ADD fortune.sh /bin/fortune.sh
ENTRYPOINT /bin/fortune.sh

3. yml 만들기

apiVersion: v1
kind : Pod
metadata :
  name: fortune
spec:
  containers:
  - image: 화사 도커 허브 주소라서 삭제/teri_epi/fortune
    name: html-generator
    volumeMounts:
    - name: html
      mountPath: /var/htdocs
  - image: nginx:alpine
    name: web-server
    volumeMounts:
    - name: html
      mountPath: /usr/share/nginx/html
      readOnly: true
    ports:
    - containerPort: 80
      protocol: TCP
  volumes:
  - name: html
    emptyDir: {}

4. Docker Image 만들기!

docker build -t 회사도커허브주소/teri_epi/fortune .

5. Docker push!

docker push 회사도커허브주소/teri_epi/fortune

잘되었는지 dockerHub에서 확인.

회사 도커허브

6. k8s pod 수행!

kubectl create -f fortune-pod.yml

k는 kubectl alias해놓음.

7. port 포워드

kubectl port-forward fortune 8080:80

8. 확인

10초 마다 html생성 -> 새로고침 해보면 된다.

메모리를 사용하도록 할 수도 있다.

emptyDir:

  medium: Memory

더 많이 했는데 귀찮아서 정리는 요기까지 ㅋㅋ

 

- 끝 -

반응형