Skip to content

Commit

Permalink
[WIP] Remove ip addr add "${U7S_HOST_IP}" dev eth0
Browse files Browse the repository at this point in the history
Fix issue 296

Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda committed Mar 31, 2024
1 parent a0ce8e3 commit ad2af38
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
9 changes: 1 addition & 8 deletions Dockerfile.d/u7s-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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}/" </etc/default/kubelet | sponge /etc/default/kubelet

# Let kubelet recognize ${U7S_HOST_IP} as its IP:
# https://github.com/kubernetes/kubernetes/issues/54337#issuecomment-363597985
ip addr add "${U7S_HOST_IP}" dev eth0

cat <<EOF >/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

Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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),)
Expand All @@ -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 </usernetes/kubeadm-config.yaml >/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
Expand Down
14 changes: 10 additions & 4 deletions kubeadm-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ad2af38

Please sign in to comment.