Skip to main content

Command Palette

Search for a command to run...

Set Up Time Check Pod in Kubernetes

How to Efficiently Set Up a Time Check Pod in Kubernetes

Published
2 min read
Set Up Time Check Pod in Kubernetes
A

Infosec Poet and CAP-certified DevOps/SecOps Engineer, passionate about security, creativity, and continuous learning.

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

DevOps

Part 1 of 10

In this series, I will cover various DevOps practices, tools, CI/CD pipelines, infrastructure as code, automation tips, and troubleshooting techniques.

Up next

Create Countdown Job in Kubernetes

How to Set Up a Countdown Job in Kubernetes