Reputation: 61
I want to execute a command during the creation of the pod. I see two options available :
kubectl run busybox --image=busybox --restart=Never -- sleep 3600
kubectl run busybox --image=busybox --restart=Never -- /bin/sh -c "sleep 3600"
What is the difference between the above two commands ?
Upvotes: 0
Views: 21055
Reputation: 3284
In short no difference in the outcome if you want to run "sleep 3600". Both perform the same operation.
To understand the behaviour of those options add dry-run option to it
First one passes "sleep" & "3600" as arguments to Entrypoint of busybox image which is "/bin/sh"
kubectl run busybox --image=busybox --restart=Never --dry-run=client -o yaml -- sleep 3600
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: busybox
name: busybox
spec:
containers:
- args:
- sleep
- "3600"
image: busybox
name: busybox
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Never
kubectl run busybox --image=busybox --restart=Never --dry-run=client -o yaml -- /bin/sh -c "sleep 3600"
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: busybox
name: busybox
spec:
containers:
- args:
- /bin/sh
- -c
- sleep 3600
image: busybox
name: busybox
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Never
status: {}
kubectl run busybox --image=busybox --restart=Never -- /bin/sh -c "sleep 3600;echo boo"
Upvotes: 2