Open LukaszKosc opened 3 years ago
I also was having a problem with this question. The answer specifies using sh after the --. I was unable to get it to work with the sh command . I'd get this error. sh: can't open 'wget': No such file or directory
Running this worked for me: k run bboxtemp2 --image=busybox -it --restart=Never -- wget -O- epIP
where epIP is the IP address of the endpoint.
Also, since this is a temporary pod, the command should probably look like:
k run bboxtemp2 --image=busybox -it --rm --restart=Never -- wget -O- epIP
I had a simple fix, just don't run the wget
directly, but swap a new sh
to run it, and you can use single quote for the command with $
.
❯ kubectl run nginx --image=nginx --restart=Never --port=80 --expose
service/nginx created
pod/nginx created
❯ IP=$(kubectl get svc nginx --template={{.spec.clusterIP}})
❯ kubectl run busybox --rm --image=busybox -it --restart=Never --env="xxIP=$IP" -- sh -c 'wget -O- $xxIP:80 --timeout 2'
Connecting to 10.71.252.172:80 (10.71.252.172: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
pod "busybox" deleted
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:
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:
so, either we skip
--env
part:or we use again first solution but with
--env
variable:Thank you for verification.
Regards, Lukasz