WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Missing `xt_recent` kernel module resulting in inability to run Kubernetes with Session Affinity

Open valeneiko opened this issue 5 years ago • 18 comments

Windows Build Number

Microsoft Windows [Version 10.0.19042.1055]

WSL Version

  • [X] WSL 2
  • [ ] WSL 1

Kernel Version

No response

Distro Version

Ubuntu 20.04

Other Software

Kind, v0.11.1 Kubernetes, v1.20.7 Docker Desktop (Windows), version 3.4.0

Repro Steps

  1. Install Docker Desktop (link)
  2. Get Kind (link)
    go get sigs.k8s.io/[email protected]
    
  3. Create a Kubernetes cluster
    kind create cluster
    
  4. Create a Service in Kubernetes with sessionAffinity: ClientIP (kubectl apply -f service.yaml).
    # service.yaml
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: session-affinity-test
    spec:
      selector:
        matchLabels:
          app: session-affinity-test
      template:
        metadata:
          labels:
            app: session-affinity-test
        spec:
          containers:
          - name: session-affinity-test
            image: mendhak/http-https-echo
            resources:
              limits:
                memory: "128Mi"
                cpu: "500m"
            ports:
            - containerPort: 8080
              name: web
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: session-affinity-service
      namespace: default
    spec:
      ports:
      - name: web
        port: 9093
        targetPort: web
      selector:
        app: session-affinity-test
      sessionAffinity: ClientIP    
    
  5. Try to access the service, or view Kube Proxy logs

Expected Behavior

Kube Proxy should have successfully applied iptables rules and Kubernetes service is accessible.

Some discussion about this issue: https://github.com/kubernetes-sigs/kind/issues/1740.

Yes, it looks like the current WSL2 Kernel is built without xt_recent, needed by iptables -m recent ... which kube-proxy uses to implement sessionAffinity: ClientIP. Custom Kernel built with CONFIG_NETFILTER_XT_MATCH_RECENT=y fixed it for me. Submitted https://github.com/microsoft/WSL2-Linux-Kernel/pull/198 (4.19.y) and https://github.com/microsoft/WSL2-Linux-Kernel/pull/199 (5.4.y)

Actual Behavior

Service is inaccessible and any other service created afterwards is inaccessible. Which is caused by inability to apply iptables rules.

The following log is present in Kube Proxy:

E0720 14:29:10.934607       1 proxier.go:1507] Failed to execute iptables-restore: exit status 2 (iptables-restore v1.8.3 (legacy): Couldn't load match `recent':No such file or directory

Error occurred at line: 96
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
)
I0720 14:29:10.934636       1 proxier.go:779] Sync failed; retrying in 30s

Diagnostic Logs

No response

valeneiko avatar Jun 27 '21 18:06 valeneiko

I've updated my link in the issue mentioned. I had a PR but MS decided that despite kernel being OSS, they won't accept outside contributions.

WSLUser avatar Jun 28 '21 19:06 WSLUser

=m on native

image

therealkenc avatar Jun 28 '21 19:06 therealkenc

@craigloewen-msft Any news on this? It's been half a year. PRs that addressed this issue were opened over at microsoft/WSL2-Linux-Kernel and closed without a good reason.

jasper-d avatar Dec 19 '21 16:12 jasper-d

Any news on this? Having to recompile the WSL2 kernel to have a good working environment for k8s is annoying and consumes a good amount of time unless you have a powerful machine. It would be great to include this in the default build.

douglascamata avatar Apr 19 '22 09:04 douglascamata

MS team - without this fix there's a whole class of WSL2 use-cases (developer local K8s on WSL2) that are invalidated. Please add this feature in an upcoming build - WSL2 has great potential as a development environment, but needs to be able to run local K8s without issue.

damarshall avatar May 25 '22 20:05 damarshall

This should be fixed as soon as possible.

@craigloewen-msft any news?

ghost avatar Jun 14 '22 17:06 ghost

I would also like to get this fixed instead of having to build own version of the kernel.

lk-1984 avatar Jun 15 '22 05:06 lk-1984

Vote! xt_recent kernel module can help all the developer who doing some work on K8s in WSL2

8ar10der avatar Jun 24 '22 03:06 8ar10der

this issue has caused me nightmares since the whole cluster wasnt able to communicate anymore just because one container has sessionAffinity: ClientIp set.

Rainson12 avatar Oct 27 '22 12:10 Rainson12

@jiayali-ms you closed both PRs to the kernel trying to implement this fix (https://github.com/microsoft/WSL2-Linux-Kernel/pull/199 and https://github.com/microsoft/WSL2-Linux-Kernel/pull/198). On your closing comment, you said:

While we understand that it is frustrating to have a PR closed, it is never our intention to ignore feedback or stifle community discussions. We are taking this opportunity to increase transparency on how we work with the WSL community and ensure all members are routed to the appropriate resources.

If you would like contribute to, discuss, or report an issue relating to WSL, or the WSL 2 Linux kernel configuration, please do so at the WSL GitHub. The team is actively monitoring and responding to user feedback there: https://github.com/microsoft/WSL.

We are here, reporting the issue that causes so many k8s environments to be broken in WSL 2 and yet we didn't hear anything back.

So, what's up? Is this going to be fixed?

Recompiling the WSL 2 kernel only for this reason is an awful solution.

douglascamata avatar Nov 28 '22 17:11 douglascamata

@therealkenc do you happen to know anything about this issue?

douglascamata avatar Nov 28 '22 17:11 douglascamata

@therealkenc do you happen to know anything about this issue?

Oh, men, I am trying to provision an RKE2 worker node using Calico on Win11 WSL2 with a bridged network. And the kube-proxy pod suffers from this no xt_recent iptables failure. I am already using a custom kernel (built using native Ubuntu 22.04 and a modified ms kconfig) with many xt options enabled to support wireguard. I wonder why MS is so hostile to the Linux net stack... All they are trying to do is to limit the role of wsl a client behind NAT... besides, I still have several machines not compatible with win11, and need to figure out how to overcome the hyper-v switch nat mode...

alex-guo-github avatar Nov 29 '22 18:11 alex-guo-github

@alex-guo-github not sure whether it will help you, but for Cilium I had to add CONFIG_NETFILTER_XT_TARGET_CT=y and CONFIG_NETFILTER_XT_TARGET_TPROXY=y too.

douglascamata avatar Nov 29 '22 18:11 douglascamata

Don't know if anyone needs this but I created a little helm snippet to detect if the node is docker-desktop running in wsl2 so I could just not set session affinity and/or throw an error if any multiple replicas scenarios were applied on wsl2.

{{- $isWSL2 := false }} {{ $nodes := (lookup "v1" "Node" "" "" ) }} {{ if $nodes }} {{ range $index, $node := $nodes.items }} {{ if $node }} {{ if $node.status }} {{ if $node.status.nodeInfo }} {{ if $node.status.nodeInfo.kernelVersion }} {{ if ( hasSuffix "WSL2" $node.status.nodeInfo.kernelVersion ) }} {{- $isWSL2 = true }} {{ end }} {{ end }} {{ end }} {{ end }} {{ end }} {{ end }} {{ end }}

davidgemel avatar Dec 09 '22 16:12 davidgemel

Also voting here for incl xt_recent - recompiling linux kernels is fine but looks like folks already tried to introduce solution pr's - seemingly without unwanted side-effects!

razlani avatar Dec 18 '22 23:12 razlani

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!

this is still an issue

benzman81 avatar Feb 15 '24 07:02 benzman81

For future reference:

The following doc article about running Kind on WSL2 explains how to build your kernel to support session affinity: https://kind.sigs.k8s.io/docs/user/using-wsl2/#kubernetes-service-with-session-affinity

mostafa avatar Feb 27 '24 15:02 mostafa