Skip to content
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

[Release 1.21] Allow svclb pod to enable ipv6 forwarding #4519

Merged
merged 1 commit into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
nodeConfig.AgentConfig.Rootless = envInfo.Rootless
nodeConfig.AgentConfig.PodManifests = filepath.Join(envInfo.DataDir, "agent", DefaultPodManifestPath)
nodeConfig.AgentConfig.ProtectKernelDefaults = envInfo.ProtectKernelDefaults
nodeConfig.AgentConfig.DisableServiceLB = envInfo.DisableServiceLB

if err := validateNetworkConfig(nodeConfig); err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions pkg/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
return errors.Wrap(err, "failed to validate kube-proxy conntrack configuration")
}
syssetup.Configure(enableIPv6, conntrackConfig)
nodeConfig.AgentConfig.EnableIPv6 = enableIPv6

if err := setupCriCtlConfig(cfg, nodeConfig); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/cmds/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Agent struct {
ServerURL string
APIAddressCh chan string
DisableLoadBalancer bool
DisableServiceLB bool
ETCDAgent bool
LBServerPort int
ResolvConf string
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
agentConfig.ServerURL = url
agentConfig.Token = token
agentConfig.DisableLoadBalancer = !serverConfig.ControlConfig.DisableAPIServer
agentConfig.DisableServiceLB = serverConfig.DisableServiceLB
agentConfig.ETCDAgent = serverConfig.ControlConfig.DisableAPIServer
agentConfig.ClusterReset = serverConfig.ControlConfig.ClusterReset

Expand Down
4 changes: 4 additions & 0 deletions pkg/daemons/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ func startKubelet(cfg *config.Agent) error {
argsMap["protect-kernel-defaults"] = "true"
}

if !cfg.DisableServiceLB && cfg.EnableIPv6 {
argsMap["allowed-unsafe-sysctls"] = "net.ipv6.conf.all.forwarding"
}

args := config.GetArgsList(argsMap, cfg.ExtraKubeletArgs)
logrus.Infof("Running kubelet %s", config.ArgString(args))

Expand Down
3 changes: 3 additions & 0 deletions pkg/daemons/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ type Agent struct {
DisableKubeProxy bool
Rootless bool
ProtectKernelDefaults bool
DisableServiceLB bool
EnableIPv6 bool
}

type Control struct {
Expand All @@ -122,6 +124,7 @@ type Control struct {
ClusterDNS net.IP
ClusterDNSs []net.IP
ClusterDomain string
DisableServiceLB bool
NoCoreDNS bool
KubeConfigOutput string
KubeConfigMode string
Expand Down
21 changes: 21 additions & 0 deletions pkg/servicelb/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ func (h *handler) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) {
name := fmt.Sprintf("svclb-%s", svc.Name)
oneInt := intstr.FromInt(1)

// If ipv6 is present, we must enable ipv6 forwarding in the manifest
var ipv6Switch bool
for _, ipFamily := range svc.Spec.IPFamilies {
if ipFamily == core.IPv6Protocol {
ipv6Switch = true
}
}

ds := &apps.DaemonSet{
ObjectMeta: meta.ObjectMeta{
Name: name,
Expand Down Expand Up @@ -394,6 +402,19 @@ func (h *handler) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) {
},
}

if ipv6Switch {
// Add security context to enable ipv6 forwarding
securityContext := &core.PodSecurityContext{
Sysctls: []core.Sysctl{
{
Name: "net.ipv6.conf.all.forwarding",
Value: "1",
},
},
}
ds.Spec.Template.Spec.SecurityContext = securityContext
}

for _, port := range svc.Spec.Ports {
portName := fmt.Sprintf("lb-port-%d", port.Port)
container := core.Container{
Expand Down