kubernetes: hairpin not set by kubelet with CNI plugin

Is this a request for help? (If yes, you should use our troubleshooting guide and community support channels, see http://kubernetes.io/docs/troubleshooting/.): No

What keywords did you search in Kubernetes issues before filing this one? (If you have found any duplicates, you should instead reply there.): kube-proxy clusterIP target hang


Is this a BUG REPORT or FEATURE REQUEST? (choose one):

BUG REPORT

Kubernetes version (use kubectl version): 1.6.2

Environment:

  • Cloud provider or hardware configuration: AWS
  • OS (e.g. from /etc/os-release): coreos-1235.6.0
  • Kernel (e.g. uname -a): 4.7.3-coreos-r2
  • Install tools: cloudinit direct install
  • Others:

What happened:

Try creating a service with a cluster IP. Then try accessing the service IP and port from within a target pod. It hangs. As far as I can tell, SYN but that is it.

Note that the same is true if you use type: NodePort and access the node IP and port.

What you expected to happen:

Should be able to access the service from any pod, whether one of the targets or a different one.

How to reproduce it (as minimally and precisely as possible):

Use the following simple service and deployment:

apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    name: nginx
spec:
  type: NodePort
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: http
    nodePort: 30100
  selector:
    instance: nginx
---
kind: Deployment
apiVersion: apps/v1beta1
metadata:
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      instance: nginx
  template:
    metadata:
      labels:
        name: nginx
        instance: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        ports:
        - containerPort: 80
          name: http

Working pod:

exec into any pod other than the one created as part of the deployment:

  1. curl <nginx_podIP>:80: works
  2. curl <nginx_serviceIP>:80: works

Failing pod

exec into the pod created by the above deployment:

  1. curl <nginx_podIP>:80: works
  2. curl localhost:80: works
  3. curl <nginx_serviceIP>:80: FAILS

Anything else we need to know:

It doesn’t matter if you use the same port for the service as for the pod or a different one, same name or different name, etc.

I suspect iptables weirdness, but…

Running 1.6.2 with weave networking. I was concerned it might be lack of --cluster-cidr on the kube-proxy, but that makes no difference.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 48 (46 by maintainers)

Commits related to this issue

Most upvoted comments

@deitch 1 - 4 sound accurate to me, but somebody should double-check 2 because that was only my vague recollection of what hairpin was meant to solve, and I forget if that is accurate or not. But other than that, yes.

Saying that some network plugins support “a pod can connect to itself via a service IP” and some plugins don’t is ugly

True. But do we want to make it too restrictive? Would we not want a more open approach that says, “you must support this or indicate clearly that you do not”?

In that case, you can release a network that does not support it, and let users decide if the trade-offs for a particular CNI plugin are worth it.

documentation for plugin writers (does such a thing exist?)

My searches say no, not yet.

ensure authors for common plugins are aware of this

In my view this change should have gone into the release notes (i.e. “stopped setting hairpin mode for non-kubenet veths”)

the promisc-bridge gunk

LOL! I must start to use “gunk” as the technical term in my conference presentations. I could have had fun with an image for that. Some bridge, with lots of “workers” on it, and a sludge delivery truck that overturned: “promiscuous bridge gunk.” 😃

I know some plugins use veth without a bridge (Calico) - how does hairpin work there?

There’s no special configuration required when using a veth without a bridge (e.g. calico, p2p). Traffic hits the kube-proxy’s Service DNAT rule, and is routed back to the Pod IP, and then gets masqueraded.

@thockin hairpin is a setting on Linux bridge ports (at least as we implement it in Kube) so without a Linux bridge, you don’t get hairpin. The network plugin could certainly figure out how to emulate hairpin without a bridge though.

But it just seems like something we need to specify at a higher level, eg “When multiple containers are run in the same pod, the Network Plugin must allow containers in the pod to access other containers in the pod using the service address” or whatever the core reason hairpin was added was. Leave it up to the network plugin to figure out how to do that.

I think the abstract “allows hairpin behavior” is a property of plugins. Some support it. Some do not. Some may support it in multiple ways with configuration required. If you don’t support it in a Kubernetes install, one class of Service behavior will not work correctly. That may be OK for some installations and not for others.

For plugins which use Linux bridges, we have ample evidence that literal hairpin mode (the Linux kernel feature) causes kernel hangs. There are alternatives (from don’t allow hairpin at all to setting the bridge in promisc mode, maybe others) that plugins must decide for themselves to support or not.

Kubelet really should not, must not, assume anything about the network. This is why kubenet has been modularized and encapsulated over the last couple releases - so we can excise it entirely. To get 100% compat, we probably should squeeze the promisc-bridge gunk (and all of the ebtables mess) into the bridge driver.

I know some plugins use veth without a bridge (Calico) - how does hairpin work there?

On Thu, May 18, 2017 at 8:45 AM, Avi Deitcher notifications@github.com wrote:

@dcbw https://github.com/dcbw I agree it should be a plugin setting e.g. some network types may not need it. Others may implement it in a way that does or does not affect kernels.

However because it always did live as a kubelet setting, imho there are two sides to this

  1. users may have come to expect it to be in kubelet. Changing it requires really making sure cluster admins know they need to control it at the network plugin layer. In other words, changelogs and docs.
  2. it’s kind of rough to hand off ownership to the plugin owners without them knowing to pick it up. I’m the first to notice and report it, I’m positive I won’t be the last. 😃

In the end, I think you do satisfy everyone by saying that a- your network plugin decides whether to support hairpin or not and how, and decides how to configure that setting, b- docs and transitions for existing.

On that front, at least weave already has an incomplete PR to configure it! 😃

— You are receiving this because you are on a team that was mentioned. Reply to this email directly, view it on GitHub https://github.com/kubernetes/kubernetes/issues/45790#issuecomment-302445220, or mute the thread https://github.com/notifications/unsubscribe-auth/AFVgVM44GZaKSM2N6U_5C7Eg3tRHrGuOks5r7Gd8gaJpZM4NaaUH .

@bboreham it might be more consistent, but it really does live in the network plugins IMHO and I don’t really think Kube should have anything to do with it. Ideally 😃

I tried disabling CRI on kubelet and that brought the hairpin-veth mode back.

Looking at the code, I see hairpin.SetUpContainerPid called in dockertools/docker_manager.go, but no similar call in dockershim/docker_service.go. So I conclude that the CRI code just doesn’t have this functionality.