diff --git a/Dockerfile.d/u7s-entrypoint.sh b/Dockerfile.d/u7s-entrypoint.sh index 36072a8..5003b84 100755 --- a/Dockerfile.d/u7s-entrypoint.sh +++ b/Dockerfile.d/u7s-entrypoint.sh @@ -2,7 +2,7 @@ set -eux -o pipefail # Append "KUBELET_EXTRA_ARGS=..." in /etc/default/kubelet -sed -e "s!\(^KUBELET_EXTRA_ARGS=.*\)!\\1 --cloud-provider=external --node-labels=usernetes/host-ip=${U7S_HOST_IP}!" >/etc/hosts diff --git a/Makefile b/Makefile index 4a55ca8..8511807 100644 --- a/Makefile +++ b/Makefile @@ -1,60 +1,48 @@ # Run `make help` to show usage .DEFAULT_GOAL := help -HOSTNAME ?= $(shell hostname) -# HOSTNAME is the name of the physical host -export HOSTNAME := $(HOSTNAME) - # Change ports for different kubernetes services -PORT_ETCD ?= 2379 -PORT_KUBELET ?= 10250 -PORT_FLANNEL ?= 8472 -PORT_KUBE_APISERVER ?= 6443 - -export U7S_PORT_ETCD := $(PORT_ETCD) -export U7S_PORT_KUBELET := $(PORT_KUBELET) -export U7S_PORT_FLANNEL := $(PORT_FLANNEL) -export U7S_PORT_KUBE_APISERVER := $(PORT_KUBE_APISERVER) - -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) -# U7S_HOST_IP is the IP address of the physical host. Accessible from other hosts. -export U7S_HOST_IP := $(HOST_IP) -# U7S_NODE_NAME is the host name of the Kubernetes node running in Rootless Docker. +export PORT_ETCD ?= 2379 +export PORT_KUBELET ?= 10250 +export PORT_FLANNEL ?= 8472 +export PORT_KUBE_APISERVER ?= 6443 + +# HOSTNAME is the name of the physical host +export HOSTNAME ?= $(shell hostname) +# HOST_IP is the IP address of the physical host. Accessible from other hosts. +export HOST_IP ?= $(shell ip --json route get 1 | jq -r .[0].prefsrc) +# NODE_NAME is the host name of the Kubernetes node running in Rootless Docker. # Not accessible from other hosts. -export U7S_NODE_NAME:= $(NODE_NAME) -# U7S_NODE_NAME is the subnet of the Kubernetes node running in Rootless Docker. +export NODE_NAME ?= u7s-$(HOSTNAME) +# NODE_SUBNET is the subnet of the Kubernetes node running in Rootless Docker. # Not accessible from other hosts. -export U7S_NODE_SUBNET := $(NODE_SUBNET) -# U7S_NODE_IP is the IP address of the Kubernetes node running in Rootless Docker. +export NODE_SUBNET ?= $(shell $(CURDIR)/Makefile.d/node-subnet.sh) +# NODE_IP is the IP address of the Kubernetes node running in Rootless Docker. # Not accessible from other hosts. -export U7S_NODE_IP := $(subst .0/24,.100,$(U7S_NODE_SUBNET)) +export NODE_IP := $(subst .0/24,.100,$(NODE_SUBNET)) -CONTAINER_ENGINE ?= $(shell $(CURDIR)/Makefile.d/detect-container-engine.sh CONTAINER_ENGINE) -export CONTAINER_ENGINE := $(CONTAINER_ENGINE) +export CONTAINER_ENGINE ?= $(shell $(CURDIR)/Makefile.d/detect-container-engine.sh CONTAINER_ENGINE) -CONTAINER_ENGINE_TYPE ?= $(shell $(CURDIR)/Makefile.d/detect-container-engine.sh CONTAINER_ENGINE_TYPE) -export CONTAINER_ENGINE_TYPE := $(CONTAINER_ENGINE_TYPE) +export CONTAINER_ENGINE_TYPE ?= $(shell $(CURDIR)/Makefile.d/detect-container-engine.sh CONTAINER_ENGINE_TYPE) COMPOSE ?= $(shell $(CURDIR)/Makefile.d/detect-container-engine.sh COMPOSE) NODE_SERVICE_NAME := node NODE_SHELL := $(COMPOSE) exec \ - -e U7S_HOST_IP=$(U7S_HOST_IP) \ - -e U7S_NODE_NAME=$(U7S_NODE_NAME) \ - -e U7S_NODE_SUBNET=$(U7S_NODE_SUBNET) \ - -e U7S_NODE_IP=$(U7S_NODE_IP) \ - -e U7S_PORT_KUBE_APISERVER=$(U7S_PORT_KUBE_APISERVER) \ - -e U7S_PORT_FLANNEL=$(U7S_PORT_FLANNEL) \ - -e U7S_PORT_KUBELET=$(U7S_PORT_KUBELET) \ - -e U7S_PORT_ETCD=$(U7S_PORT_ETCD) \ + -e HOST_IP=$(HOST_IP) \ + -e NODE_NAME=$(NODE_NAME) \ + -e NODE_SUBNET=$(NODE_SUBNET) \ + -e NODE_IP=$(NODE_IP) \ + -e PORT_KUBE_APISERVER=$(PORT_KUBE_APISERVER) \ + -e PORT_FLANNEL=$(PORT_FLANNEL) \ + -e PORT_KUBELET=$(PORT_KUBELET) \ + -e PORT_ETCD=$(PORT_ETCD) \ $(NODE_SERVICE_NAME) ifeq ($(CONTAINER_ENGINE),nerdctl) ifneq (,$(wildcard $(XDG_RUNTIME_DIR)/bypass4netnsd.sock)) - export U7S_B4NN := true - export U7S_B4NN_IGNORE_SUBNETS := ["10.96.0.0/16", "10.244.0.0/16", "$(U7S_NODE_SUBNET)"] + export BYPASS4NETNS := true + export BYPASS4NETNS_IGNORE_SUBNETS := ["10.96.0.0/16", "10.244.0.0/16", "$(NODE_SUBNET)"] endif endif diff --git a/Makefile.d/install-flannel.sh b/Makefile.d/install-flannel.sh index 88f65af..0936d27 100755 --- a/Makefile.d/install-flannel.sh +++ b/Makefile.d/install-flannel.sh @@ -3,10 +3,10 @@ set -eu -o pipefail # See chart values, 0 indicates default for platform # https://github.com/flannel-io/flannel/blob/v0.26.1/chart/kube-flannel/values.yaml -: "${U7S_PORT_FLANNEL:='0'}" +: "${PORT_FLANNEL:='0'}" if ! helm -n kube-flannel list -q | grep flannel; then kubectl create namespace kube-flannel kubectl label --overwrite namespace kube-flannel pod-security.kubernetes.io/enforce=privileged - helm install flannel --namespace kube-flannel --set-json flannel.backendPort=${U7S_PORT_FLANNEL} /flannel + helm install flannel --namespace kube-flannel --set-json flannel.backendPort=${PORT_FLANNEL} /flannel fi diff --git a/docker-compose.yaml b/docker-compose.yaml index 3e2161a..09707ea 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,25 +1,25 @@ # Use `make up`, not `docker compose up`, -# as this YAML requires ${U7S_...} variables to be set. +# as this YAML requires ${...} variables to be set. --- services: node: build: . - hostname: ${U7S_NODE_NAME} + hostname: ${NODE_NAME} privileged: true restart: always networks: default: - ipv4_address: ${U7S_NODE_IP} + ipv4_address: ${NODE_IP} ports: # : # etcd (default: 2379) - - ${U7S_PORT_ETCD}:${U7S_PORT_ETCD} + - ${PORT_ETCD}:${PORT_ETCD} # kube-apiserver (default: 6443) - - ${U7S_PORT_KUBE_APISERVER}:${U7S_PORT_KUBE_APISERVER} + - ${PORT_KUBE_APISERVER}:${PORT_KUBE_APISERVER} # kubelet (default: 10250) - - ${U7S_PORT_KUBELET}:${U7S_PORT_KUBELET} + - ${PORT_KUBELET}:${PORT_KUBELET} # flannel (default: 8472) - - ${U7S_PORT_FLANNEL}:${U7S_PORT_FLANNEL}/udp + - ${PORT_FLANNEL}:${PORT_FLANNEL}/udp volumes: - .:/usernetes:ro - /boot:/boot:ro @@ -34,7 +34,7 @@ services: working_dir: /usernetes environment: KUBECONFIG: /etc/kubernetes/admin.conf - U7S_HOST_IP: ${U7S_HOST_IP} + HOST_IP: ${HOST_IP} sysctls: - net.ipv4.ip_forward=1 # In addition, `net.ipv4.conf.default.rp_filter` @@ -42,16 +42,16 @@ services: # in the daemon's network namespace. annotations: # Accelerate network for nerdctl >= 2.0.0-beta.4 with bypass4netns >= 0.4.1 - "nerdctl/bypass4netns": "${U7S_B4NN:-false}" + "nerdctl/bypass4netns": "${BYPASS4NETNS:-false}" "nerdctl/bypass4netns-ignore-bind": "true" - "nerdctl/bypass4netns-ignore-subnets": "${U7S_B4NN_IGNORE_SUBNETS:-}" + "nerdctl/bypass4netns-ignore-subnets": "${BYPASS4NETNS_IGNORE_SUBNETS:-}" networks: default: ipam: config: # Each of the nodes has to have a different IP. # The node IP here is not accessible from other nodes. - - subnet: ${U7S_NODE_SUBNET} + - subnet: ${NODE_SUBNET} volumes: node-var: {} node-opt: {} diff --git a/kubeadm-config.yaml b/kubeadm-config.yaml index 2b40ad8..91f1880 100644 --- a/kubeadm-config.yaml +++ b/kubeadm-config.yaml @@ -1,24 +1,24 @@ apiVersion: kubeadm.k8s.io/v1beta4 kind: InitConfiguration localAPIEndpoint: - bindPort: ${U7S_PORT_KUBE_APISERVER} + bindPort: ${PORT_KUBE_APISERVER} --- apiVersion: kubeadm.k8s.io/v1beta4 kind: ClusterConfiguration -controlPlaneEndpoint: "${U7S_NODE_NAME}:${U7S_PORT_KUBE_APISERVER}" +controlPlaneEndpoint: "${NODE_NAME}:${PORT_KUBE_APISERVER}" apiServer: certSANs: - localhost - 127.0.0.1 - - "${U7S_NODE_NAME}" - - "${U7S_HOST_IP}" + - "${NODE_NAME}" + - "${HOST_IP}" extraArgs: - name: etcd-servers - value: https://127.0.0.1:${U7S_PORT_ETCD} + value: https://127.0.0.1:${PORT_ETCD} - name: advertise-address - value: ${U7S_HOST_IP} + value: ${HOST_IP} - name: secure-port - value: "${U7S_PORT_KUBE_APISERVER}" + value: "${PORT_KUBE_APISERVER}" - name: cloud-provider value: external # Default: "Hostname,InternalDNS,InternalIP,ExternalDNS,ExternalIP" @@ -35,14 +35,14 @@ etcd: local: extraArgs: - name: listen-client-urls - value: "https://127.0.0.1:${U7S_PORT_ETCD},https://${U7S_NODE_IP}:${U7S_PORT_ETCD}" + value: "https://127.0.0.1:${PORT_ETCD},https://${NODE_IP}:${PORT_ETCD}" - name: advertise-client-urls - value: https://${U7S_NODE_IP}:${U7S_PORT_ETCD} + value: https://${NODE_IP}:${PORT_ETCD} --- kind: KubeletConfiguration apiVersion: kubelet.config.k8s.io/v1beta1 failSwapOn: false -port: ${U7S_PORT_KUBELET} +port: ${PORT_KUBELET} featureGates: KubeletInUserNamespace: true ---