Kubernetes Time Check Pod Kodekloud



The Nautilus DevOps team want to create a time check pod in a particular Kubernetes namespace and record the logs. This might be initially used only for testing purposes, but later can be implemented in an existing cluster. Please find more details below about the task and perform it.

    Create a pod called time-check in the devops namespace. This pod should run a container called time-check, container should use the busybox image with latest tag only and remember to mention tag i.e busybox:latest.

    Create a config map called time-config with the data TIME_FREQ=7 in the same namespace.

    The time-check container should run the command: while true; do date; sleep $TIME_FREQ;done and should write the result to the location /opt/data/time/time-check.log. Remember you will also need to add an environmental variable TIME_FREQ in the container, which should pick value from the config map TIME_FREQ key.

    Create a volume log-volume and mount the same on /opt/data/time within the container.

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


At first create the namespace

kubectl create ns devops

Then create a yml file

vi time-check-pod.yml and paste this. Check the mount path time frequence according to question

apiVersion: v1
kind: ConfigMap
name: time-config
namespace: devops
apiVersion: v1
kind: Pod
name: time-check
namespace: devops
app: time-check
- name: log-volume
emptyDir: {}
- name: time-check
image: busybox:latest
- mountPath: /opt/data/time
name: log-volume
- configMapRef:
name: time-config
command: ["/bin/sh", "-c"]
"while true; do date; sleep $TIME_FREQ;done > /opt/data/time/time-check.log",

Finally apply the yml

kubectl apply -f time-check-pod.yml

Check the pod

kubectl get po -n devops

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment