<p>I'm trying to understand why this particular <code>socat</code> command isn't working in my case where I run it in a IPv6 only Kubernetes cluster.</p>
<p>Cluster is build on top of AWS with Calico CNI &amp; containerd. Provisioned using <code>kubeadm</code> and Kubernetes 1.21.</p>
<p>I have run the following <code>socat</code> command which binds to loopback interface <code>::1</code>,</p>
<pre><code>kubectl --context=$CLUSTER1 run --image=alpine/socat socat -- tcp6-listen:15000,bind=\[::1\],fork,reuseaddr /dev/null
</code></pre>
<p>And then I try to <code>port-forward</code> and <code>curl</code> to <code>15000</code> port,</p>
<pre><code>kubectl --context=$CLUSTER1 port-forward pod/socat 35000:15000 --address=::1
curl -ivg http://localhost:35000
</code></pre>
<p>I get the error,</p>
<pre><code>Forwarding from [::1]:35000 -&gt; 15000
Handling connection for 35000
E0830 17:09:59.604799   79802 portforward.go:400] an error occurred forwarding 35000 -&gt; 15000: error forwarding port 15000 to pod a8ba619774234e73f4c1b4fe4ff47193af835cffc56cb6ad1a8f91e745ac74e9, uid : failed to execute portforward in network namespace &quot;/var/run/netns/cni-8bade2c1-28c9-6776-5326-f10d55fd0ff9&quot;: failed to dial 15000: dial tcp4 127.0.0.1:15000: connect: connection refused
</code></pre>
<p>Its listening to <code>15000</code> as,</p>
<pre><code>Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 ::1:15000               :::*                    LISTEN      1/socat
</code></pre>
<p>However if I run the following it works fine,</p>
<pre><code>kubectl --context=$CLUSTER1 run --image=alpine/socat socat -- tcp6-listen:15000,bind=\[::\],fork,reuseaddr /dev/null
</code></pre>
<p>Not sure I understand why <code>port-forward</code> would fail for the loopback interface binding <code>::1</code> but not for catch all <code>::</code>. Can someone please shed some light on this ?</p>

nixgadget
<p>For those of you running into a similar issue with your IPv6 only Kubernetes clusters heres what I have investigated found so far.</p>
<p><strong>Background:</strong> It seems that this is a generic issue relating to IPv6 and CRI.
I was running <code>containerd</code> in my setup and <code>containerd</code> versions <code>1.5.0</code>-<code>1.5.2</code> added two PRs (<a href="https://github.com/containerd/containerd/commit/11a78d9d0f1664466fa3fffebd8ff234f3ef2677" rel="nofollow noreferrer">don't use socat for port forwarding</a> and <a href="https://github.com/containerd/containerd/commit/305b42583073aa1435d15ff5773c049827fa8d51" rel="nofollow noreferrer">use happy-eyeballs for port-forwarding</a>) which fixed a number of issues in IPv6 port-forwarding.</p>
<p><strong>Potential fix:</strong> Further to pulling in <code>containerd</code> version <code>1.5.2</code> (as part of Ubuntu 20.04 LTS) I was also getting the error <code>IPv4: dial tcp4 127.0.0.1:15021: connect: connection refused IPv6 dial tcp6: address localhost: no suitable address found</code> when port-forwarding. This is caused by a DNS issue when resolving <code>localhost</code>. Hence I added <code>localhost</code> to resolve as <code>::1</code> in the host machine with the following command.</p>
<pre><code>sed -i 's/::1 ip6-localhost ip6-loopback/::1 localhost ip6-localhost ip6-loopback/' /etc/hosts
</code></pre>
<p>I think the important point here is that check your container runtimes to make sure IPv6 (tcp6 binding) is supported.</p>
