Outbound internet does not work with CNI plugin
To repro:
- deploy a cluster with CNI
- kubectl exec to the container, and try to access the internet from a container
@ofiliz can you take a look?
I propose that we revise the issue title: "Kubernetes pods do not have outbound internet access with CNI plugin in l2tunnel mode".
Azure-vnet CNI/CNM plugins in regular IaaS VMs can be given outgoing access to internet with a simple NAT rule:
iptables -t nat -A POSTROUTING -m iprange ! --dst-range 168.63.129.16 -m addrtype ! --dst-type local ! -d {{{vnetCidr}}} -j MASQUERADE
The problem is this rule doesn't work in Kubernetes clusters with azure-vnet CNI plugin due to what seems to be a bug in the Linux kernel. Connections get established (SYN+ACK handshake succeeds), but port translation later fails. We are adding this capability directly to Azure SDN stack, instead of SNAT'ing in the VM and relying on Linux kernel.
Discussed further with @seanknox and it is better to remove the examples until this can be fixed, otherwise customers will keep hitting this error.
Verified this is no longer an issue. On a cluster with azure CNI enabled:
$ ps auxfww | grep '/etc/cni/'
azureus+ 19583 0.0 0.0 12948 936 pts/0 S+ 00:06 0:00 \_ grep --color=auto /etc/cni/
root 6778 0.0 0.2 161524 17400 ? Ssl Nov21 0:00 /usr/bin/docker run --net=host --pid=host --privileged --rm --volume=/dev:/dev --volume=/sys:/sys:ro --volume=/var/run:/var/run:rw --volume=/var/lib/docker/:/var/lib/docker:rw --volume=/var/lib/kubelet/:/var/lib/kubelet:shared --volume=/var/log:/var/log:rw --volume=/etc/kubernetes/:/etc/kubernetes:ro --volume=/srv/kubernetes/:/srv/kubernetes:ro --volume=/etc/cni/:/etc/cni:ro --volume=/opt/cni/:/opt/cni:ro --volume=/var/lib/waagent/ManagedIdentity-Settings:/var/lib/waagent/ManagedIdentity-Settings:ro gcrio.azureedge.net/google_containers/hyperkube-amd64:v1.7.9 /hyperkube kubelet --kubeconfig=/var/lib/kubelet/kubeconfig --require-kubeconfig --pod-infra-container-image=gcrio.azureedge.net/google_containers/pause-amd64:3.0 --address=0.0.0.0 --allow-privileged=true --enable-server --pod-manifest-path=/etc/kubernetes/manifests --cluster-dns=10.0.0.10 --cluster-domain=cluster.local --node-labels=kubernetes.io/role=master,kubernetes.azure.com/cluster=francis-1dot6 --cloud-provider=azure --cloud-config=/etc/kubernetes/azure.json --azure-container-registry-config=/etc/kubernetes/azure.json --network-plugin=cni --max-pods=30 --node-status-update-frequency=10s --image-gc-high-threshold=85 --image-gc-low-threshold=80 --v=2 --non-masquerade-cidr=10.0.0.0/8 --register-node=true --register-with-taints=node-role.kubernetes.io/master=true:NoSchedule
Was able to create a container, apt-get install curl, and curl to the internet:
$ kubectl exec -it shell-demo -- /bin/bash
root@shell-demo:/# curl google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
Awesome! Do you know what changed? Newer CNI image?
@seanknox I suspect it was the addition of a masquerade rule in iptables. See here for an example:
https://github.com/Azure/acs-engine/blob/master/parts/kubernetesmastercustomdata.yml#L283
@jackfrancis @seanknox Yes, it was fixed with the IPTables rule. Internet access should be working.