Kubernetes Time Check Pod

Ticker

6/recent/ticker-posts

Kubernetes Time Check Pod

 Question : The Nautilus DevOps team want to create a time check pod in a particular Kubernetes namespace and record the logs. This might be initially used only for existing purposes, but later can be implemented in a n existing cluster. Please find more details beow about the task and perform it.

Create a pod called time-check in the devops namespace. This pod should run a container called time-check container should use the busybox image with latest tag only and remember to mention tag i.e busybox:latest.

Create a config map called time-config with the data TIME_FREQ=10 in the same namespace, and volume name should be log-volume.

The time-check container should run the command: while true; do date; sleep $TIME_FREQ;done and should write the result to the location /opt/security/time/time-check.log.

The path /opt/security/time on the pod should mount a volume that lasts the lifetime of this pod.

Please Note:-  Perform the below commands based on your question server,  user name & other details that might differ. So please read the task carefully before executing it. 
All the Best 👍

Solution:  

1. At first  kubectl  utility configure and working from jump server, run below commands  

thor@jump_host /$ kubectl get namespace

NAME              STATUS   AGE

default           Active   8m20s

kube-node-lease   Active   8m21s

kube-public       Active   8m22s

kube-system       Active   8m22s

thor@jump_host /$

thor@jump_host /$ kubectl get pods

No resources found in default namespace.

thor@jump_host /$


2. create a new namespace  as per the given in the task 
  

thor@jump_host /$ kubectl create namespace devops

namespace/devops created

thor@jump_host /$

3.  Create a YAML  file with all the parameters, you can copy from GitLab

    https://gitlab.com/nb-tech-support/devops.git

    Refer Below Video for more clarity )

thor@jump_host /$ vi /tmp/time.yaml

thor@jump_host /$ cat /tmp/time.yaml

apiVersion: v1

kind: ConfigMap

metadata:

  name: time-config

  namespace: devops

data:

  TIME_FREQ: "10"

---

apiVersion: v1

kind: Pod

metadata:

  name: time-check

  namespace: devops

  labels:

    app: time-check

spec:

  volumes:

    - name: log-volume

      emptyDir: {}

  containers:

    - name: time-check

      image: busybox:latest

      volumeMounts:

        - mountPath: /opt/security/time

          name: log-volume

      envFrom:

        - configMapRef:

            name: time-config

      command: ["/bin/sh", "-c"]

      args:

        [

          "while true; do date; sleep $TIME_FREQ;done > /opt/security/time/time-check.log",

        ]

thor@jump_host /$

4.  Run the below command to create a pod

thor@jump_host /$ kubectl create -f /tmp/time.yaml

configmap/time-config created

pod/time-check created

thor@jump_host /$


5.  Wait for  pods to get running status
      

thor@jump_host /$ kubectl get pods -n devops

NAME         READY   STATUS    RESTARTS   AGE

time-check   1/1     Running   0          31s

thor@jump_host /$

6.  Click on Finish & Confirm to complete the task successfully

Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this , 

please go through and share your comments. Like and share the knowledge



Post a Comment

0 Comments

Latest Posts

KodeKloud Kubernetes Security CKS  Lab Challenge 4 |  Audit-policy | Install & configure falco utility | Inspect the API server audit logs and identify the user