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