100-Days-Of-DevOps-Challenge-KodeKloud

Kubernetes Sidecar Containers

We have a web server container running the nginx image. The access and error logs generated by the web server are not critical enough to be placed on a persistent volume. However, Nautilus developers need access to the last 24 hours of logs so that they can trace issues and bugs. Therefore, we need to ship the access and error logs for the web server to a log-aggregation service. Following the separation of concerns principle, we implement the Sidecar pattern by deploying a second container that ships the error and access logs from nginx. Nginx does one thing, and it does it well—serving web pages. The second container also specializes in its task—shipping logs. Since containers are running on the same Pod, we can use a shared emptyDir volume to read and write logs.

Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.

Steps

  1. Create a k3s-pod.yml using this YAML file

  2. Create pod

     kubectl apply -f k3s-pod.yml
    
  3. Verify pod is running

    ```bash kubectl get pods

Good to Know?

Sidecar Pattern

Log Aggregation

Sidecar Benefits

Implementation Patterns