Skip to content

Commit

Permalink
feat: customization of exposed service ports
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vsoch committed Dec 5, 2024
1 parent 31887a8 commit b1f1768
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion kubeadm-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit b1f1768

Please sign in to comment.