For the LIGHTNING LAB – 1, Create a pod called time-check in the dvl1987 namesp . . .

madhusmita:
For the LIGHTNING LAB – 1,

Create a pod called time-check in the dvl1987 namespace. This pod should run a container called time-check that uses the busybox image.
> Create a config map called time-config with the data TIME_FREQ=10 in the same namespace.
The time-check container should run the command: while true; do date; sleep $TIME_FREQ;done and write the result to the location /opt/time/time-check.log.
The path /opt/time on the pod should mount a volume that lasts the lifetime of this pod.

Pod time-check configured correctly?

I created the namespace dvl1987 and time-config in dvl1987 namespace.
The yaml for pod is:
apiVersion: v1
kind: Pod
metadata:
labels:
run: time-check
name: time-check
namespace: dvl1987
spec:
containers:

  • image: busybox
    name: time-check
    env:
    # Define the environment variable
    • name: TIME_FREQ
      valueFrom:
      configMapKeyRef:
      name: time-config
      key: TIME_FREQ
      command: [“/bin/sh”]
      args: [“-c”, “while true; do date; sleep $TIME_FREQ;done”]
      volumeMounts:
    • name: config-vol
      mountPath: /opt/time
      volumes:
    • name: config-vol
      emptyDir: {}

it creates the pod and when I check the date in the container, it shows me the date. The env variable is set in the container. But answer says it is incorrect. Coudl you tell me what is wrong in the creating pod here?

unnivkn:
command: [“/bin/sh”,“-c”,“while true; do date; sleep $TIME_FREQ;done > /opt/time/time-check.log”]

unnivkn:
missing this in your yaml: /opt/time/time-check.log

madhusmita:
Thanks @unnivkn.it worked.

My error is Need to add Environment Variable for TIME_FREQ. How to solve this? @madhusmita

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; sleep $TIME_FREQ;done > /opt/dba/time/time-check.log”,
]
envFrom:
- configMapRef:
name: time-config
volumeMounts:
- name: log-volume
mountPath: /opt/dba/time
volumes:
- name: log-volume
emptyDir : {}
restartPolicy: Never