kubernetes-up-and-running / kuard

Demo app for Kubernetes Up and Running book
Apache License 2.0
1.59k stars 543 forks source link

Jobs, chapter 12, with K8s 1.18, 2 breaking changes #33

Open javajon opened 4 years ago

javajon commented 4 years ago

Chapter 12 says to start a Job like this:

$ kubectl run -i oneshot \
  --image=gcr.io/kuar-demo/kuard-amd64:blue \
  --restart=OnFailure \
  -- --keygen-enable \
      --keygen-exit-on-complete \
      --keygen-num-to-gen 10

With K8s 1.18, there is a deprecation.

Remove all the generators from kubectl run. It will now only create pods. Additionally, deprecates all the flags that are not relevant anymore. (#87077, @soltysh) [SIG Architecture, SIG CLI, and SIG Testing]

So instead this command creates a Pod instead of a Job. OK, software evolves and printed copies do not. We can deal with this. However, there is another issue. The Pod will fail with:

Error: failed to start container "kuard": Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"--keygen-enable\": executable file not found in $PATH": unknown

Something about "blue" version of Kuard container changed. To work around it one has to change the command to

$ kubectl run -i oneshot \
  --image=gcr.io/kuar-demo/kuard-amd64:blue \
  --restart=OnFailure \
  -- \
      /kuard \
      --keygen-enable \
      --keygen-exit-on-complete \
      --keygen-num-to-gen 10

Notice the addition of /kuard \

@surfer190 also documented their findings in these extensive notes found here. In the document search for "That said the error:" to see the same finding.

The issue is noted and worked around in this Katacoda scenario. I'm the author of this scenario.

This issue is more of an errata note for the Jobs chapter.

Cesarsk commented 2 years ago

That was a lifesaver! Thank you.

Cesarsk commented 2 years ago

Leaving it to readers:

If you want instead use the .yaml, the updated version is:

apiVersion: batch/v1
kind: Job
metadata:
  name: oneshot
spec:
  parallelism: 5
  completions: 10
  template:
    spec:
      containers:
        - name: kuard
          image: gcr.io/kuar-demo/kuard-amd64:blue
          imagePullPolicy: Always
          args:
          - "/kuard"
          - "--keygen-enable"
          - "--keygen-exit-on-complete"
          - "--keygen-num-to-gen=10"
      restartPolicy: OnFailure
soltysh commented 2 years ago

Wouldn't it be easier to use:

kubectl create job oneshot --image=gcr.io/kuar-demo/kuard-amd64:blue -- \
    --keygen-enable --keygen-exit-on-complete --keygen-num-to-gen 10
Cesarsk commented 2 years ago

Yes, it's easier, but the syntax would be, according to the changes:

kubectl create job oneshot --image=gcr.io/kuar-demo/kuard-amd64:blue -- \
    /kuard --keygen-enable --keygen-exit-on-complete --keygen-num-to-gen 10