<p>I have a macbook (<code>192.168.1.101</code>) and a macmini(<code>192.168.1.104</code>) over same wifi.</p>

<p>I launched a k8s cluster through docker-desktop on macmini and would like to access it through <code>kubectl</code> on macbook.</p>

<p>Here is how my <code>~/.kube/config</code> on macmini looks like:</p>

<pre><code>apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: ******
    server: https://kubernetes.docker.internal:6443
  name: docker-desktop
contexts:
- context:
    cluster: docker-desktop
    user: docker-desktop
  name: docker-desktop
- context:
    cluster: docker-desktop
    user: docker-desktop
  name: docker-for-desktop
current-context: docker-desktop
kind: Config
preferences: {}
users:
- name: docker-desktop
  user:
    client-certificate-data: ******
    client-key-data: ******
</code></pre>

<p>How can I write <code>~/.kube/config</code> on macbook? Currently I followed official <a href="https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/" rel="noreferrer">doc</a> and got following errors.</p>

<pre><code>$ kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: http://192.168.1.104:6443
  name: macmini-cluster
contexts:
- context:
    cluster: macmini-cluster
    user: macmini-user
  name: macmini-context
current-context: macmini-context
kind: Config
preferences: {}
users:
- name: macmini-user
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
$ kubectl get pods
The connection to the server 192.168.1.104 was refused - did you specify the right host or port?
</code></pre>

<p><strong>Update</strong>:</p>

<p>I added port <code>6443</code> to <code>server</code> of <code>cluster</code> and tried to <code>telnet</code> macmini's port <code>6443</code>, but got:</p>

<pre><code>$ telnet 192.168.1.104 6443
Trying 192.168.1.104...
telnet: connect to address 192.168.1.104: Connection refused
telnet: Unable to connect to remote host
</code></pre>

<p>When I checked on macmini:</p>

<pre><code>$ netstat -na|grep 6443
tcp4       0      0  127.0.0.1.6443         *.*                    LISTEN
</code></pre>

<p>There seems to be an unresolved related <a href="https://github.com/docker/for-mac/issues/3730" rel="noreferrer">issue</a>.</p>

<p>It seems your kubernetes api server did not bind to a local network accessible ipv4 address, instead it is bound to host's loopback adapter at 127.0.0.1</p>
<pre><code>$ netstat -na|grep 6443
tcp4       0      0  127.0.0.1.6443         *.*                    LISTEN
</code></pre>
<p>Which means it can only be accessed by the machine running the process.</p>
<p>You need to proxy this port to your local ipv4 network. You can do this as below with command prompt running in kubernetes host computer as administrator:</p>
<pre><code>netsh interface portproxy add v4tov4 listenaddress=192.168.1.104 listenport=6443 connectaddress=127.0.0.1 connectport=6443
</code></pre>
