Link Search Menu Expand Document

Lab 3 - Pod : Logging Volume

  • You can use a sidecar container in one of the following ways:

    • The sidecar container streams application logs to its own stdout.
    • The sidecar container runs a logging agent, which is configured to pick up logs from an application container.

A pod runs a single container, and the container writes to two different log files, using two different formats. Here’s a configuration file for the Pod:

Create pod-logging-volum.yml File With Following Contents

apiVersion: v1
kind: Pod
  name: counter-log-vol
  - name: count
    image: busybox
    - /bin/sh
    - -c
    - >
        while true;
          echo "$i: $(date)" >> /var/log/1.log;
          echo "$(date) INFO $i" >> /var/log/2.log;
          sleep 1;
    - name: varlog
      mountPath: /var/log
  - name: varlog
    emptyDir: {}

Use kubectl create OR ` kubectl apply`

sangam:~ sangam$ kubectl create -f pod-logging-volum.yml 
pod/counter-log-vol created

List Of All Runnning Pods

sangam:~ sangam$ kubectl get po
NAME                                 READY   STATUS                       RESTARTS   AGE
counter                              1/1     Running                      0          3h39m
counter-log-vol                      1/1     Running                      0          12m
myapp-pod                            1/1     Running                      0          28h


An emptyDir volume is first created when a Pod is assigned to a Node, and exists as long as that Pod is running on that node. As the name says, it is initially empty. Containers in the Pod can all read and write the same files in the emptyDir volume, though that volume can be mounted at the same or different paths in each Container. When a Pod is removed from a node for any reason, the data in the emptyDir is deleted forever.

Check Volume from the inside pod

 kubectl exec -it  counter-log-vol -- bin/sh
 cd /var/log
 cat 1.log 2.log