티스토리 뷰

Kubernetes

K8s Sidecar Pattern - Multi Container Pod

KyeongRok Kim 2022. 1. 21. 23:27

Sidecar Pattern을 멀티 컨테이너 Pod로 구성하는 예제

Sidecar Pattern을 Pod에 적용한다는 것은 log를 수집하는 container를 하나 더 띄워서 어플리케이션에서 생성하는 로그를 처리하는 방식 입니다. 어플리케이션의 로그에 Sidecar역할을 하는 Container가 접근 할 때는 volume을 emptDir로 선언 하고 Pod안에 있는 Container끼리 공유하도록 설정하는 방법을 이용합니다.

 

아래 문제는 killer sh에 나온 CKA 시험 문제 입니다.

 

문제

Create a Pod named multi-container-playground in Namespace default with three containers, named c1, c2 and c3. There should be a volume attached to that Pod and mounted into every container, but the volume shouldn't be persisted or shared with other Pods.

 

Container c1 should be of image nginx:1.17.6-alpine and have the name of the node where its Pod is running on value available as environment variable MY_NODE_NAME.

 

Container c2 should be of image busybox:1.31.1 and write the output of the date command every second in the shared volume into file date.log. You can use while true; do date >> /your/vol/path/date.log; sleep 1; done for this.

컨테이너 c2은 이미지 busybox로 생성 하고 매 초마다 shared volume의 date.log에 현재 시간을 출력 합니다.

 

Container c3 should be of image busybox:1.31.1 and constantly write the content of file date.log from the shared volume to stdout. You can use tail -f /your/vol/path/date.log for this.

 

Check the logs of container c3 to confirm correct setup.

 

과정

1.multi-container인 pod띄우기

2.volume을 emptydir로 생성하기

volumes:
  - name: cache-volume
    emptyDir: {}

3.volume mount하기

4.variable 추가 하기

https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/

5.variable 추가한 것 k exec -it nginx -- sh 로 들어간 후 printenv로 확인 하기

6./vol/date.log의 내용 k logs로 출력하기

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
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
글 보관함