Log collection example for sidecar containers (#64)
* Log collection example for sidecar containers * Add service and update readme * Update 16-sidecar-containers/README.md Co-authored-by: Matthieu Dumont <5095856+Jerska@users.noreply.github.com>
This commit is contained in:
parent
10b545a97d
commit
843e542937
|
@ -3,20 +3,58 @@ apiVersion: v1
|
||||||
kind: Pod
|
kind: Pod
|
||||||
metadata:
|
metadata:
|
||||||
name: two-containers
|
name: two-containers
|
||||||
|
labels:
|
||||||
|
app: sidecar-container
|
||||||
spec:
|
spec:
|
||||||
volumes:
|
volumes:
|
||||||
- name: shared-data
|
- name: shared-logs
|
||||||
emptyDir: {}
|
emptyDir: {}
|
||||||
|
- name: fluentd-config
|
||||||
|
configMap:
|
||||||
|
name: fluentd
|
||||||
containers:
|
containers:
|
||||||
- name: nginx
|
- name: nginx
|
||||||
image: nginx
|
image: nginx
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: shared-data
|
- name: shared-logs
|
||||||
mountPath: /usr/share/nginx/html
|
mountPath: /var/log/nginx
|
||||||
- name: debian
|
- name: fluentd
|
||||||
image: debian
|
image: fluent/fluentd:v1.11-1
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: shared-data
|
- name: shared-logs
|
||||||
mountPath: /pod-data
|
mountPath: /logs
|
||||||
command: ["/bin/sh"]
|
- name: fluentd-config
|
||||||
args: ["-c", "echo Hello from the debian container > /pod-data/index.html"]
|
mountPath: /fluentd/etc
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: fluentd
|
||||||
|
data:
|
||||||
|
fluent.conf: |
|
||||||
|
<source>
|
||||||
|
@type tail
|
||||||
|
path /logs/*
|
||||||
|
pos_file /tmp/fluentd-nginx-pos.log
|
||||||
|
tag nginx
|
||||||
|
<parse>
|
||||||
|
@type nginx
|
||||||
|
</parse>
|
||||||
|
</source>
|
||||||
|
|
||||||
|
<match nginx>
|
||||||
|
@type stdout
|
||||||
|
</match>
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
targetPort: 80
|
||||||
|
selector:
|
||||||
|
app: sidecar-container
|
||||||
|
|
|
@ -14,7 +14,7 @@ spec:
|
||||||
- name: container1
|
- name: container1
|
||||||
image: nginx
|
image: nginx
|
||||||
- name: container2
|
- name: container2
|
||||||
image: busybox
|
image: fluentd
|
||||||
```
|
```
|
||||||
|
|
||||||
Here we have 2 containers: `container1` and `container2`.
|
Here we have 2 containers: `container1` and `container2`.
|
||||||
|
@ -33,14 +33,20 @@ Istio, the service mesh tool, installs a sidecar container to do its job: https:
|
||||||
|
|
||||||
## Exercices
|
## Exercices
|
||||||
|
|
||||||
Review and apply the file [01-sidecar.yml](01-sidecar.yml). Connect to the `nginx` container and look at the file system in `/usr/share/nginx/html`.
|
Review and apply the file [01-sidecar.yml](01-sidecar.yml).
|
||||||
|
|
||||||
|
Connect to the `nginx` container (`kubectl exec -it two-containers -c nginx -- /bin/sh`) and look at the file system in `/var/log/nginx`.
|
||||||
|
|
||||||
|
Do the same for the `fluentd` container and this time look in `/logs`. What do you see?
|
||||||
|
|
||||||
|
Tail the logs from the fluentd pod (`kubectl logs -f two-containers -c fluentd`) and in another terminal window, send requests to the nginx service with a `curl` from a separate pod (or nginx's pod itself). What do you see? How do you explain it?
|
||||||
|
|
||||||
This exercice is taken from the [official Kubernetes documentation](https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/#creating-a-pod-that-runs-two-containers).
|
This exercice is taken from the [official Kubernetes documentation](https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/#creating-a-pod-that-runs-two-containers).
|
||||||
|
|
||||||
## Clean up
|
## Clean up
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
kubectl delete service,deployment,pod --all
|
kubectl delete service,deployment,pod,configmap --all
|
||||||
```
|
```
|
||||||
|
|
||||||
## Links
|
## Links
|
||||||
|
|
Loading…
Reference in New Issue