Logo

Armand.nz

Home / About / Linkedin / Github

Multi-Container Pods and emptyDir for shared volumed

#cka #ckd #kubernetes |

  1. Create a YAML file named multi.yml:
  apiVersion: v1
  kind: Pod
  metadata:
    name: multi
    namespace: baz
  spec:
    containers:
    - name: nginx
      image: nginx
    - name: redis
      image: redis

Save the file

  1. Create the multi-container pod:
  kubectl create -f multi.yml
  1. Check the status of the pod:
  kubectl get pods -n baz

Create a Pod Which Uses a Sidecar to Expose the Main Container’s Log File to Stdout

  1. Create a YAML file named logging-sidecar.yml:
  vim logging-sidecar.yml

In the file, paste the following:

  apiVersion: v1
  kind: Pod
  metadata:
    name: logging-sidecar
    namespace: baz
  spec:
    containers:
    - name: busybox1
      image: busybox
      command: ['sh', '-c', 'while true; do echo Logging data > /output/output.log; sleep 5; done']
      volumeMounts:
      - name: sharedvol
        mountPath: /output
    - name: sidecar
      image: busybox
      command: ['sh', '-c', 'tail -f /input/output.log']
      volumeMounts:
      - name: sharedvol
        mountPath: /input
    volumes:
    - name: sharedvol
      emptyDir: {}

Save the file

  1. Create the logging-sidecar pod:
  kubectl create -f logging-sidecar.yml
  1. Check the status of the pod
  kubectl get pods -n baz
  1. Check the logging-sidecar logs:
  kubectl logs logging-sidecar -n baz -c sidecar
comments powered byDisqus

Copyright © Armand