From b1f1768abffc6ea45b4dbc0ece32026e961c5a9b Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 4 Dec 2024 12:02:40 -0700 Subject: [PATCH] feat: customization of exposed service ports Problem: when deploying usernetes in a multi tenant environment, there will likely be clashing of ports due to their hard coding of traditional values. Solution: expose these ports (those mapped to the host in the docker-compose.yaml and kubeadm-config yaml as environment variables to customize. Signed-off-by: vsoch --- Makefile | 7 +++++++ docker-compose.yaml | 8 ++++---- kubeadm-config.yaml | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 00a1e8a..59dd22c 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,12 @@ HOSTNAME ?= $(shell hostname) # HOSTNAME is the name of the physical host export HOSTNAME := $(HOSTNAME) +# Exposed ports to the host (default to same as in container) +export U7S_EXPOSED_PORT_ETCD ?= 2379 +export U7S_EXPOSED_PORT_KUBE_APISERVER ?= 6443 +export U7S_EXPOSED_PORT_KUBELET ?= 10250 +export U7S_EXPOSED_PORT_FLANNEL ?= 8472 + HOST_IP ?= $(shell ip --json route get 1 | jq -r .[0].prefsrc) NODE_NAME ?= u7s-$(HOSTNAME) NODE_SUBNET ?= $(shell $(CURDIR)/Makefile.d/node-subnet.sh) @@ -34,6 +40,7 @@ NODE_SHELL := $(COMPOSE) exec \ -e U7S_NODE_NAME=$(U7S_NODE_NAME) \ -e U7S_NODE_SUBNET=$(U7S_NODE_SUBNET) \ -e U7S_NODE_IP=$(U7S_NODE_IP) \ + -e U7S_EXPOSED_PORT_KUBE_APISERVER=$(U7S_EXPOSED_PORT_KUBE_APISERVER) \ $(NODE_SERVICE_NAME) ifeq ($(CONTAINER_ENGINE),nerdctl) diff --git a/docker-compose.yaml b/docker-compose.yaml index 15d8e9f..e80bfe7 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,13 +12,13 @@ services: ipv4_address: ${U7S_NODE_IP} ports: # etcd - - 2379:2379 + - ${U7S_EXPOSED_PORT_ETCD}:2379 # kube-apiserver - - 6443:6443 + - ${U7S_EXPOSED_PORT_KUBE_APISERVER}:6443 # kubelet - - 10250:10250 + - ${U7S_EXPOSED_PORT_KUBELET}:10250 # flannel - - 8472:8472/udp + - ${U7S_EXPOSED_PORT_FLANNEL}:8472/udp volumes: - .:/usernetes:ro - /boot:/boot:ro diff --git a/kubeadm-config.yaml b/kubeadm-config.yaml index cc09f9a..24c2fdc 100644 --- a/kubeadm-config.yaml +++ b/kubeadm-config.yaml @@ -7,7 +7,7 @@ kind: ClusterConfiguration networking: serviceSubnet: "10.96.0.0/16" podSubnet: "10.244.0.0/16" -controlPlaneEndpoint: "${U7S_NODE_NAME}:6443" +controlPlaneEndpoint: "${U7S_NODE_NAME}:${U7S_EXPOSED_PORT_KUBE_APISERVER}" apiServer: extraArgs: advertise-address: "${U7S_HOST_IP}"