The Nautilus DevOps team needs to create a time-check Pod in a specific Kubernetes namespace for logging purposes. Initially, this setup is for testing but might be integrated into an existing cluster later. Here’s what is required:
- Create a Pod named time-check in the devops namespace.
- The Pod should contain a container named time-check, using the busybox image with the latest tag (specify as
busybox:latest
). - Create a ConfigMap named time-config with the data
TIME_FREQ=12
in the same namespace. - Configure the time-check container to execute the command:
while true; do date; sleep $TIME_FREQ; done
. Ensure the result is written to/opt/devops/time/time-check.log
. - Add an environmental variable TIME_FREQ in the container, fetching its value from the ConfigMap TIME_FREQ key.
- Create a volume log-volume and mount it at
/opt/devops/time
within the container.
First, create the namespace where the Pod and ConfigMap will be deployed.
kubectl create namespace devops
Output:
namespace/devops created
Create a ConfigMap named time-config in the devops namespace with the specified data.
kubectl create configmap time-config --from-literal=TIME_FREQ=12 --namespace=devops
Output:
configmap/time-config created
Create a YAML file named time-check-pod.yaml
with the following content:
apiVersion: v1
kind: Pod
metadata:
name: time-check
namespace: devops
spec:
volumes:
- name: log-volume
emptyDir: {}
containers:
- name: time-check
image: busybox:latest
volumeMounts:
- name: log-volume
mountPath: /opt/devops/time/
env:
- name: TIME_FREQ
valueFrom:
configMapKeyRef:
name: time-config
key: TIME_FREQ
command: ["/bin/sh", "-c"]
args:
- "while true; do date; sleep $TIME_FREQ; done > /opt/devops/time/time-check.log"
Apply the Pod configuration to the Kubernetes cluster.
kubectl apply -f time-check-pod.yaml
Output:
pod/time-check created
-
Verify the Pod Creation:
kubectl get pods --namespace=devops
Expected Output:
NAME READY STATUS RESTARTS AGE time-check 1/1 Running 0 <age>
-
Check the Logs:
To verify that the command is running correctly and logs are being generated, you can use:
kubectl exec -it time-check --namespace=devops -- cat /opt/devops/time/time-check.log
This solution sets up a Pod with the specified requirements, using ConfigMaps for environment variables, and ensures logging to a mounted volume.