[파드 디자인 패턴과 잡(Job) 실행] 사이드카 컨테이너 개념과 실습

hi·2023년 8월 19일
0

쿠버네티스

목록 보기
52/64
post-thumbnail
post-custom-banner

사이드카 컨테이너란?

  • 오토바이의 사이드카에서 유래
  • 이륜차에 기존 기능을 향상/확장하는데 사용 (여기서는 파드의 기능을 향상)
  • 파드의 파일시스템을 공유하는 형태



사이드카 컨테이너 생성 실습

  • 접속 후 다음 명령을 통해 로그 확인

kubectl logs nginx-sidecar sidecar-access

# nginx-sidecar.yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx-sidecar
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80
    volumeMounts:
    - name: varlognginx
      mountPath: /var/log/nginx
  - name: sidecar-access
    image: busybox
    args: [/bin/sh, -c, 'tail -n+1 -f /var/log/nginx/access.log']
    volumeMounts:
    - name: varlognginx
      mountPath: /var/log/nginx
  - name: sidecar-error
    image: busybox
    args: [/bin/sh, -c, 'tail -n+1 -f /var/log/nginx/error.log']
    volumeMounts:
    - name: varlognginx
      mountPath: /var/log/nginx
  volumes:
  - name: varlognginx
    emptyDir: {}

imkunyoung@cloudshell:~ (kubernetes-397511)$ kubectl create -f nginx-sidecar.yaml
pod/nginx-sidecar created
imkunyoung@cloudshell:~ (kubernetes-397511)$ kubectl get pods
NAME                                            READY   STATUS    RESTARTS   AGE
admin-page                                      1/1     Running   0          3d5h
front-end                                       1/1     Running   0          3d6h
jenkins-deployment-58f88d9746-gmvkc             1/1     Running   0          2d10h
jhipster-prometheus-operator-77c8f847cb-sr7sx   1/1     Running   0          46h
mariadb-5bfcbc8dd5-vm69q                        1/1     Running   0          8h
nginx-sidecar                                   3/3     Running   0          15s
imkunyoung@cloudshell:~ (kubernetes-397511)$ kubectl logs nginx-sidecar
Defaulted container "nginx" out of: nginx, sidecar-access, sidecar-error
imkunyoung@cloudshell:~ (kubernetes-397511)$ kubectl logs nginx-sidecar sidecar-access
imkunyoung@cloudshell:~ (kubernetes-397511)$ kubectl exec nginx-sidecar -- curl 127.0.0.1
Defaulted container "nginx" out of: nginx, sidecar-access, sidecar-error
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   615  100   615    0     0   478k      0 --:--:-- --:--:-- --:--:--  600k
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
imkunyoung@cloudshell:~ (kubernetes-397511)$ kubectl logs nginx-sidecar sidecar-access
127.0.0.1 - - [10/Sep/2023:07:38:50 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.88.1" "-"
imkunyoung@cloudshell:~ (kubernetes-397511)$ kubectl exec nginx-sidecar -- curl 127.0.0.1/tttttttttttttttttt
Defaulted container "nginx" out of: nginx, sidecar-access, sidecar-error
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   153  100   153    0     0  41757      0 --:<html>--:--:-- --:--:--     0
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.25.2</center>
</body>
</html>
--:-- --:--:-- --:--:-- 51000
imkunyoung@cloudshell:~ (kubernetes-397511)$ kubectl logs nginx-sidecar sidecar-access
127.0.0.1 - - [10/Sep/2023:07:38:50 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.88.1" "-"
127.0.0.1 - - [10/Sep/2023:07:39:50 +0000] "GET /tttttttttttttttttt HTTP/1.1" 404 153 "-" "curl/7.88.1" "-"
post-custom-banner

0개의 댓글