Skip to main content

Time Check Pod (devops)

·243 words·2 mins
Jack Warner
Author
Jack Warner
A little blog by me

Step 1: Create the devops namespace and ConfigMap
#

Create the namespace:

kubectl create namespace devops

Create 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.yaml

Verify it was created:

kubectl get configmap time-config -n devops
kubectl describe configmap time-config -n devops

Step 2: Create the Pod with all requirements
#

Create the complete Pod YAML with the following:

  • Pod name: time-check in namespace devops
  • Container named time-check using busybox:latest
  • Command: while true; do date; sleep $TIME_FREQ; done and append output to /opt/itadmin/time/time-check.log
  • Environment variable TIME_FREQ from ConfigMap time-config
  • Volume log-volume mounted 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.yaml

Verification
#

Check Pod status:

kubectl get pod time-check -n devops

Describe the Pod for details:

kubectl describe pod time-check -n devops

Verify the environment variable:

kubectl exec -it time-check -n devops -- env | grep TIME_FREQ

Check the log file (allow a few seconds for the first entries):

kubectl exec -it time-check -n devops -- cat /opt/itadmin/time/time-check.log

Tail the log in real-time:

kubectl exec -it time-check -n devops -- tail -f /opt/itadmin/time/time-check.log

Related