Our course you can check :- Udemy course
Ques:-
DevOps team needs a time check pod created in a specific Kubernetes namespace for logging purposes. Initially, it's for testing, but it may be integrated into an existing cluster later. Here's what's required:
Create a pod called time-check in the devops namespace. The pod should contain a container named time-check, utilizing the busybox image with the latest tag (specify as busybox:latest).
Create a config map named time-config with the data TIME_FREQ=10 in the same namespace.
Configure the time-check container to execute the command: while true; do date; sleep $TIME_FREQ;done. Ensure the result is written /opt/finance/time/time-check.log. Also, add an environmental variable TIME_FREQ in the container, fetching its value from the config map TIME_FREQ key.
Create a volume log-volume and mount it at /opt/finance/time within the container.
Ans:-
raj@jumphost ~$ kubectl create ns devops
namespace/devops created
raj@jumphost ~$ vi pod.yaml
raj@jumphost ~$ cat pod.yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: time-config
namespace: devops
data:
TIME_FREQ: "10"
---
apiVersion: v1
kind: Pod
metadata:
name: time-check
namespace: devops
spec:
containers:
- name: time-check
image: busybox:latest
command: ["/bin/sh", "-c"]
args:
- while true; do date >> /opt/finance/time/time-check.log; sleep $TIME_FREQ; done
env:
- name: TIME_FREQ
valueFrom:
configMapKeyRef:
name: time-config
key: TIME_FREQ
volumeMounts:
- name: log-volume
mountPath: /opt/finance/time
volumes:
- name: log-volume
emptyDir: {}
restartPolicy: Always
raj@jumphost ~$ kubectl apply -f pod.yaml
configmap/time-config created
pod/time-check created
raj@jumphost ~$ kubectl get cm -n devops
NAME DATA AGE
kube-root-ca.crt 1 36s
time-config 1 32s
raj@jumphost ~$ kubectl get pod -n devops
NAME READY STATUS RESTARTS AGE
time-check 1/1 Running 0 47s
raj@jumphost ~$ kubectl exec -it time-check -n devops -- sh
/ # cat opt/finance/time/time-check.log
Sun Oct 5 15:39:43 UTC 2025
Sun Oct 5 15:39:53 UTC 2025
Sun Oct 5 15:40:03 UTC 2025
Sun Oct 5 15:40:13 UTC 2025
Sun Oct 5 15:40:23 UTC 2025
Sun Oct 5 15:40:33 UTC 2025
Sun Oct 5 15:40:43 UTC 2025
Sun Oct 5 15:40:53 UTC 2025
Sun Oct 5 15:41:03 UTC 2025
Sun Oct 5 15:41:13 UTC 2025
Sun Oct 5 15:41:23 UTC 2025
Sun Oct 5 15:41:33 UTC 2025
Sun Oct 5 15:41:43 UTC 2025
Sun Oct 5 15:41:53 UTC 2025
Sun Oct 5 15:42:03 UTC 2025
Sun Oct 5 15:42:13 UTC 2025
Sun Oct 5 15:42:23 UTC 2025
Sun Oct 5 15:42:33 UTC 2025
/ # cd /opt/finance/time
/opt/finance/time # ls
time-check.log
/opt/finance/time # cat time-check.log
Sun Oct 5 15:39:43 UTC 2025
Sun Oct 5 15:39:53 UTC 2025
Sun Oct 5 15:40:03 UTC 2025
Sun Oct 5 15:40:13 UTC 2025
Sun Oct 5 15:40:23 UTC 2025
Sun Oct 5 15:40:33 UTC 2025
Sun Oct 5 15:40:43 UTC 2025
Sun Oct 5 15:40:53 UTC 2025
Sun Oct 5 15:41:03 UTC 2025
Sun Oct 5 15:41:13 UTC 2025
Sun Oct 5 15:41:23 UTC 2025
Sun Oct 5 15:41:33 UTC 2025
Sun Oct 5 15:41:43 UTC 2025
Sun Oct 5 15:41:53 UTC 2025
Sun Oct 5 15:42:03 UTC 2025
Sun Oct 5 15:42:13 UTC 2025
Sun Oct 5 15:42:23 UTC 2025
Sun Oct 5 15:42:33 UTC 2025
Sun Oct 5 15:42:43 UTC 2025
Sun Oct 5 15:42:53 UTC 2025
Sun Oct 5 15:43:03 UTC 2025
Sun Oct 5 15:43:13 UTC 2025
/opt/finance/time #
This will:
- Create a config map
time-config
withTIME_FREQ=10
- Create a pod
time-check
in thedevops
namespace - Use
busybox:latest
to run a loop that logs the date every$TIME_FREQ
seconds - Write logs to
/opt/finance/time/time-check.log
- Mount a volume named
log-volume
at/opt/finance/time
No comments:
Post a Comment