Kubernetes Time Check Pod Setup Guide

Set Up Time Check Pod in Kubernetes

Set Up Time Check Pod in Kubernetes

How to Efficiently Set Up a Time Check Pod in Kubernetes

Tasks

  • Create a pod called time-check in the devops namespace. The pod should have a container named time-check, using the busybox image with the latest tag (busybox:latest).

  • Create a config map named time-config with the data TIME_FREQ=12 in the same namespace.

  • Configure the time-check container to run the command: while true; do date; sleep $TIME_FREQ; done. Ensure the output is written to /opt/sysops/time/time-check.log. Add an environment variable TIME_FREQ in the container, getting its value from the config map TIME_FREQ key.

  • Create a volume log-volume and mount it at /opt/sysops/time within the container.

Steps

  1. Create a manifest file time-check.yaml.

     apiVersion: v1
     kind: Namespace
     metadata:
       name: devops
     ---
     apiVersion: v1
     kind: ConfigMap
     metadata:
       name: time-config
       namespace: devops
     data:
       TIME_FREQ: "12"
     ---
     apiVersion: v1
     kind: Pod
     metadata:
       name: time-check
       namespace: devops
     spec:
       containers:
         - name: time-check
           image: busybox:latest
           command: ["sh", "-c", "while true; do date >> /opt/sysops/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/sysops/time
       volumes:
         - name: log-volume
           emptyDir: {}
     cat << EOF > time-check.yaml
     apiVersion: v1
     kind: Namespace
     metadata:
       name: devops
     ---
     apiVersion: v1
     kind: ConfigMap
     metadata:
       name: time-config
       namespace: devops
     data:
       TIME_FREQ: "12"
     ---
     apiVersion: v1
     kind: Pod
     metadata:
       name: time-check
       namespace: devops
     spec:
       containers:
         - name: time-check
           image: busybox:latest
           command: ["sh", "-c", "while true; do date >> /opt/sysops/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/sysops/time
       volumes:
         - name: log-volume
           emptyDir: {}
     EOF
  2. Now apply

     kubectl apply -f time-check.yaml
  3. ss