Skip to content

Commit 43c5a80

Browse files
authored
Enable IPVS on kube proxy (#2357)
1 parent a2412d9 commit 43c5a80

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed

dev/versions.md

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
1. Update `ami.json` (see release checklist for instructions)
1919
1. See instructions for upgrading the Kubernetes client below
2020

21+
## kube-proxy (IPVS mode)
22+
23+
1. Before spinning up a Cortex cluster with the new eksctl/kubernetes/eks updates, make sure to have the `setup_ipvs` functional call commented out in the manager.
24+
1. Once the cluster is up, run the `cat /var/lib/kube-proxy-config/config` command on any of the kube-proxy pods of the cluster. Compare the output of that with what the `upgrade_kube_proxy_mode.py` script is applying and make sure it's still applicable, if not, check out the spec of the [KubeProxyConfiguration](https://kubernetes.io/docs/reference/config-api/kube-proxy-config.v1alpha1/) and upgrade `upgrade_kube_proxy_mode.py`.
25+
1. Compare the spec of the `kube-proxy.patch.yaml` patch with the current spec of the kube-proxy daemoset and make sure it's still applicable. You can either inspect the `kube-proxy` command helper by exec-ing into the pod or by looking at the [kube-proxy](https://kubernetes.io/docs/reference/command-line-tools-reference/kube-proxy/) documentation for the respective version of Kubernetes.
26+
1. Once both config map and the daemonset are updated and the kube-proxy pod(s) has/have started, make sure you notice the `Using ipvs Proxier` log.
27+
2128
## aws-iam-authenticator
2229

2330
1. Find the latest release [here](https://docs.aws.amazon.com/eks/latest/userguide/install-aws-iam-authenticator.html)

manager/generate_eks.py

+9
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ def default_nodegroup(cluster_config):
6767
"evictionHard": {"memory.available": "200Mi", "nodefs.available": "5%"},
6868
"registryPullQPS": 10,
6969
},
70+
"preBootstrapCommands": [
71+
"sudo yum install -y ipvsadm",
72+
"sudo modprobe ip_vs", # IP virtual server
73+
"sudo modprobe ip_vs_rr", # round robing load balancer
74+
"sudo modprobe ip_vs_lc", # least connected load balancer
75+
"sudo modprobe ip_vs_wrr", # weighted round robin load balancer
76+
"sudo modprobe ip_vs_sh", # source-hashing load balancer
77+
"sudo modprobe nf_conntrack_ipv4",
78+
],
7079
}
7180

7281

manager/install.sh

+20
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function cluster_up() {
4141
echo ""
4242

4343
echo -n "○ configuring networking (this will take a few minutes) "
44+
setup_ipvs
4445
setup_istio
4546
python render_template.py $CORTEX_CLUSTER_CONFIG_FILE manifests/apis.yaml.j2 | kubectl apply -f - >/dev/null
4647
echo ""
@@ -368,6 +369,25 @@ function remove_nodegroups() {
368369
echo
369370
}
370371

372+
function setup_ipvs() {
373+
# get a random kube-proxy pod
374+
kubectl rollout status daemonset kube-proxy -n kube-system --timeout 30m >/dev/null
375+
kube_proxy_pod=$(kubectl get pod -n kube-system -l k8s-app=kube-proxy -o jsonpath='{.items[*].metadata.name}' | cut -d " " -f1)
376+
377+
# export kube-proxy's current config
378+
kubectl exec -it -n kube-system ${kube_proxy_pod} -- cat /var/lib/kube-proxy-config/config > proxy_config.yaml
379+
380+
# upgrade proxy mode from the exported kube-proxy config
381+
python upgrade_kube_proxy_mode.py proxy_config.yaml > upgraded_proxy_config.yaml
382+
383+
# update kube-proxy's configmap to include the updated configuration
384+
kubectl get configmap -n kube-system kube-proxy -o yaml | yq --arg replace "`cat upgraded_proxy_config.yaml`" '.data.config=$replace' | kubectl apply -f - >/dev/null
385+
386+
# patch the kube-proxy daemonset
387+
kubectl patch ds -n kube-system kube-proxy --patch "$(cat manifests/kube-proxy.patch.yaml)" >/dev/null
388+
kubectl rollout status daemonset kube-proxy -n kube-system --timeout 30m >/dev/null
389+
}
390+
371391
function setup_istio() {
372392
if ! grep -q "istio-customgateway-certs" <<< $(kubectl get secret -n istio-system); then
373393
WEBSITE=localhost
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2021 Cortex Labs, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This is a patch that needs to be applied onto the daemonset that's added by eksctl.
16+
17+
apiVersion: apps/v1
18+
kind: DaemonSet
19+
metadata:
20+
name: kube-proxy
21+
namespace: kube-system
22+
spec:
23+
selector:
24+
matchLabels:
25+
k8s-app: kube-proxy
26+
template:
27+
spec:
28+
containers:
29+
- name: kube-proxy
30+
command:
31+
- kube-proxy
32+
- --v=2
33+
- --proxy-mode=ipvs
34+
- --ipvs-scheduler=rr
35+
- --config=/var/lib/kube-proxy/config
36+
env:
37+
- name: KUBE_PROXY_MODE
38+
value: ipvs
39+
updateStrategy:
40+
rollingUpdate:
41+
maxUnavailable: 20%
42+
type: RollingUpdate

manager/upgrade_kube_proxy_mode.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2021 Cortex Labs, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Usage: python create_user.py $KUBE_PROXY_CONFIG.yaml
16+
17+
import yaml
18+
import sys
19+
20+
21+
def main():
22+
kube_proxy_config_file = sys.argv[1]
23+
with open(kube_proxy_config_file, "r") as f:
24+
kube_proxy_config = yaml.safe_load(f)
25+
26+
kube_proxy_config["mode"] = "ipvs" # IP Virtual Server
27+
kube_proxy_config["ipvs"]["scheduler"] = "rr" # round robin
28+
29+
print(yaml.dump(kube_proxy_config, indent=2))
30+
31+
32+
if __name__ == "__main__":
33+
main()

0 commit comments

Comments
 (0)