Command to start a pod - answerkubectl run nginx --image=nginx --restart=Never
Command to change image of a pod - answerkubectl set image pod/nginx
nginx=nginx:1.7.1
Sequence to ping a pod from busybox - answerkubectl run busybox --image=busybox --
restart=Never --rm -it -- sh
# / wget -O- <pod_ip>:80
#/ exit
Output nice yaml from a resource - answerkubectl get pod nginx -o yaml --export
Get logs of a previous version of a pod - answerkubectl logs nginx -p
Attach a process to a running pod - answerkubectl exec -it nginx -- /bin/sh
Set an environment variable from command line - answerkubectl run nginx --
image=nginx --env=var1=val1
Multi-container pod - answerkubectl run busybox --image=busybox -o yaml --dry-run
-- /bin/sh -c 'echo hello;' > pod.yaml
# vi pod.yaml, Copy + Paste container list and rename the container
kubectl create -f pod.yaml
kubectl exec -it busybox -c busybox2 -- /bin/bash # Connect to second container
Create a pod with labels - answerkubectl run --image... --restart=Never --
labels=app=v1,label2=val2
Show labels on pods / resource - answerkubectl get pods --show-labels
Label a running pod - answerkubectl label po nginx app=v2 --overwrite
Get all pods with a certain label - answerkubectl get po -lapp
Remove a label from a running pod - answerkubectl label nginx{1..3} app-
Get documentation for a pod spec - answerkubectl explain po.spec
Annotate a running pod - answerkubectl annotate po nginx description='test description'
kubectl annotate po nginx description- # Remove
, Create pod with 2 replicas and open port 80 from yaml - answerkubectl create deploy
nginx --image=... --dry-run -oyaml > deploy.yaml
vi deploy.yaml
# Change replicas: 2
# Under containers list add following
ports:
- containerPort: 80
kubectl create -f deploy.yaml
Check status and history of a deployment - answerkubectl rollout status deploy nginx
kubectl rollout history deploy nginx
Up replicas of a deployment to 5 - answerkubectl scale deploy nginx --replicas=5
Install a horizontal pod autoscaler on a deployment - answerkubectl autoscale deploy
nginx --min=5 --max=10 --cpu-percent=80
Temporarily disable+enable future updates to a deployment - answerkubectl rollout
pause deploy nginx
kubectl rollout resume deploy nginx
Get history of of a deployment - answerkubectl rollout history deploy nginx --revision=6
Start a "job" pod - answerkubectl run pi --image=perl --restart=OnFailure -- perl ...
Monitor running jobs - answerkubectl get jobs -w
Get the logs of a job/pod (and monitor as it runs) - answerkubectl logs perl-*** -f
Remove a job from history/cluster - answerkubectl delete job pi
Get logs after the pod/job completes - answerkubectl logs job/pi
Job yaml to run concurrently or multiple times - answerjob.spec.completions=5
job.spec.parallelism=5
Command to run a cronjob (view it afterwards) - answerkubectl run pi --image=perl --
restart=OnFailure --schedule="*/1 (four asterisk)"
kubectl get cj
Config map from file or env file - answerecho -e "foo3=lili\nfoo4=lele" > config.txt
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller Dreamer252. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $18.99. You're not tied to anything after your purchase.