From ad2af389efd64f23a3b5338c7ca0e8a6c39500ac Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Sun, 31 Mar 2024 22:54:12 +0900 Subject: [PATCH] [WIP] Remove `ip addr add "${U7S_HOST_IP}" dev eth0` Fix issue 296 Signed-off-by: Akihiro Suda --- Dockerfile | 2 -- Dockerfile.d/u7s-entrypoint.sh | 9 +-------- Makefile | 7 +++++-- kubeadm-config.yaml | 14 ++++++++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index c97356e..0698b08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,11 +7,9 @@ RUN arch="$(uname -m | sed -e s/x86_64/amd64/ -e s/aarch64/arm64/)" && \ curl -fsSL https://github.com/containernetworking/plugins/releases/download/${CNI_PLUGINS_VERSION}/cni-plugins-linux-${arch}-${CNI_PLUGINS_VERSION}.tgz \ | tar Cxzv /opt/cni/bin # gettext-base: for `envsubst` -# moreutils: for `sponge` # socat: for `socat` (to silence "[WARNING FileExisting-socat]" from kubeadm) RUN apt-get update && apt-get install -y --no-install-recommends \ gettext-base \ - moreutils \ socat ADD Dockerfile.d/u7s-entrypoint.sh / ENTRYPOINT ["/u7s-entrypoint.sh", "/usr/local/bin/entrypoint", "/sbin/init"] diff --git a/Dockerfile.d/u7s-entrypoint.sh b/Dockerfile.d/u7s-entrypoint.sh index 537707c..f1b3f79 100755 --- a/Dockerfile.d/u7s-entrypoint.sh +++ b/Dockerfile.d/u7s-entrypoint.sh @@ -1,19 +1,12 @@ #!/bin/bash set -eux -o pipefail -# Append "---node-ip=${U7S_HOST_IP}" to "KUBELET_EXTRA_ARGS=..." in /etc/default/kubelet -sed -e "s/\(^KUBELET_EXTRA_ARGS=.*\)/\\1 --node-ip=${U7S_HOST_IP}/" /u7s-flanneld-wrapper.sh #!/bin/sh # Usage: /u7s-flanneld-wrapper.sh /opt/bin/flanneld --ip-masq --kube-subnet-mgr ... # This script is expected to be mounted inside a "docker.io/flannel/flannel" container. set -eux -"\$@" --public-ip="${U7S_HOST_IP}" +"\$@" EOF chmod +x /u7s-flanneld-wrapper.sh diff --git a/Makefile b/Makefile index d458f09..ba259ce 100644 --- a/Makefile +++ b/Makefile @@ -81,7 +81,7 @@ logs: .PHONY: kubeconfig kubeconfig: - $(COMPOSE) exec -T $(NODE_SERVICE_NAME) cat /etc/kubernetes/admin.conf >kubeconfig + $(COMPOSE) exec -T $(NODE_SERVICE_NAME) sed -e "s/$(NODE_NAME)/localhost/g" /etc/kubernetes/admin.conf >kubeconfig @echo "# Run the following command by yourself:" @echo "export KUBECONFIG=$(shell pwd)/kubeconfig" ifeq ($(shell command -v kubectl 2> /dev/null),) @@ -98,13 +98,16 @@ kubectl: .PHONY: join-command join-command: - $(NODE_SHELL) kubeadm token create --print-join-command | tr -d '\r' >join-command + $(NODE_SHELL) kubeadm token create --print-join-command | tr -d '\r' | sed -e "s/$(NODE_NAME)/$(HOST_IP)/g" >join-command @echo "# Copy the 'join-command' file to another host, and run 'make kubeadm-join' on that host (not on this host)" .PHONY: kubeadm-init kubeadm-init: $(NODE_SHELL) sh -euc "envsubst /tmp/kubeadm-config.yaml" $(NODE_SHELL) kubeadm init --config /tmp/kubeadm-config.yaml --skip-token-print + $(NODE_SHELL) kubectl patch node $(NODE_NAME) --type=merge --subresource status --patch \ + "\"status\": {\"addresses\": [{\"type\":\"ExternalIP\", \"address\": \"$(HOST_IP)\"}]}" + $(NODE_SHELL) kubectl taint node $(NODE_NAME) node.cloudprovider.kubernetes.io/uninitialized- @echo "# Run 'make join-command' to print the join command" .PHONY: kubeadm-join diff --git a/kubeadm-config.yaml b/kubeadm-config.yaml index dd2d9e2..1becd0f 100644 --- a/kubeadm-config.yaml +++ b/kubeadm-config.yaml @@ -1,16 +1,22 @@ --- apiVersion: kubeadm.k8s.io/v1beta3 kind: InitConfiguration -localAPIEndpoint: - advertiseAddress: "${U7S_HOST_IP}" - bindPort: 6443 +nodeRegistration: + kubeletExtraArgs: + cloud-provider: external --- apiVersion: kubeadm.k8s.io/v1beta3 kind: ClusterConfiguration networking: serviceSubnet: "10.96.0.0/16" podSubnet: "10.244.0.0/16" -controlPlaneEndpoint: "${U7S_HOST_IP}:6443" +controlPlaneEndpoint: "${U7S_NODE_NAME}:6443" +apiServer: + certSANs: + - localhost + - 127.0.0.1 + - "${U7S_NODE_NAME}" + - "${U7S_HOST_IP}" --- kind: KubeletConfiguration apiVersion: kubelet.config.k8s.io/v1beta1