305-998-7702 | 415-800-2922 info@rx-m.com

Practice Drills

Learn how to put the latest open source technology into practice with hands-on training, delivered by industry experts, aligned to your desired business outcomes

Build an image using the following Dockerfile tagged self-study/webserver:v1:

FROM centos/httpd
RUN /bin/sh -c "echo welcome" > /usr/share/httpd/noindex/index.html
Practice Drill: Answer
$ nano Dockerfile && cat $_

FROM centos/httpd
RUN /bin/sh -c "echo welcome" > /usr/share/httpd/noindex/index.html

$ docker build -t self-study/webserver:v1 .

Sending build context to Docker daemon  3.584kB
Step 1/2 : FROM centos/httpd
 ---> 2cc07fbb5000
Step 2/2 : RUN /bin/sh -c "echo welcome" > /usr/share/httpd/noindex/index.html
 ---> Running in 2addf467f100
Removing intermediate container 2addf467f100
 ---> 3c1011807b54
Successfully built 3c1011807b54
Successfully tagged self-study/webserver:v1


Define a pod named self-study-pod-1 which has one container named primary running the self-study/webserver:v1 image you just built. The primary container should have an ephemeral volume named share mounted at /var/log/httpd. This pod should also have an adapter container named logger running the fluent/fluent-bit:1.9.2 image that mounts volume the share volume at /httpd and runs the command /fluent-bit/bin/fluent-bit -i tail -p path=/httpd/access_log -o stdout.

Practice Drill: Answer
$ nano self-study-pod-1.yaml && cat $_

apiVersion: v1
kind: Pod
    run: self-study-pod-1
  name: self-study-pod-1
  - image: self-study/webserver:v1
    name: primary
    - name: logs
      mountPath: /var/log/httpd
  - image: fluent/fluent-bit:1.9.2
    name: logger
    - name: logs
      mountPath: /httpd
    - /fluent-bit/bin/fluent-bit
    - -i
    - tail
    - -p
    - path=/httpd/access_log
    - -o
    - stdout
  - name: logs
    emptyDir: {}

$ kubectl apply -f self-study-pod-1.yaml

pod/self-study-pod-1 created


To test it, curl the IP of the self-study-pod-1 pod and retrieve the logs from the its logger container:

$ kubectl get pods self-study-pod-1 -o wide

NAME               READY   STATUS    RESTARTS   AGE    IP          NODE               NOMINATED NODE   READINESS GATES
self-study-pod-1   2/2     Running   0          4m1s   ip-172-31-57-184              

$ curl


$ kubectl logs self-study-pod-1 logger
Fluent Bit v1.9.2
* Copyright (C) 2015-2022 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2022/04/19 00:14:32] [ info] [fluent bit] version=1.9.2, commit=27a63c11d3, pid=1
[2022/04/19 00:14:32] [ info] [storage] version=1.1.6, type=memory-only, sync=normal, checksum=disabled, max_chunks_up=128
[2022/04/19 00:14:32] [ info] [cmetrics] version=0.3.0
[2022/04/19 00:14:32] [ info] [sp] stream processor started
[2022/04/19 00:14:32] [ info] [output:stdout:stdout.0] worker #0 started
[2022/04/19 00:14:32] [ info] [input:tail:tail.0] inotify_fs_add(): inode=777359 watch_fd=1 name=/httpd/access_log
[0] tail.0: [1650327514.381999019, {"log"=>" - - [19/Apr/2022:00:18:34 +0000] "GET / HTTP/1.1" 403 8 "-" "curl/7.68.0""}]