You need to make sure that each pod scheduled as part of your Kubernetes job will have label myJobId="great job". How will you do that?

Experience Level: Junior
Tags: Kubernetes

Answer

Create a job manifest and save it to file by running the following command:

kubectl create job job1 --image=busybox --dry-run=client -o yaml -- /bin/sh -c 'echo hello' > job.yaml

Then edit the file by running the following command:

nano job.yaml

Find metadata.labels section in the template. Add the label.

apiVersion: batch/v1
kind: Job
metadata:
  creationTimestamp: null
  name: job1
spec:
  template:
    metadata:
      creationTimestamp: null
      labels:
        myJobId: "great job" #add this line
    spec:
      containers:
      - image: busybox
        name: job1
        command:
        - /bin/sh
        - -c
        - echo hello
      restartPolicy: Never

Then save the file and run the following command

kubectl apply -f job.yaml
Kubernetes Certified Application Developer (CKAD) preparation
Kubernetes Certified Application Developer (CKAD) preparation

Are you learning Kubernetes ? Try our test we designed to help you progress faster.

Test yourself
Kubernetes
Kubernetes

Are you learning Kubernetes ? Try our test we designed to help you progress faster.

Test yourself
Kubernetes Certified Administrator (CKA) preparation
Kubernetes Certified Administrator (CKA) preparation

Are you learning Kubernetes ? Try our test we designed to help you progress faster.

Test yourself