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
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
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