-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Open
Description
Hi,
I was looking today on https://github.com/dgkanatsios/CKAD-exercises/blob/master/f.services.md - and I think I noticed an issue there:
in question:
Get service's ClusterIP, create a temp busybox pod and 'hit' that IP with wget
Second solution is given as:
IP=$(kubectl get svc nginx --template={{.spec.clusterIP}}) # get the IP (something like 10.108.93.130)
kubectl run busybox --rm --image=busybox -it --restart=Never --env="IP=$IP" -- wget -O- $IP:80 --timeout 2
It works only by coincident as we use the same environment variable 'IP' in host system and inside of pod, because if we change name of variable containing ip address - it fails:
IP=$(kubectl get svc nginx --template={{.spec.clusterIP}})
kubectl run busybox --rm --image=busybox -it --restart=Never --env="HA=$IP" -- wget -O- $HA:80 --timeout 2
If you don't see a command prompt, try pressing enter.
Error attaching, falling back to logs: unable to upgrade connection: container busybox not found in pod busybox_default
wget: bad address ':80'
pod "busybox" deleted
pod default/busybox terminated (Error)
so, either we skip --env part:
IP=$(kubectl get svc nginx --template={{.spec.clusterIP}}) # get the IP (something like 10.108.93.130)
kubectl run busybox --rm --image=busybox -it --restart=Never -- wget -O- $IP:80 --timeout 2
or we use again first solution but with --env variable:
IP=$(kubectl get svc nginx --template={{.spec.clusterIP}})
kubectl run busybox --rm --image=busybox -it --restart=Never --env=HA=$IP -- sh
If you don't see a command prompt, try pressing enter.
/ # wget -O- $HA:80
Connecting to 10.152.183.190:80 (10.152.183.190:80)
writing to stdout
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
- 100% |***********************************************| 615 0:00:00 ETA
written to stdout
/ # exit
pod "busybox" deleted
Thank you for verification.
Regards,
Lukasz
Metadata
Metadata
Assignees
Labels
No labels