azure-cli: aks browse fails in azure-cli Docker container on Mac

Describe the bug I set up a cluster in AKS and executed the commands required to browse to it and they work from my machine. But when I execute them in an Azure CLI Docker container, it hangs and eventually exits with an error.

To Reproduce Steps to reproduce the behavior.

  1. Create a K8S cluster
  2. Launch an Azure CLI container: docker run -it -p 8001:8001 microsoft/azure-cli:latest
  3. az login
  4. az aks install-cli
  5. az aks get-credentials --resource-group my-resource-group --name my-k8s-name
  6. az aks browse --resource-group my-resource-group --name my-k8s-name --disable-browser
  7. Navigate to http://{container-ip}:8001

Expected behavior See the Kubernetes dashboard

Environment summary

  • MacOS Mojave (10.14)
  • CLI version 2.0.49 (in the Docker container)
  • Shell: zsh

Additional context

This is what appears eventually after running the aks browse command. It also appears when you cancel the running aks browse command:

HTTPConnectionPool(host=‘localhost’, port=8888): Max retries exceeded with url: /closeport/8001 (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x7fa8bae70860>: Failed to establish a new connection: [Errno 111] Connection refused’,)) Traceback (most recent call last): File “/usr/local/lib/python3.6/site-packages/urllib3/connection.py”, line 159, in _new_conn (self._dns_host, self.port), self.timeout, **extra_kw) File “/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py”, line 80, in create_connection raise err File “/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py”, line 70, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File “/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 600, in urlopen chunked=chunked) File “/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 354, in _make_request conn.request(method, url, **httplib_request_kw) File “/usr/local/lib/python3.6/http/client.py”, line 1239, in request self._send_request(method, url, body, headers, encode_chunked) File “/usr/local/lib/python3.6/http/client.py”, line 1285, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File “/usr/local/lib/python3.6/http/client.py”, line 1234, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File “/usr/local/lib/python3.6/http/client.py”, line 1026, in _send_output self.send(msg) File “/usr/local/lib/python3.6/http/client.py”, line 964, in send self.connect() File “/usr/local/lib/python3.6/site-packages/urllib3/connection.py”, line 181, in connect conn = self._new_conn() File “/usr/local/lib/python3.6/site-packages/urllib3/connection.py”, line 168, in _new_conn self, “Failed to establish a new connection: %s” % e) urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fa8bae70860>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File “/usr/local/lib/python3.6/site-packages/requests/adapters.py”, line 449, in send timeout=timeout File “/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 638, in urlopen _stacktrace=sys.exc_info()[2]) File “/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py”, line 398, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host=‘localhost’, port=8888): Max retries exceeded with url: /closeport/8001 (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x7fa8bae70860>: Failed to establish a new connection: [Errno 111] Connection refused’,))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File “/usr/local/lib/python3.6/site-packages/knack/cli.py”, line 197, in invoke cmd_result = self.invocation.execute(args) File “/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/init.py”, line 372, in execute six.reraise(*sys.exc_info()) File “/usr/local/lib/python3.6/site-packages/six.py”, line 693, in reraise raise value File “/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/init.py”, line 346, in execute result = cmd(params) File “/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/init.py”, line 182, in call return self.handler(*args, **kwargs) File “/usr/local/lib/python3.6/site-packages/azure/cli/core/init.py”, line 436, in default_command_handler result = op(**command_args) File “/usr/local/lib/python3.6/site-packages/azure/cli/command_modules/acs/custom.py”, line 1381, in aks_browse requests.post(‘http://localhost:8888/closeport/8001’) File “/usr/local/lib/python3.6/site-packages/requests/api.py”, line 116, in post return request(‘post’, url, data=data, json=json, **kwargs) File “/usr/local/lib/python3.6/site-packages/requests/api.py”, line 60, in request return session.request(method=method, url=url, **kwargs) File “/usr/local/lib/python3.6/site-packages/requests/sessions.py”, line 524, in request resp = self.send(prep, **send_kwargs) File “/usr/local/lib/python3.6/site-packages/requests/sessions.py”, line 637, in send r = adapter.send(request, **kwargs) File “/usr/local/lib/python3.6/site-packages/requests/adapters.py”, line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host=‘localhost’, port=8888): Max retries exceeded with url: /closeport/8001 (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x7fa8bae70860>: Failed to establish a new connection: [Errno 111] Connection refused’,))

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (1 by maintainers)

Most upvoted comments

Can this issue be reopened?

I’ve tested the fix and it only seems to fix the problem partially.

When I run the fix, it no longer spits out the error, but simply exits the proxy.

You can test it as follows (tested this on a mac running 10.14.5):

  1. Run az aks browse --resource-group my-resource-group --name my-cluster-name

  2. The proxy will start and will open http://127.0.0.1:8001

  3. Wait a couple of minutes without doing anything and you’ll see that the az command silently exits…

Does this relate to? https://github.com/Azure/azure-cli/issues/7914

I managed to work around this by adding socat installation and exposing a port in my Dockerfile:

FROM microsoft/azure-cli:latest
...
RUN apk add --no-cache socat
EXPOSE 8888
...

When I run docker I specify:

docker run -it -p 8888:8888 MYIMAGE

Then I forward 8888 traffic to 9090 (apologies if this isn’t quite right terminology, I’m not a networks expert) and then run “az aks browse”.

socat TCP-LISTEN:8888,fork TCP:127.0.0.1:9090 &
az aks browse --resource-group RESOURCE --name NAME --listen-port 9090 --disable-browser

I can then access the Dashboard on my host via http://localhost:8888/