Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6f29c5d

Browse files
committedDec 8, 2024·
feat: allow customization of flannel port
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
1 parent b7e2b1a commit 6f29c5d

File tree

6 files changed

+111
-4
lines changed

6 files changed

+111
-4
lines changed
 

‎.github/workflows/main.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
with:
1717
# Defaults to 6443
1818
kube_apiserver_port: "8080"
19+
# Defaults to 8472
20+
flannel_port: "9072"
1921
# Defaults to 10250
2022
kubelet_port: "20250"
2123
# Defaults to 2379
@@ -32,6 +34,8 @@ jobs:
3234
with:
3335
# Defaults to 6443
3436
kube_apiserver_port: "8080"
37+
# Defaults to 8472
38+
flannel_port: "9072"
3539
# Defaults to 10250
3640
kubelet_port: "20250"
3741
# Defaults to 2379

‎.github/workflows/reusable-multi-node.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
description: kubelet serving port
88
type: string
99
default: "10250"
10+
flannel_port:
11+
description: flannel vxlan port
12+
type: string
13+
default: "8472"
1014
etcd_port:
1115
description: etcd service port
1216
type: string
@@ -42,6 +46,7 @@ jobs:
4246
LIMA_TEMPLATE: "${{ matrix.lima-template }}"
4347
CONTAINER_ENGINE: "${{ matrix.engine }}"
4448
U7S_PORT_KUBE_APISERVER: "${{ inputs.kube_apiserver_port }}"
49+
U7S_PORT_FLANNEL: "${{ inputs.flannel_port }}"
4550
U7S_PORT_KUBELET: "${{ inputs.kubelet_port }}"
4651
U7S_PORT_ETCD: "${{ inputs.etcd_port }}"
4752
DOCKER_BUILDKIT: 1

‎.github/workflows/reusable-single-node.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
description: kubelet serving port
77
type: string
88
default: "10250"
9+
flannel_port:
10+
description: flannel vxlan port
11+
type: string
12+
default: "8472"
913
etcd_port:
1014
description: etcd service port
1115
type: string
@@ -32,6 +36,7 @@ jobs:
3236
env:
3337
CONTAINER_ENGINE: "${{ matrix.engine }}"
3438
U7S_PORT_KUBE_APISERVER: "${{ inputs.kube_apiserver_port }}"
39+
U7S_PORT_FLANNEL: "${{ inputs.flannel_port }}"
3540
U7S_PORT_KUBELET: "${{ inputs.kubelet_port }}"
3641
U7S_PORT_ETCD: "${{ inputs.etcd_port }}"
3742
DOCKER_BUILDKIT: 1

‎Dockerfile

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ RUN arch="$(uname -m | sed -e s/x86_64/amd64/ -e s/aarch64/arm64/)" && \
99
grep "${fname}" "/tmp/SHA256SUMS.d/cni-plugins-${CNI_PLUGINS_VERSION}" | sha256sum -c && \
1010
mkdir -p /opt/cni/bin && \
1111
tar xzf "${fname}" -C /opt/cni/bin && \
12-
rm -f "${fname}"
12+
rm -f "${fname}" && \
13+
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && \
14+
chmod 700 get_helm.sh && ./get_helm.sh
1315
# gettext-base: for `envsubst`
1416
# moreutils: for `sponge`
1517
# socat: for `socat` (to silence "[WARNING FileExisting-socat]" from kubeadm)
1618
RUN apt-get update && apt-get install -y --no-install-recommends \
1719
gettext-base \
1820
moreutils \
19-
socat
21+
socat \
22+
git
2023
ADD Dockerfile.d/etc_udev_rules.d_90-flannel.rules /etc/udev/rules.d/90-flannel.rules
2124
ADD Dockerfile.d/u7s-entrypoint.sh /
2225
ENTRYPOINT ["/u7s-entrypoint.sh", "/usr/local/bin/entrypoint", "/sbin/init"]

‎Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export HOSTNAME := $(HOSTNAME)
88
# Change ports for different kubernetes services
99
export U7S_PORT_ETCD ?= 2379
1010
export U7S_PORT_KUBELET ?= 10250
11-
export U7S_PORT_FLANNEL := 8472
11+
export U7S_PORT_FLANNEL ?= 8472
1212
export U7S_PORT_KUBE_APISERVER ?= 6443
1313

1414
HOST_IP ?= $(shell ip --json route get 1 | jq -r .[0].prefsrc)
@@ -41,6 +41,7 @@ NODE_SHELL := $(COMPOSE) exec \
4141
-e U7S_NODE_SUBNET=$(U7S_NODE_SUBNET) \
4242
-e U7S_NODE_IP=$(U7S_NODE_IP) \
4343
-e U7S_PORT_KUBE_APISERVER=$(U7S_PORT_KUBE_APISERVER) \
44+
-e U7S_PORT_FLANNEL=$(U7S_PORT_FLANNEL) \
4445
-e U7S_PORT_KUBELET=$(U7S_PORT_KUBELET) \
4546
-e U7S_PORT_ETCD=$(U7S_PORT_ETCD) \
4647
$(NODE_SERVICE_NAME)
@@ -157,4 +158,4 @@ kubeadm-reset:
157158

158159
.PHONY: install-flannel
159160
install-flannel:
160-
$(NODE_SHELL) kubectl apply -f https://github.com/flannel-io/flannel/releases/download/v0.26.1/kube-flannel.yml
161+
$(NODE_SHELL) /usernetes/Makefile.d/install-flannel.sh

‎Makefile.d/install-flannel.sh

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
function INFO() {
5+
echo >&2 -e "\e[104m\e[97m[INFO]\e[49m\e[39m $@"
6+
}
7+
function WARNING() {
8+
echo >&2 -e "\e[101m\e[97m[WARNING]\e[49m\e[39m $@"
9+
}
10+
11+
function ERROR() {
12+
echo >&2 -e "\e[101m\e[97m[ERROR]\e[49m\e[39m $@"
13+
}
14+
15+
script_dir="$(dirname "$0")"
16+
17+
# See chart values, 0 indicates default for platform
18+
# https://github.com/flannel-io/flannel/blob/v0.26.1/chart/kube-flannel/values.yaml
19+
: "${U7S_PORT_FLANNEL:=$("0" U7S_PORT_FLANNEL)}"
20+
INFO "Flannel port: ${U7S_PORT_FLANNEL}"
21+
22+
# Check hard dependency commands
23+
for cmd in helm kubectl git; do
24+
if ! command -v "${cmd}" >/dev/null 2>&1; then
25+
ERROR "Command \"${cmd}\" is not installed"
26+
exit 1
27+
fi
28+
done
29+
30+
# We need to customize the values.yaml to expose the backendPort and args
31+
flannel_root=$(mktemp -d -u -t flannel-XXXXXXX)
32+
git clone --depth 1 --branch v0.26.1 https://github.com/flannel-io/flannel $flannel_root
33+
cd $flannel_root/chart
34+
35+
# Write a new values.yaml that exposes what we need
36+
cat <<EOF > ./new-values.yaml
37+
---
38+
global:
39+
imagePullSecrets:
40+
# - name: "a-secret-name"
41+
42+
# The IPv4 cidr pool to create on startup if none exists. Pod IPs will be
43+
# chosen from this range.
44+
podCidr: "10.244.0.0/16"
45+
podCidrv6: ""
46+
flannel:
47+
# kube-flannel image
48+
image:
49+
repository: docker.io/flannel/flannel
50+
tag: v0.26.1
51+
image_cni:
52+
repository: docker.io/flannel/flannel-cni-plugin
53+
tag: v1.5.1-flannel2
54+
# flannel command arguments
55+
enableNFTables: false
56+
args:
57+
- "--ip-masq"
58+
- "--kube-subnet-mgr"
59+
- "--vxlan-port=${U7S_PORT_FLANNEL}"
60+
# Backend for kube-flannel. Backend should not be changed
61+
# at runtime. (vxlan, host-gw, wireguard, udp)
62+
# Documentation at https://github.com/flannel-io/flannel/blob/master/Documentation/backends.md
63+
backend: "vxlan"
64+
# Port used by the backend 0 means default value (VXLAN: 8472, Wireguard: 51821, UDP: 8285)
65+
backendPort: ${U7S_PORT_FLANNEL}
66+
tolerations:
67+
- effect: NoExecute
68+
operator: Exists
69+
- effect: NoSchedule
70+
operator: Exists
71+
72+
netpol:
73+
enabled: false
74+
args:
75+
- "--hostname-override=$(MY_NODE_NAME)"
76+
- "--v=2"
77+
image:
78+
repository: registry.k8s.io/networking/kube-network-policies
79+
tag: v0.4.0
80+
EOF
81+
82+
mv ./new-values.yaml ./kube-flannel/values.yaml
83+
84+
kubectl create namespace kube-flannel || WARNING "kube-flannel namespace is already created"
85+
kubectl label --overwrite namespace kube-flannel pod-security.kubernetes.io/enforce=privileged
86+
# We could also do --set flannel.backendPort=<value> but it's the same to set as the default
87+
helm install flannel --namespace kube-flannel kube-flannel
88+
cd -
89+
rm -rf $flannel_root

0 commit comments

Comments
 (0)
Please sign in to comment.