|
2 | 2 |
|
3 | 3 | The Nautilus DevOps team needs a time check pod created in a specific Kubernetes namespace for logging purposes. Initially, it's for testing, but it may be integrated into an existing cluster later. Here's what's required: |
4 | 4 |
|
5 | | -Create a pod called time-check in the devops namespace. The pod should contain a container named time-check, utilizing the busybox image with the latest tag (specify as busybox:latest). |
| 5 | +Create a pod called `time-check` in the `nautilus` namespace. The pod should contain a container named `time-check`, utilizing the `busybox` image with the latest tag (specify as `busybox:latest`). |
6 | 6 |
|
7 | | -- Create a config map named time-config with the data TIME_FREQ=10 in the same namespace. |
| 7 | +- Create a config map named `time-config` with the data `TIME_FREQ=7` in the same namespace. |
8 | 8 |
|
9 | | -- Configure the time-check container to execute the command: while true; do date; sleep $TIME_FREQ;done. Ensure the result is written /opt/finance/time/time-check.log. Also, add an environmental variable TIME_FREQ in the container, fetching its value from the config map TIME_FREQ key. |
| 9 | +- Configure the `time-check` container to execute the command: `while true; do date; sleep $TIME_FREQ;done`. Ensure the result is written `/opt/finance/time/time-check.log`. Also, add an environmental variable `TIME_FREQ` in the container, fetching its value from the config map `TIME_FREQ` key. |
10 | 10 |
|
11 | | -- Create a volume log-volume and mount it at /opt/finance/time within the container. |
| 11 | +- Create a volume `log-volume` and mount it at `/opt/finance/time` within the container. |
12 | 12 |
|
13 | 13 | > Note: The kubectl utility on jump_host is configured to operate with the Kubernetes cluster. |
14 | 14 |
|
15 | 15 | ## Steps |
16 | 16 |
|
| 17 | +1. Let's check namespace and create `nautilus` namespace |
| 18 | + |
| 19 | + ```sh |
| 20 | + kubectl get ns |
| 21 | + kubectl create ns nautilus |
| 22 | + ``` |
| 23 | + |
| 24 | +2. Let's create the `k3s.yml` file using [this contents](./09.yml) |
| 25 | +
|
| 26 | + ```YAML |
| 27 | + # ConfigMap |
| 28 | + apiVersion: v1 |
| 29 | + kind: ConfigMap |
| 30 | + metadata: |
| 31 | + name: time-config |
| 32 | + namespace: nautilus |
| 33 | + data: |
| 34 | + TIME_FREQ: "7" |
| 35 | +
|
| 36 | + --- |
| 37 | +
|
| 38 | + apiVersion: v1 |
| 39 | + kind: Pod |
| 40 | + metadata: |
| 41 | + name: time-check |
| 42 | + namespace: nautilus |
| 43 | + labels: |
| 44 | + app: time-check |
| 45 | + spec: |
| 46 | + containers: |
| 47 | + - name: time-check |
| 48 | + image: busybox:latest |
| 49 | + command: ["/bin/sh", "-c", "while true; do date >> /opt/finance/time/time-check.log; sleep ${TIME_FREQ}; done"] |
| 50 | + env: |
| 51 | + - name: TIME_FREQ |
| 52 | + valueFrom: |
| 53 | + configMapKeyRef: |
| 54 | + name: time-config |
| 55 | + key: TIME_FREQ |
| 56 | + volumeMounts: |
| 57 | + - name: log-volume |
| 58 | + mountPath: /opt/finance/time |
| 59 | + resources: |
| 60 | + limits: |
| 61 | + cpu: 100m |
| 62 | + memory: 128Mi |
| 63 | + requests: |
| 64 | + cpu: 100m |
| 65 | + memory: 128Mi |
| 66 | + volumes: |
| 67 | + - name: log-volume |
| 68 | + emptyDir: {} |
| 69 | + ``` |
| 70 | +
|
| 71 | +3. Let's run the following command: |
| 72 | + |
| 73 | + ```sh |
| 74 | + kubectl apply -f k3s.yml |
| 75 | + ``` |
| 76 | + |
| 77 | + > It will create configmap and pod |
| 78 | + |
| 79 | +4. We can verify |
| 80 | + |
| 81 | + ```sh |
| 82 | + kubectl get pods -n nautilus |
| 83 | + ``` |
| 84 | + |
| 85 | + ```shell |
| 86 | + kubectl get pods -n nautilus |
| 87 | + NAME READY STATUS RESTARTS AGE |
| 88 | + time-check 1/1 Running 0 19s |
| 89 | + ``` |
| 90 | + |
| 91 | +5. Verify log: |
| 92 | + To verify log, we can execute the container of the pods and inside we can check our log files. |
| 93 | + |
| 94 | + ```sh |
| 95 | + kubectl exec -it time-check -n nautilus /bin/sh |
| 96 | + cat /opt/finance/time/time-check.log |
| 97 | + ``` |
0 commit comments