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.
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
/$ |
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
/$ |
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!!!!
0 Comments