Skip to content

Commit

Permalink
Merge pull request #359 from AkihiroSuda/dev
Browse files Browse the repository at this point in the history
Consistently remove "U7S_" prefix from all the variables
  • Loading branch information
AkihiroSuda authored Dec 12, 2024
2 parents 251bb6a + 21331b3 commit 85c2d1d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.d/u7s-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/default/kubelet | sponge /etc/default/kubelet
sed -e "s!\(^KUBELET_EXTRA_ARGS=.*\)!\\1 --cloud-provider=external --node-labels=usernetes/host-ip=${HOST_IP}!" </etc/default/kubelet | sponge /etc/default/kubelet

# Import control plane hosts from previous boot
[ -e /etc/hosts.u7s ] && cat /etc/hosts.u7s >>/etc/hosts
Expand Down
66 changes: 27 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions Makefile.d/install-flannel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 11 additions & 11 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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:
# <host>:<container>
# 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
Expand All @@ -34,24 +34,24 @@ 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`
# has to be set to 0 (disabled) or 2 (loose)
# 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: {}
Expand Down
20 changes: 10 additions & 10 deletions kubeadm-config.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
---
Expand Down

0 comments on commit 85c2d1d

Please sign in to comment.