Skip to content

Commit

Permalink
Added back required restart=Never for busybox only
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenJDH committed Feb 18, 2021
1 parent 57f19cf commit eff61d2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
16 changes: 8 additions & 8 deletions a.core_concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ kubectl run nginx --image=nginx --dry-run=client -o yaml | kubectl create -n myn
<p>

```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
```
Expand All @@ -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
```
Expand Down Expand Up @@ -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}')
```

</p>
Expand Down Expand Up @@ -318,9 +318,9 @@ kubectl exec -it nginx -- /bin/sh
<p>

```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'
```

</p>
Expand All @@ -332,7 +332,7 @@ kubectl run busybox --image=busybox -it -- /bin/sh -c 'echo hello world'
<p>

```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 :)
```

Expand Down
4 changes: 2 additions & 2 deletions b.multi_container_pods.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions e.observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ kubectl delete -f pod.yaml
<p>

```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
```

Expand All @@ -157,7 +157,7 @@ kubectl logs busybox -f # follow the logs
<p>

```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
Expand All @@ -173,7 +173,7 @@ kubectl delete po busybox
<p>

```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...
Expand Down
12 changes: 6 additions & 6 deletions f.services.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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)
```

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
```

</p>
Expand Down
6 changes: 3 additions & 3 deletions g.state.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
```

Expand Down Expand Up @@ -255,7 +255,7 @@ There are lots of different types per cloud provider (see here)[https://kubernet
<p>

```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
Expand Down

0 comments on commit eff61d2

Please sign in to comment.