Removed old trick to create pods with kubectl run#167
Conversation
| <p> | ||
|
|
||
| ```bash | ||
| kubectl run busybox --image=busybox --command --restart=Never -it -- env # -it will help in seeing the output |
There was a problem hiding this comment.
Default is restart=Always, which implies that the busybox container will be restarted indefinitely...
Pod lifecyle in this case:
start container > execute command > stop container > restart container > ... (loop infinitely...)
==> --restart=Never arg should not be omitted here.
Same comment is valid for several similar changes in this PR.
There was a problem hiding this comment.
@dgkanatsios, my mistake for those pod with busybox, merlixo makes a good point. I was thinking about something else when I made these changes since I normally use busybox with something like sleep 3600 to keep it running for an hour in labs, or to use it as a temp container using --rm to run some tests.
For the other changes where nginx is used, my original commit message still applies because nginx doesn't run and complete like busybox, creating a loop. In other words, using kubectl run nginx --image=nginx --restart=Never -n mynamespace is an example of the old trick being applied. Using kubectl run nginx --image=nginx -n mynamespace without --restart=Never is fine because the logic here is correct.
I've updated my PR so that the changes are only applied where nginx is used. The busybox entries are now the original entries before the change.
Before k8s 1.18, people would set the restart policy in their imperative commands to make
kubectl rungenerate deployments, pods, or jobs depending on whether the restart policy was set to Always, OnFailure, or Never respectively. For example,kubectl run nginx --image=nginx --restart=Alwayscreated a deployment, andkubectl run nginx --image=nginx --restart=Nevercreated a pod. The default behavior ofkubectl runwhen a restart policy wasn't specified was also a deployment. You could even specify--scheduleto create cronjobs too. With k8s 1.18 and above,kubectl runcan now ONLY create pods, and people now have to use thekubectl createcommands to create the other objects, including deployments. The bad thing about this is that in 1.18,kubectl create deploymentdoesn't support all the flags thatkubectl rundid, but with 1.19, some of these flags like--portand--replicashave been added to make the command more useful. With all of this in mind, this pull requests removes the--restart=Nevertrick wherekubectl runis used, since we no longer need it for forcing the command to create pods. In other words, how this flag is being used is redundant and only serves to override the default restart policy of a pod, which isAlwaysand not why it was included originally. I feel this change will make things more consistent now and in line with the exam, which is based on k8s 1.19+ now.References:
https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.18.md#kubectl
https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.19.md#feature-3
https://alexellisuk.medium.com/kubernetes-1-18-broke-kubectl-run-heres-what-to-do-about-it-2a88e5fb389a