-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/k3s: add nftables to Path of k3s service #360796
Conversation
Please, to follow up with nixpkgs guidelines, properly scope the NixOS module name and rename title of this PR and commits. Such as:
(Note: It is in lowercase.) |
Eval summary
|
@superherointj happy with that one? |
Yes. |
pls dont merge now, i'm testing it. |
Just undraft when ready. |
After searched kube-proxy code, i found the
otherwise, the Do you think it's acceptable? Or just still use the |
Since that is required, Unfortunately iptables/nftables switch adds another testing dimension. As this is extra work, I'm not requesting you to do that. Just adding the extra |
All git commits should have a scoped title (like, |
i know, but i prefer to format commit message via squash merging |
@@ -498,7 +525,7 @@ in | |||
"network-online.target" | |||
]; | |||
wantedBy = [ "multi-user.target" ]; | |||
path = lib.optional config.boot.zfs.enabled config.boot.zfs.package; | |||
path = [ pkgs.nftables ] ++ lib.optional config.boot.zfs.enabled config.boot.zfs.package; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other packages that k3s needs are wrapped with the binaries. We should add nftables
also there to be consistent with other dependencies.
See
k3sRuntimeDeps = [ |
default = { | ||
clientConnection = { | ||
kubeconfig = "/etc/rancher/k3s/k3s.yaml"; | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether I get your comments right, but I think this is a wrong default. K3s actually doesn't use this kubeconfig for kube-proxy. By default it passes kube-proxy the argument --kubeconfig=/var/lib/rancher/k3s/agent/kubeproxy.kubeconfig
, which is another file. I suggest to make the default {}
, so that the --kube-proxy-arg=config=...
gets only passed if a user explicitly changes this option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k3s will pass kubeconfig
to kube-proxy in https://github.com/k3s-io/k3s/blob/4ec261733e241e2baf77684ad5d87ff071d0f00a/pkg/daemons/agent/agent_linux.go#L43 via command line arg --kube-config
, then kube-proxy will save this arg to o.config.ClientConnection.Kubeconfig
in https://github.com/kubernetes/kubernetes/blob/master/cmd/kube-proxy/app/options.go#L106 . However, the o.config
object will be override in https://github.com/kubernetes/kubernetes/blob/master/cmd/kube-proxy/app/options.go#L221 by the kubeProxyConfigurataion object which specified via the config=path
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can firstly run k3s with this pr to observe behaviors with different args.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k3s will pass kubeconfig to kube-proxy in https://github.com/k3s-io/k3s/blob/4ec261733e241e2baf77684ad5d87ff071d0f00a/pkg/daemons/agent/agent_linux.go#L43 via command line arg --kube-config
I agree, but notice that the variable used here is cfg.KubeConfigKubeProxy
, which gets constructed here . K3s generates multiple kubeconfigs with different certificates for different components, e.g. kubelet, kubeconfig, k3s-controller, etc. I don't know the internals but we shouldn't change which kubeconfig is used without good reason. The default kubeconfig for kube-proxy is at /var/lib/rancher/k3s/agent/kubeproxy.kubeconfig
and not the admin kubeconfig at /etc/rancher/k3s/k3s.yaml
.
You can see which args are passed to kube-proxy with journalctl -u k3s | grep kube-proxy
, on the current master without this PR and default settings I see:
k3s[778]: time="2024-12-08T14:05:20Z" level=info msg="Running kube-proxy --cluster-cidr=10.42.0.0/16 --conntrack-max-per-core=0 --conntrack-tcp-timeout-close-wait=0s --conntrack-tcp-timeout-established=0s --healthz-bind-address=127.0.0.1 --hostname-override=foo --kubeconfig=/var/lib/rancher/k3s/agent/kubeproxy.kubeconfig --proxy-mode=iptables"
The actual default for extraKubeProxyConfig
would change the kubeconfig that kube-proxy uses. Of course we could change the default, but this would lead to other problems, for example if k3s changes its defaults or the k3s data dir is changed. I think it would be best to not generate a config for kube-proxy by default, so that k3s can decide which kubeconfig it passes to kube-proxy. However, if somebody configures a custom extraKubeProxyConfig
, he has to take care of setting clientConnection.kubeconfig
as mentioned in the option description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual default for
extraKubeProxyConfig
would change the kubeconfig that kube-proxy uses. Of course we could change the default, but this would lead to other problems, for example if k3s changes its defaults or the k3s data dir is changed. I think it would be best to not generate a config for kube-proxy by default, so that k3s can decide which kubeconfig it passes to kube-proxy. However, if somebody configures a customextraKubeProxyConfig
, he has to take care of settingclientConnection.kubeconfig
as mentioned in the option description.
I agree that.
Thanks a lot for this! I can't resolve my own comments but they are resolved. From my side this is ready to go once you squashed the commits. |
Looks great! Thanks for this. |
kubernetes 1.31 has nftables support, and k3s now support kubernetes 1.31, so it needs nftables binary
nft
.Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.