๐Ÿค—์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์ปจํ…Œ์ด๋„ˆ[์‚ฌ์ด๋“œ์นด, ์–ด๋Œ‘ํ„ฐ, ์— ๋ฒ„์„œ๋”]

๊น€์„ฑ์ธยท2023๋…„ 10์›” 20์ผ
0

[DevOps] ๐ŸณDocker & Kubernetes

๋ชฉ๋ก ๋ณด๊ธฐ
41/62

https://kubernetes.io/ko/docs/concepts/cluster-administration/logging/

์‚ฌ์ด๋“œ์นด ์ปจํ…Œ์ด๋„ˆ : ๋กœ๊ทธ ๋“ฑ์„ stdout ์œผ๋กœ ํ‘œํ˜„
์–ด๋Œ‘ํ„ฐ ์ปจํ…Œ์ด๋„ˆ : ๊ธฐ์กด ์ปจํ…Œ์ด๋„ˆ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๊ณ  ๋‚ด์šฉ ํ™œ์šฉ
์•ฐ๋ฐฐ์„œ๋” ์ปจํ…Œ์ด๋„ˆ : ์ปจํ…Œ์ด๋„ˆ


์‚ฌ์ด๋“œ์นด ์ปจํ…Œ์ด๋„ˆ

https://kubernetes.io/ko/docs/concepts/cluster-administration/logging/#sidecar-container-with-logging-agent
ํŒŒ๋“œ์˜ ํŒŒ์ผ ์‹œ์Šคํ…œ์„ ๊ณต์œ ํ•˜๋Š” ํ˜•ํƒœ
์›๋ž˜ ์‚ฌ์šฉํ•˜๋ ค๋˜ ๊ธฐ๋ณธ ์ปจํ…Œ์ด๋„ˆ์˜ ๊ธฐ๋Šฅ์„ ํ™•์žฅํ•˜๊ฑฐ๋‚˜ ๊ฐ•ํ™”ํ•˜๋Š” ์šฉ๋„์˜ ์ปจํ…Œ์ด๋„ˆ

  • ์‚ฌ์ด๋“œ์นด ์ปจํ…Œ์ด๋„ˆ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋กœ๊ทธ๋ฅผ ์ž์ฒด stdout ์œผ๋กœ ์ŠคํŠธ๋ฆฌ๋ฐํ•œ๋‹ค.
  • ์‚ฌ์ด๋“œ์นด ์ปจํ…Œ์ด๋„ˆ๋Š” ๋กœ๊น… ์—์ด์ „ํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋ฉฐ, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ปจํ…Œ์ด๋„ˆ์—์„œ ๋กœ๊ทธ๋ฅผ ๊ฐ€์ ธ์˜ค๋„๋ก ๊ตฌ์„ฑ๋œ๋‹ค
apiVersion: v1
kind: Pod
metadata:
  name: nginx-sidecar
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80
    volumeMounts:
    - name: varlog
      mountPath: /var/log/nginx
  - name: sidecar-access
    image: busybox:1.28
    args: [/bin/sh, -c, 'tail -n+1 -F /var/log/nginx/access.log']
    volumeMounts:
    - name: varlog
      mountPath: /var/log/nginx
  - name: sidecar-error
    image: busybox:1.28
    args: [/bin/sh, -c, 'tail -n+1 -F /var/log/nginx/error.log']
    volumeMounts:
    - name: varlog
      mountPath: /var/log/nginx
  volumes:
  - name: varlog
    emptyDir: {}

kubectl apply -f nginx-sidecar.yaml
kubectl exec nginx-sidecar -- curl 127.0.0.1
kubectl logs nginx-sidecar sidecar-access


์–ด๋Œ‘ํ„ฐ ์ปจํ…Œ์ด๋„ˆ

ํŒŒ๋“œ ์™ธ๋ถ€๋กœ ๋…ธ์ถœ๋˜๋Š” ์ •๋ณด๋ฅผ ํ‘œ์ค€ํ™”ํ•˜๋Š” ์–ด๋Œ‘ํ„ฐ ์ปจํ…Œ์ด๋„ˆ
ํŠน์ • ์ปจํ…Œ์ด๋„ˆ์— ๊ธฐ์กด ํ”„๋กœ๊ทธ๋žจ์„ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๊ณ  ์ ์šฉ์‹œํ‚ค๊ธฐ ์œ„ํ•ด ์–ด๋Œ‘ํ„ฐ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋™์ž‘์„ ๊ตฌ์„ฑํ•จ.

https://medium.com/bb-tutorials-and-thoughts/kubernetes-learn-adaptor-container-pattern-97674285983c

server.js

pod

kubectl apply -f https://raw.githubusercontent.com/bbachi/k8s-adaptor-container-pattern/master/pod.yml
kubectl port-forward adapter-container-demo 8080:3080


์— ๋ฒ„์„œ๋” ์ปจํ…Œ์ด๋„ˆ

ํŒŒ๋“œ ์•ˆ์—์„œ ํ”„๋ก์‹œ ์—ญํ• ์„ ํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ํŒจํ„ด
ํŒŒ๋“œ ์™ธ๋ถ€์˜ ์„œ๋น„์Šค์— ๋Œ€ํ•œ ์•ก์„ธ์Šค๋ฅผ ๊ฐ„์†Œํ™”ํ•˜๋Š” ์œ ํ˜•

  • ํ†ต์‹ ์„ ๋”ฐ๋กœ ๋‹ด๋‹นํ•จ
  • ํŠธ๋ž˜ํ”ฝ์— ๋Œ€ํ•œ proxy ์—ญํ• 

https://github.com/bbachi/k8s-ambassador-container-pattern

(https://medium.com/bb-tutorials-and-thoughts/kubernetes-learn-ambassador-container-pattern-bc2e1331bd3a)

kubectl apply -f https://raw.githubusercontent.com/bbachi/k8s-ambassador-container-pattern/master/pod.yml
kubectl exec -it ambassador-container-demo -c ambassador-container -- curl localhost:9000
kubectl logs ambassado-container-demo main-container

profile
๊ฐœ๋ฐœ์ž๊ฐ€ ๊ฟˆ์ธ 25์‚ด ๋Œ€ํ•™์ƒ์ž…๋‹ˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€