I am not able to find issue in answer. kindly help me to find issue.
Question:
For this question, please set the context to cluster1
by running:
kubectl config use-context cluster1
In the ckad-job
namespace, create a cronjob named simple-python-job
to run every 30 minutes to list all the running processes inside a container that used python
image (the command needs to be run in a shell).
In Python, ps –eaf
can be use to list all the running processes.
My answer is:
apiVersion: batch/v1
kind: CronJob
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"batch/v1","kind":"CronJob","metadata":{"annotations":{},"creationTimestamp":null,"name":"simple-python-job","namespace":"ckad-job"},"spec":{"jobTemplate":{"metadata":{"creationTimestamp":null,"name":"simple-python-job"},"spec":{"template":{"metadata":{"creationTimestamp":null},"spec":{"containers":[{"command":["/bin/sh","-c","ps -eaf"],"image":"python","name":"simple-python-job","resources":{}}],"restartPolicy":"OnFailure"}}}},"schedule":"*/30 * * * *"},"status":{}}
creationTimestamp: "2024-01-10T19:33:42Z"
generation: 1
name: simple-python-job
namespace: ckad-job
resourceVersion: "5413"
uid: 40584d7c-6926-4912-b726-37f5f3738a83
spec:
concurrencyPolicy: Allow
failedJobsHistoryLimit: 1
jobTemplate:
metadata:
creationTimestamp: null
name: simple-python-job
spec:
template:
metadata:
creationTimestamp: null
spec:
containers:
- command:
- /bin/sh
- -c
- ps -eaf
image: python
imagePullPolicy: Always
name: simple-python-job
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: OnFailure
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
schedule: '*/30 * * * *'
successfulJobsHistoryLimit: 3
suspend: false
status:
lastScheduleTime: "2024-01-10T20:30:00Z"
lastSuccessfulTime: "2024-01-10T20:30:41Z"
Correct answer is:
apiVersion: batch/v1
kind: CronJob
metadata:
name: simple-python-job
namespace: ckad-job
spec:
schedule: "*/30 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: simple-python-job
image: python
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- ps –eaf
restartPolicy: OnFailure
I am not able to find where is the actual issue in my implementation.
Issue is "incorrect command’ rest is okay.