Question
Create a Job with an image node which prints node version. Verify if the pod is created for this job and check its logs.
Answer
Create a job imperatively:
kubectl create job nodeversion --image=node -- node -v
Verify:
kubectl get job -w
kubectl get pod
kubectl logs nodeversion-9kzh8
Manifest for declarative approach:
apiVersion: batch/v1
kind: Job
metadata:
labels:
job-name: nodeversion
name: nodeversion
spec:
completions: 1
parallelism: 1
selector:
matchLabels:
job-name: nodeversion
template:
metadata:
labels:
job-name: nodeversion
spec:
containers:
- command:
- node
- -v
image: node
name: nodeversion
restartPolicy: Never