diff --git a/a.core_concepts.md b/a.core_concepts.md index 4379e150..5a88a35e 100644 --- a/a.core_concepts.md +++ b/a.core_concepts.md @@ -77,9 +77,9 @@ kubectl run nginx --image=nginx --dry-run=client -o yaml | kubectl create -n myn
```bash -kubectl run busybox --image=busybox --command -it -- env # -it will help in seeing the output +kubectl run busybox --image=busybox --command --restart=Never -it -- env # -it will help in seeing the output # or, just run it without -it -kubectl run busybox --image=busybox --command -- env +kubectl run busybox --image=busybox --command --restart=Never -- env # and then, check its logs kubectl logs busybox ``` @@ -94,7 +94,7 @@ kubectl logs busybox ```bash # create a YAML template with this command -kubectl run busybox --image=busybox --dry-run=client -o yaml --command -- env > envpod.yaml +kubectl run busybox --image=busybox --restart=Never --dry-run=client -o yaml --command -- env > envpod.yaml # see it cat envpod.yaml ``` @@ -234,13 +234,13 @@ Alternatively you can also try a more advanced option: # Get IP of the nginx pod NGINX_IP=$(kubectl get pod nginx -o jsonpath='{.status.podIP}') # create a temp busybox pod -kubectl run busybox --image=busybox --env="NGINX_IP=$NGINX_IP" --rm -it -- sh -c 'wget -O- $NGINX_IP:80' +kubectl run busybox --image=busybox --env="NGINX_IP=$NGINX_IP" --rm -it --restart=Never -- sh -c 'wget -O- $NGINX_IP:80' ``` Or just in one line: ```bash -kubectl run busybox --image=busybox --rm -it -- wget -O- $(kubectl get pod nginx -o jsonpath='{.status.podIP}:{.spec.containers[0].ports[0].containerPort}') +kubectl run busybox --image=busybox --rm -it --restart=Never -- wget -O- $(kubectl get pod nginx -o jsonpath='{.status.podIP}:{.spec.containers[0].ports[0].containerPort}') ```
@@ -318,9 +318,9 @@ kubectl exec -it nginx -- /bin/sh```bash -kubectl run busybox --image=busybox -it -- echo 'hello world' +kubectl run busybox --image=busybox -it --restart=Never -- echo 'hello world' # or -kubectl run busybox --image=busybox -it -- /bin/sh -c 'echo hello world' +kubectl run busybox --image=busybox -it --restart=Never -- /bin/sh -c 'echo hello world' ```
@@ -332,7 +332,7 @@ kubectl run busybox --image=busybox -it -- /bin/sh -c 'echo hello world'```bash -kubectl run busybox --image=busybox -it --rm -- /bin/sh -c 'echo hello world' +kubectl run busybox --image=busybox -it --rm --restart=Never -- /bin/sh -c 'echo hello world' kubectl get po # nowhere to be found :) ``` diff --git a/b.multi_container_pods.md b/b.multi_container_pods.md index 54e346db..fd6bf18b 100644 --- a/b.multi_container_pods.md +++ b/b.multi_container_pods.md @@ -9,7 +9,7 @@ Easiest way to do it is create a pod with a single container and save its definition in a YAML file: ```bash -kubectl run busybox --image=busybox -o yaml --dry-run=client -- /bin/sh -c 'echo hello;sleep 3600' > pod.yaml +kubectl run busybox --image=busybox --restart=Never -o yaml --dry-run=client -- /bin/sh -c 'echo hello;sleep 3600' > pod.yaml vi pod.yaml ``` @@ -135,7 +135,7 @@ kubectl apply -f pod-init.yaml kubectl get po -o wide # Execute wget -kubectl run box --image=busybox -it --rm -- /bin/sh -c "wget -O- IP" +kubectl run box --image=busybox --restart=Never -it --rm -- /bin/sh -c "wget -O- IP" # you can do some cleanup kubectl delete po box diff --git a/e.observability.md b/e.observability.md index d07aaabe..85007c98 100644 --- a/e.observability.md +++ b/e.observability.md @@ -142,7 +142,7 @@ kubectl delete -f pod.yaml
```bash -kubectl run busybox --image=busybox -- /bin/sh -c 'i=0; while true; do echo "$i: $(date)"; i=$((i+1)); sleep 1; done' +kubectl run busybox --image=busybox --restart=Never -- /bin/sh -c 'i=0; while true; do echo "$i: $(date)"; i=$((i+1)); sleep 1; done' kubectl logs busybox -f # follow the logs ``` @@ -157,7 +157,7 @@ kubectl logs busybox -f # follow the logs
```bash -kubectl run busybox --image=busybox -- /bin/sh -c 'ls /notexist' +kubectl run busybox --restart=Never --image=busybox -- /bin/sh -c 'ls /notexist' # show that there's an error kubectl logs busybox kubectl describe po busybox @@ -173,7 +173,7 @@ kubectl delete po busybox
```bash -kubectl run busybox --image=busybox -- notexist +kubectl run busybox --restart=Never --image=busybox -- notexist kubectl logs busybox # will bring nothing! container never started kubectl describe po busybox # in the events section, you'll see the error # also... diff --git a/f.services.md b/f.services.md index 5337b5e8..aabb1d25 100644 --- a/f.services.md +++ b/f.services.md @@ -35,7 +35,7 @@ kubectl get ep # endpoints ```bash kubectl get svc nginx # get the IP (something like 10.108.93.130) -kubectl run busybox --rm --image=busybox -it -- sh +kubectl run busybox --rm --image=busybox -it --restart=Never -- sh wget -O- IP:80 exit ``` @@ -46,7 +46,7 @@ or ```bash IP=$(kubectl get svc nginx --template={{.spec.clusterIP}}) # get the IP (something like 10.108.93.130) -kubectl run busybox --rm --image=busybox -it --env="IP=$IP" -- wget -O- $IP:80 --timeout 2 +kubectl run busybox --rm --image=busybox -it --restart=Never --env="IP=$IP" -- wget -O- $IP:80 --timeout 2 # Tip: --timeout is optional, but it helps to get answer more quickly when connection fails (in seconds vs minutes) ``` @@ -128,7 +128,7 @@ kubectl create deploy foo --image=dgkanatsios/simpleapp --port=8080 --replicas=3 ```bash kubectl get pods -l app=foo -o wide # 'wide' will show pod IPs -kubectl run busybox --image=busybox -it --rm -- sh +kubectl run busybox --image=busybox --restart=Never -it --rm -- sh wget -O- POD_IP:8080 # do not try with pod name, will not work # try hitting all IPs to confirm that hostname is different exit @@ -159,7 +159,7 @@ kubectl get endpoints foo # you will see the IPs of the three replica nodes, lis ```bash kubectl get svc # get the foo service ClusterIP -kubectl run busybox --image=busybox -it --rm -- sh +kubectl run busybox --image=busybox -it --rm --restart=Never -- sh wget -O- foo:6262 # DNS works! run it many times, you'll see different pods responding wget -O- SERVICE_CLUSTER_IP:6262 # ClusterIP works as well # you can also kubectl logs on deployment pods to see the container logs @@ -210,8 +210,8 @@ kubectl create -f policy.yaml # Check if the Network Policy has been created correctly # make sure that your cluster's network provider supports Network Policy (https://kubernetes.io/docs/tasks/administer-cluster/declare-network-policy/#before-you-begin) -kubectl run busybox --image=busybox --rm -it -- wget -O- http://nginx:80 --timeout 2 # This should not work. --timeout is optional here. But it helps to get answer more quickly (in seconds vs minutes) -kubectl run busybox --image=busybox --rm -it --labels=access=granted -- wget -O- http://nginx:80 --timeout 2 # This should be fine +kubectl run busybox --image=busybox --rm -it --restart=Never -- wget -O- http://nginx:80 --timeout 2 # This should not work. --timeout is optional here. But it helps to get answer more quickly (in seconds vs minutes) +kubectl run busybox --image=busybox --rm -it --restart=Never --labels=access=granted -- wget -O- http://nginx:80 --timeout 2 # This should be fine ```
diff --git a/g.state.md b/g.state.md index ddcdbfa7..224f693f 100644 --- a/g.state.md +++ b/g.state.md @@ -17,7 +17,7 @@ kubernetes.io > Documentation > Tasks > Configure Pods and Containers > [Configu Easiest way to do this is to create a template pod with: ```bash -kubectl run busybox --image=busybox -o yaml --dry-run=client -- /bin/sh -c 'sleep 3600' > pod.yaml +kubectl run busybox --image=busybox --restart=Never -o yaml --dry-run=client -- /bin/sh -c 'sleep 3600' > pod.yaml vi pod.yaml ``` Copy paste the container definition and type the lines that have a comment in the end: @@ -165,7 +165,7 @@ kubectl get pv # will show as 'Bound' as well Create a skeleton pod: ```bash -kubectl run busybox --image=busybox -o yaml --dry-run=client -- /bin/sh -c 'sleep 3600' > pod.yaml +kubectl run busybox --image=busybox --restart=Never -o yaml --dry-run=client -- /bin/sh -c 'sleep 3600' > pod.yaml vi pod.yaml ``` @@ -255,7 +255,7 @@ There are lots of different types per cloud provider (see here)[https://kubernet```bash -kubectl run busybox --image=busybox -- sleep 3600 +kubectl run busybox --image=busybox --restart=Never -- sleep 3600 kubectl cp busybox:etc/passwd ./passwd # kubectl cp command # previous command might report an error, feel free to ignore it since copy command works cat passwd