Step 1: Create the devops namespace and ConfigMap
#
Create the namespace:
kubectl create namespace devopsCreate time-config ConfigMap with TIME_FREQ=3:
apiVersion: v1
kind: ConfigMap
metadata:
name: time-config
namespace: devops
data:
TIME_FREQ: "3"Apply the ConfigMap:
kubectl apply -f time-config.yamlVerify it was created:
kubectl get configmap time-config -n devops
kubectl describe configmap time-config -n devopsStep 2: Create the Pod with all requirements #
Create the complete Pod YAML with the following:
- Pod name:
time-checkin namespacedevops - Container named
time-checkusingbusybox:latest - Command:
while true; do date; sleep $TIME_FREQ; doneand append output to/opt/itadmin/time/time-check.log - Environment variable
TIME_FREQfrom ConfigMaptime-config - Volume
log-volumemounted at/opt/itadmin/time
apiVersion: v1
kind: Pod
metadata:
name: time-check
namespace: devops
spec:
containers:
- name: time-check
image: busybox:latest
command:
- /bin/sh
- -c
- while true; do date; sleep $TIME_FREQ; done >> /opt/itadmin/time/time-check.log
env:
- name: TIME_FREQ
valueFrom:
configMapKeyRef:
name: time-config
key: TIME_FREQ
volumeMounts:
- name: log-volume
mountPath: /opt/itadmin/time
restartPolicy: Always
volumes:
- name: log-volume
emptyDir: {}Apply the Pod:
kubectl apply -f time-pod.yamlVerification #
Check Pod status:
kubectl get pod time-check -n devopsDescribe the Pod for details:
kubectl describe pod time-check -n devopsVerify the environment variable:
kubectl exec -it time-check -n devops -- env | grep TIME_FREQCheck the log file (allow a few seconds for the first entries):
kubectl exec -it time-check -n devops -- cat /opt/itadmin/time/time-check.logTail the log in real-time:
kubectl exec -it time-check -n devops -- tail -f /opt/itadmin/time/time-check.log