Skip to content

Commit e21d5ce

Browse files
cheina97adamjensenbot
authored andcommitted
Added possibility to switch to iptables nf_tables
1 parent 94c73c0 commit e21d5ce

File tree

9 files changed

+46
-21
lines changed

9 files changed

+46
-21
lines changed

deployments/liqo/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
| metricAgent.pod.labels | object | `{}` | Labels for the metricAgent pod. |
9191
| metricAgent.pod.resources | object | `{"limits":{},"requests":{}}` | Resource requests and limits (https://kubernetes.io/docs/user-guide/compute-resources/) for the metricAgent pod. |
9292
| nameOverride | string | `""` | Override the standard name used by Helm and associated to Kubernetes/Liqo resources. |
93-
| networkConfig.mtu | int | `1340` | Set the MTU for the interfaces managed by liqo: vxlan, tunnel and veth interfaces. The value is used by the gateway and route operators. The default value is configured to ensure correct behavior regardless of the combination of the underlying environments (e.g., cloud providers). This guarantees improved compatibility at the cost of possible limited performance drops. |
9493
| networkManager.config.additionalPools | list | `[]` | Set of additional network pools to perform the automatic address mapping in Liqo. Network pools are used to map a cluster network into another one in order to prevent conflicts. Default set of network pools is: [10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12] |
9594
| networkManager.config.podCIDR | string | `""` | The subnet used by the pods in your cluster, in CIDR notation (e.g., 10.0.0.0/16). |
9695
| networkManager.config.reservedSubnets | list | `[]` | List of IP subnets that do not have to be used by Liqo. Liqo can perform automatic IP address remapping when a remote cluster is peering with you, e.g., in case IP address spaces (e.g., PodCIDR) overlaps. In order to prevent IP conflicting between locally used private subnets in your infrastructure and private subnets belonging to remote clusters you need tell liqo the subnets used in your cluster. E.g if your cluster nodes belong to the 192.168.2.0/24 subnet, then you should add that subnet to the reservedSubnets. PodCIDR and serviceCIDR used in the local cluster are automatically added to the reserved list. |
@@ -103,6 +102,9 @@
103102
| networkManager.pod.labels | object | `{}` | Labels for the networkManager pod. |
104103
| networkManager.pod.resources | object | `{"limits":{},"requests":{}}` | Resource requests and limits (https://kubernetes.io/docs/user-guide/compute-resources/) for the networkManager pod. |
105104
| networking.internal | bool | `true` | Use the default Liqo network manager. |
105+
| networking.iptables | object | `{"mode":"nf_tables"}` | Iptables configuration tuning. |
106+
| networking.iptables.mode | string | `"nf_tables"` | Select the iptables mode to use. Possible values are "legacy" and "nf_tables". |
107+
| networking.mtu | int | `1340` | Set the MTU for the interfaces managed by liqo: vxlan, tunnel and veth interfaces. The value is used by the gateway and route operators. The default value is configured to ensure correct behavior regardless of the combination of the underlying environments (e.g., cloud providers). This guarantees improved compatibility at the cost of possible limited performance drops. |
106108
| networking.reflectIPs | bool | `true` | Reflect pod IPs and EnpointSlices to the remote clusters. |
107109
| openshiftConfig.enable | bool | `false` | Enable/Disable the OpenShift support, enabling Openshift-specific resources, and setting the pod security contexts in a way that is compatible with Openshift. |
108110
| openshiftConfig.virtualKubeletSCCs | list | `["anyuid"]` | Security context configurations granted to the virtual kubelet in the local cluster. The configuration of one or more SCCs for the virtual kubelet is not strictly required, and privileges can be reduced in production environments. Still, the default configuration (i.e., anyuid) is suggested to prevent problems (i.e., the virtual kubelet fails to add the appropriate labels) when attempting to offload pods not managed by higher-level abstractions (e.g., Deployments), and not associated with a properly privileged service account. Indeed, "anyuid" is the SCC automatically associated with pods created by cluster administrators. Any pod granted a more privileged SCC and not linked to an adequately privileged service account will fail to be offloaded. |

deployments/liqo/templates/liqo-gateway-deployment.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ spec:
4646
args:
4747
- --run-as=liqo-gateway
4848
- --gateway.leader-elect=true
49-
- --gateway.mtu={{ .Values.networkConfig.mtu }}
49+
- --gateway.mtu={{ .Values.networking.mtu }}
5050
- --gateway.listening-port={{ .Values.gateway.config.listeningPort }}
5151
{{- if .Values.gateway.metrics.enabled }}
5252
- --metrics-bind-addr=:{{ .Values.gateway.metrics.port }}
@@ -72,6 +72,8 @@ spec:
7272
fieldPath: status.podIP
7373
- name: WIREGUARD_IMPLEMENTATION
7474
value: {{ .Values.gateway.config.wireguardImplementation }}
75+
- name: IPTABLES_MODE
76+
value: {{ .Values.networking.iptables.mode }}
7577
hostNetwork: true
7678
{{- if ((.Values.common).nodeSelector) }}
7779
nodeSelector:

deployments/liqo/templates/liqo-network-manager-deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ spec:
5858
valueFrom:
5959
fieldRef:
6060
fieldPath: metadata.namespace
61+
- name: IPTABLES_MODE
62+
value: {{ .Values.networking.iptables.mode }}
6163
resources: {{- toYaml .Values.networkManager.pod.resources | nindent 12 }}
6264
{{- if ((.Values.common).nodeSelector) }}
6365
nodeSelector:

deployments/liqo/templates/liqo-route-daemonset.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ spec:
4343
command: ["/usr/bin/liqonet"]
4444
args:
4545
- --run-as=liqo-route
46-
- --route.vxlan-mtu={{ .Values.networkConfig.mtu }}
46+
- --route.vxlan-mtu={{ .Values.networking.mtu }}
4747
{{- if .Values.route.pod.extraArgs }}
4848
{{- toYaml .Values.route.pod.extraArgs | nindent 10 }}
4949
{{- end }}
@@ -67,6 +67,8 @@ spec:
6767
valueFrom:
6868
fieldRef:
6969
fieldPath: spec.nodeName
70+
- name: IPTABLES_MODE
71+
value: {{ .Values.networking.iptables.mode }}
7072
volumeMounts:
7173
- mountPath: /run/xtables.lock
7274
name: xtables-lock

deployments/liqo/values.yaml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
tag: ""
77
# -- The pullPolicy for liqo pods.
88
pullPolicy: "IfNotPresent"
9+
10+
common:
11+
# -- NodeSelector for all liqo services, excluding virtual kubelet deployment.
12+
nodeSelector: {}
13+
# -- Tolerations for all liqo services, excluding virtual kubelet deployment.
14+
tolerations: []
15+
# -- Affinity for all liqo services, excluding virtual kubelet deployment.
16+
affinity: {}
17+
918
apiServer:
1019
# -- The address that must be used to contact your API server, it needs to be reachable from the clusters that you will peer with (defaults to your master IP).
1120
address: ""
@@ -17,6 +26,15 @@ networking:
1726
internal: true
1827
# -- Reflect pod IPs and EnpointSlices to the remote clusters.
1928
reflectIPs: true
29+
# -- Iptables configuration tuning.
30+
iptables:
31+
# -- Select the iptables mode to use. Possible values are "legacy" and "nf_tables".
32+
mode: "nf_tables"
33+
# -- Set the MTU for the interfaces managed by liqo: vxlan, tunnel and veth interfaces.
34+
# The value is used by the gateway and route operators.
35+
# The default value is configured to ensure correct behavior regardless of the combination of the underlying environments
36+
# (e.g., cloud providers). This guarantees improved compatibility at the cost of possible limited performance drops.
37+
mtu: 1340
2038

2139
reflection:
2240
skip:
@@ -465,18 +483,4 @@ openshiftConfig:
465483
virtualKubeletSCCs:
466484
- anyuid
467485

468-
# Configuration for liqo networking.
469-
networkConfig:
470-
# -- Set the MTU for the interfaces managed by liqo: vxlan, tunnel and veth interfaces.
471-
# The value is used by the gateway and route operators.
472-
# The default value is configured to ensure correct behavior regardless of the combination of the underlying environments
473-
# (e.g., cloud providers). This guarantees improved compatibility at the cost of possible limited performance drops.
474-
mtu: 1340
475486

476-
common:
477-
# -- NodeSelector for all liqo services, excluding virtual kubelet deployment.
478-
nodeSelector: {}
479-
# -- Tolerations for all liqo services, excluding virtual kubelet deployment.
480-
tolerations: []
481-
# -- Affinity for all liqo services, excluding virtual kubelet deployment.
482-
affinity: {}

docs/_legacy/pages/configuration/networking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ liqoctl install ${YOUR_PROVIDER} --cluster-name ${YOUR_CLUSTER_NAME} --mtu 1400
4747
The `liqoctl install` command is idempotent and can be executed multiple times to enforce the desired configuration.
4848
{{% /notice %}}
4949

50-
If you are installing Liqo using the provided helm chart than the MTU size can be configured by setting the `networkConfig.mtu` variable in the [values.yaml file](../../../installation/chart_values/#values).
50+
If you are installing Liqo using the provided helm chart than the MTU size can be configured by setting the `networking.mtu` variable in the [values.yaml file](../../../installation/chart_values/#values).
5151

5252

5353

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,6 @@ require (
264264
)
265265

266266
replace github.com/grandcat/zeroconf => github.com/liqotech/zeroconf v1.0.1-0.20201020081245-6384f3f21ffb
267+
268+
// Waitin for PR https://github.com/coreos/go-iptables/pull/110 to be merged
269+
replace github.com/coreos/go-iptables => github.com/cheina97/go-iptables v0.0.0-20230824102241-61fc692e7548

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj
204204
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
205205
github.com/chai2010/gettext-go v1.0.2 h1:1Lwwip6Q2QGsAdl/ZKPCwTe9fe0CjlUbqj5bFNSjIRk=
206206
github.com/chai2010/gettext-go v1.0.2/go.mod h1:y+wnP2cHYaVj19NZhYKAwEMH2CI1gNHeQQ+5AjwawxA=
207+
github.com/cheina97/go-iptables v0.0.0-20230824102241-61fc692e7548 h1:tsUrWiCxLp1cI8TB7qDmHNezZavWgxghH+m+pW+04wA=
208+
github.com/cheina97/go-iptables v0.0.0-20230824102241-61fc692e7548/go.mod h1:Qe8Bv2Xik5FyTXwgIbLAnv2sWSBmvWdFETJConOQ//Q=
207209
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
208210
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
209211
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
@@ -227,8 +229,6 @@ github.com/containernetworking/plugins v1.3.0 h1:QVNXMT6XloyMUoO2wUOqWTC1hWFV62Q
227229
github.com/containernetworking/plugins v1.3.0/go.mod h1:Pc2wcedTQQCVuROOOaLBPPxrEXqqXBFt3cZ+/yVg6l0=
228230
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
229231
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
230-
github.com/coreos/go-iptables v0.7.0 h1:XWM3V+MPRr5/q51NuWSgU0fqMad64Zyxs8ZUoMsamr8=
231-
github.com/coreos/go-iptables v0.7.0/go.mod h1:Qe8Bv2Xik5FyTXwgIbLAnv2sWSBmvWdFETJConOQ//Q=
232232
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
233233
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
234234
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=

pkg/liqonet/iptables/iptables.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package iptables
1717
import (
1818
"encoding/csv"
1919
"fmt"
20+
"os"
2021
"strings"
2122

2223
"github.com/coreos/go-iptables/iptables"
@@ -95,10 +96,19 @@ type IPTHandler struct {
9596

9697
// NewIPTHandler return the iptables handler used to configure the iptables rules.
9798
func NewIPTHandler() (IPTHandler, error) {
98-
ipt, err := iptables.New()
99+
selectedmode := os.Getenv("IPTABLES_MODE")
100+
var ipt *iptables.IPTables
101+
var err error
102+
if iptables.ModeType(selectedmode) == iptables.ModeTypeNFTables || iptables.ModeType(selectedmode) == iptables.ModeTypeLegacy {
103+
ipt, err = iptables.New(iptables.Mode(iptables.ModeType(selectedmode)))
104+
} else {
105+
ipt, err = iptables.New()
106+
}
99107
if err != nil {
100108
return IPTHandler{}, err
101109
}
110+
v1, v2, v3, mode := ipt.GetIptablesVersion()
111+
klog.Infof("Iptables version: %d.%d.%d, mode: %s", v1, v2, v3, mode)
102112
return IPTHandler{
103113
ipt: *ipt,
104114
}, err

0 commit comments

Comments
 (0)