Can anyone tell me why my solution is wrong? Question: Create a pod with the ub . . .

Samir:
Can anyone tell me why my solution is wrong?

Question: Create a pod with the ubuntu image to run a container to sleep for 5000 seconds. Modify the file ubuntu-sleeper-2.yaml.
My file:

apiVersion: v1
kind: Pod
metadata:
  name: ubuntu-sleeper-2
spec:
  containers:
  - name: ubuntu
    image: ubuntu
    command: ['sh', '-c', 'sleep 5000']

Samir:
suggested solution:

---
apiVersion: v1 
kind: Pod 
metadata:
  name: ubuntu-sleeper-2 
spec:
  containers:
  - name: ubuntu
    image: ubuntu
    command:
      - "sleep"
      - "5000"

Samir:
Can someone tell me how generally I can pass cmds to pods? I am a bit confused because there are so many different ways to do it

Mayur Sharma:
I think it is fine any way you chooses, till your pod in coming running.
You can describe the pod and check if it same as you were expecting

Mohamed Ayman:
FORM#1:

spec:
containers:

  • command:
    • sleep
      args:
    • “4000”

FORM#2:
spec:
containers:

  • command:
    • sh
    • -c
    • sleep 4000

FORM#3:

spec:
containers:

  • command: [‘sh’, ‘-c’, ‘sleep 4000’]

All of them will work properly as you can the command inline or in multiple lines or you can use args to specify the arguments.

MB:
you can try command: [‘sh’, ‘-c’, ‘sleep’, ‘5000’] since 5000 is an argument

PR:
you can try kubectl run ubuntu --image=ubuntu --command sleep 5000 --dry-run=client -o yaml > xxx.yaml

PR:
just mention like this.

spec:
  containers:
  - name: ubuntu
    image: ubuntu
    command: ["sleep", "5000"].          manually you can mention this way

PR:
by command you get this way spec:
containers:

  • command:
    • sh
    • -c
    • sleep 5000