Hi everyone. I have a question about kubectl run command. Problem: declaritive w . . .

Hye Jin Park:
Hi everyone. I have a question about kubectl run command.
Problem: declaritive way works fine. but Imperative way doesn’t work… :confused:

  1. This works fine.
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: test
  name: test
spec:
  containers:
  - args: ["/bin/sh","-c","--","while true; do sleep 60; done;"]
    image: busybox
    name: test
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

$ kubectl apply -f test.yaml

  1. This doesn’t work.
kubectl run test --image=busybox -- /bin/bash -c -- while true; do sleep 10; done;
> bash: syntax error near unexpected token 'do'

kubectl run test --image=busybox -- /bin/bash -c -- 'while true; do sleep 10; done;'
> Error: failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown

Paweł Cyrklaf:
I can create without any problem

Hye Jin Park:
@Paweł Cyrklaf Thank you for replying!
I found the command was

kubectl run test --image=busybox -- /bin/bash -c -- while true; do sleep 10; done;

except --dry-run and -o option. sorry ;;

Hye Jin Park:
I also rewrote the first message.

Paweł Cyrklaf:
Ok so, you should add the command in an apostrophe and change /bin/bash to /bin/sh . I mean

kubectl run test --image=busybox -- /bin/sh -c  -- 'while true; do sleep 10; done;'

Paweł Cyrklaf:

Paweł Cyrklaf:
@Hye Jin Park Look at difference between declarative and imperative. In declarative you use /bin/sh, but in imperative you use /bin/bash :slight_smile:

Hye Jin Park:
oh!

Hye Jin Park:
:anguished:

Hye Jin Park:
thank you @Paweł Cyrklaf!!!

Paweł Cyrklaf:
You’re welcome :slight_smile: