Justin Dowe:
imperative commands specifying arguments
Was wonder how I run this as imperative command to get commands and arguments
kubectl run box1 image=busybox --command
Shwetha:
k run box1 --image=busybox --command -- /bin/sh -c "while true;do echo hello;sleep 10;done"
Justin Dowe:
Shwetha:
Ah… So, it doesnt addnt add them as args but part of command
Alistair Mackay:
You got commas in there - container will crash!
Needs to be all semicolons
Justin Dowe:
good to know
Justin Dowe:
but if you leave command out,
– “/bin/sh” “-c” “while true…”
Shwetha:
yep. It is either command or args
Shwetha:
I guess you will need to edit the yaml if you need -c “while true….” to be specified as args.
Justin Dowe:
ok
Alistair Mackay:
Without --command
you get args
k run busybox --image busybox --dry-run=client -o yaml -- sh -c "while true ; do echo hi ; done"
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: busybox
name: busybox
spec:
containers:
- args:
- sh
- -c
- while true ; do echo hi ; done
image: busybox
name: busybox
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
With --command
you get command
k run busybox --image busybox --dry-run=client -o yaml --command -- sh -c "while true ; do echo hi ; done"
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: busybox
name: busybox
spec:
containers:
- command:
- sh
- -c
- while true ; do echo hi ; done
image: busybox
name: busybox
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
Alistair Mackay:
Which I guess means if it is args that are being generated, the docker image will need an ENTRYPOINT
for this format, to which the args will be passed.
Alistair Mackay:
And also sh -c 'some script'
probably doesn’t make sense for most arguments, unless the entrypoint was something like sudo
Justin Dowe:
OK, thats fair, ty for the tip about the commas
Alistair Mackay:
You may still need to edit the generated YAML, as it is likely that the script argument while ...
will need to be quoted within the YAML so it is passed to the container’s shell correctly.
Justin Dowe:
I saw an example in one of the labs
[“/bin/sh -c while true; do echo hello; sleep 10;done”]
unnivkn:
Hi @Justin Dowe alternatively, you can refer this link to get similar declarative statements:
https://kubernetes.io/docs/concepts/cluster-administration/logging/