Launch a single container
Problem: I want to launch a container, not write a Pod or Replication Controller file.
kubectl run, for example like so:
$ kubectl run asimplewebserver --image=nginx
Bootstrap a Replication Controller file
Problem: How can I bootstrap a Replication Controller (RC) manifest file?
kubectl run with the
$ kubectl run asimplewebserver --image=nginx --output=yaml --dry-run > asimplewebserver-rc.yaml
Note that above command will output the RC into
asimplewebserver-rc.yaml which you then can edit to your liking.
Problem: I want to provide a username and password to a container, how can I do that in a secure way?
Debugging using labels
Problem: I noticed one of the pods has gone bad. Can I debug it online?
Solution: Yes, by using labels. Assume you mark up your running pods with
status=serving and when you want to debug one of the pods without impacting the service, just re-label the bad pod to
status=troubleshooting and the RC will kick in to launch a new one, instead. Also, you have the bad pod for yourself to dissect. See also the walkthrough example here for a step-by-step instruction:
Multiple commands in container
Problem: Can I specify multiple commands for a container in a pod?
Solution: Yes, for example like so:
command: ["/bin/sh","-c"] args: ["first_command ; then_second_command && third_command_only_if_second_succeeded"]
command: ["/bin/sh", "-c"]above you specify a shell to execute in the container that gets the arguments listed in
args: [ ... ]passed in. In the above case, the first command as well as the second would always be executed and the third command only if the second command successfully executed (that is, a return value of 0). See also these two StackOverflow posts: , .
Access pod label from within one of its container
Problem: I want to access the labels of a pod from within one of its containers.
Have got a recipe you want to share? Please send in a Pull Request against the mhausenblas/k8s.info repo.