Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions docs/contributor/multinode/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,36 @@ and run it remotely.
```
git clone https://github.com/openshift/microshift.git ~/microshift
cd ~/microshift/
scp -o StrictHostKeyChecking=no ./scripts/multinode/configure-pri.sh redhat@${PRI_ADDR}:
ssh redhat@${PRI_ADDR} ./configure-pri.sh "${PRI_HOST}" "${PRI_ADDR}" "${SEC_HOST}" "${SEC_ADDR}"
scp -o StrictHostKeyChecking=no ./scripts/multinode/configure-node.sh redhat@${PRI_ADDR}:
ssh redhat@${PRI_ADDR} ./configure-node.sh
```

If the configuration script runs successfully, it prints the list of the
`kubelet` configuration files that need to be copied to the secondary host.
If the configuration script runs successfully, it prints the location of a
bootstrap kubeconfig that will be used in the secondary host.

Copy the `kubelet` configuration files from the primary to the secondary host.
Copy the kubeconfig configuration file from the primary to the secondary host.
```
scp -3 -o StrictHostKeyChecking=no \
redhat@${PRI_ADDR}:/home/redhat/kubelet-${SEC_HOST}.{key,crt} \
redhat@${PRI_ADDR}:/home/redhat/kubeconfig-${PRI_HOST} \
scp -o StrictHostKeyChecking=no \
redhat@${PRI_ADDR}:/home/redhat/kubeconfig-bootstrap \
redhat@${SEC_ADDR}:
```

Run the following commands to copy the configuration script to the secondary host
and run it remotely.
```
cd ~/microshift/
scp -o StrictHostKeyChecking=no ./scripts/multinode/configure-sec.sh redhat@${SEC_ADDR}:
ssh redhat@${SEC_ADDR} ./configure-sec.sh "${PRI_HOST}" "${PRI_ADDR}" "${SEC_HOST}" "${SEC_ADDR}"
scp -o StrictHostKeyChecking=no ./scripts/multinode/configure-node.sh redhat@${SEC_ADDR}:
ssh redhat@${SEC_ADDR} "BOOTSTRAP_KUBECONFIG=~/kubeconfig-bootstrap ./configure-node.sh"
```

## Run Tests
Before running tests, make sure that the `microshift-pri` host name is resolved
and accessible from the `hypervisor host`.
Before running tests, make sure that the `microshift-pri` host is accessible
from the `hypervisor host`.

Set the `KUBECONFIG` variable using the configuration file from the primary host.
```
export KUBECONFIG=$(mktemp /tmp/microshift-kubeconfig.XXXXXXXXXX)
scp redhat@${PRI_ADDR}:/home/redhat/kubeconfig-${PRI_HOST} ${KUBECONFIG}
scp redhat@${PRI_ADDR}:/home/redhat/kubeconfig-bootstrap ${KUBECONFIG}
```

Verify that the cluster has **two** nodes in the `Ready` status and wait until
Expand All @@ -76,4 +75,4 @@ watch oc get pods -A

Run your test suite of choice using the primary and secondary MicroShift instances.

If you want to run [openshift-tests](https://github.com/openshift/origin) suite, follow [this](../openshift_ci.md#running-tests-manually) document.
If you want to run [openshift-tests](https://github.com/openshift/origin) suite, follow [this](../openshift_ci.md#running-tests-manually) document.
27 changes: 0 additions & 27 deletions scripts/auto-rebase/rebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1289,33 +1289,10 @@ rebase_to() {
echo "No changes to buildfiles."
fi

update_cncf_kubelet_version
if [[ -n "$(git status -s scripts/multinode/configure-sec.sh)" ]]; then
title "## Committing changes to scripts/multinode/configure-sec.sh"
git add scripts/multinode/configure-sec.sh
git commit -m "update kubernetes version in CNCF scripts"
else
echo "No changes to Kubernetes version."
fi

title "# Removing staging directory"
rm -rf "${STAGING_DIR}"
}

update_cncf_kubelet_version() {
title "Updating Kubernetes version in CNCF scripts"

source "${REPOROOT}/Makefile.kube_git.var"
local -r kube_hash_amd64="$(curl -L https://dl.k8s.io/release/${KUBE_GIT_VERSION}/bin/linux/amd64/kubelet.sha256 2>/dev/null)"
local -r kube_hash_arm64="$(curl -L https://dl.k8s.io/release/${KUBE_GIT_VERSION}/bin/linux/arm64/kubelet.sha256 2>/dev/null)"

local -r target="${REPOROOT}/scripts/multinode/configure-sec.sh"
sed -i "s,# version=v1\.[0-9]*\.[0-9]*;,# version=${KUBE_GIT_VERSION};,g" "${target}"
sed -i "s,local -r version=.*,local -r version=\"${KUBE_GIT_VERSION}\",g" "${target}"
sed -i "s,local -r kube_hash_amd64=.*,local -r kube_hash_amd64=\"${kube_hash_amd64}\",g" "${target}"
sed -i "s,local -r kube_hash_arm64=.*,local -r kube_hash_arm64=\"${kube_hash_arm64}\",g" "${target}"
}

to_just_images() {
local release_image_amd64=$1
local release_image_arm64=$2
Expand Down Expand Up @@ -1353,7 +1330,6 @@ usage() {
echo "$(basename "$0") generated-apis Regenerates OpenAPIs"
echo "$(basename "$0") images Rebases the component images to the downloaded release"
echo "$(basename "$0") manifests Rebases the component manifests to the downloaded release"
echo "$(basename "$0") cncf-kube-version Updates kubelet version in configure-sec.sh to match version in Makefile.kube_git.var"
exit 1
}

Expand Down Expand Up @@ -1385,8 +1361,5 @@ case "$command" in
copy_manifests
update_openshift_manifests
;;
cncf-kube-version)
update_cncf_kubelet_version
;;
*) usage;;
esac
161 changes: 161 additions & 0 deletions scripts/multinode/configure-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#!/bin/bash
set -euo pipefail

# Variables for node configuration
NODE_ADDR=""
BOOTSTRAP_KUBECONFIG=""

function usage() {
echo "This script configures a node to run a MicroShift cluster."
echo "Optionally, it can also be used to configure MicroShift to join an existing cluster."
echo "Usage: $(basename "$0") [OPTIONS]"
echo "Options:"
echo " --bootstrap-kubeconfig PATH Path to kubeconfig file for joining existing cluster (optional)"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo " --bootstrap-kubeconfig PATH Path to kubeconfig file for joining existing cluster (optional)"
echo " --join-to-cluster BOOTSTRAP_KUBECONFIG_PATH Path to kubeconfig file for joining existing cluster (optional)"

I'm wondering if this would be clear. Looking at the invocs I'm missing a bit info whether I'm setting up a primary or adding (secondary) node - aka invocs are not clear at first glance, but maybe that's just me :)

Like

./configure-node.sh
./configure-node.sh --bootstrap-kubeconfig ~/path

compared to something like (just thinking out loud, I don't expect it to be change to this)

./configure-node.sh primary
./configure-node.sh add-node ~/path

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some help to the command.

Just calling the script without options means "configure this node to run MicroShift", while also allowing it to be prepared to add more nodes. This is implied by the location of the script (scripts/multinode).
Similar semantics with the --bootstrap-kubeconfig, which implies there is another cluster (the kubeconfig) that you will be using to bootstrap this node into it. Also the help shows it.
Keep in mind that this is all unsupported, so quite niche for now.

echo " -h, --help Show this help message"
exit 1
}

function configure_system() {
# TODO: Edit firewall rules instead of stopping firewall
sudo systemctl stop firewalld
sudo systemctl disable firewalld

sudo systemctl stop greenboot-healthcheck
sudo systemctl reset-failed greenboot-healthcheck
sudo systemctl disable greenboot-healthcheck
}

function configure_microshift() {
# Clean the current MicroShift configuration and stop the service
echo 1 | sudo microshift-cleanup-data --all --keep-images

get_node_ip_from_config

# Configure MicroShift to disable telemetry
cat <<EOF | sudo tee /etc/microshift/config.d/multinode.yaml &>/dev/null
apiServer:
subjectAltNames:
- ${NODE_ADDR}
telemetry:
status: Disabled
EOF

sudo mkdir -p /etc/systemd/system/microshift.service.d
cat <<EOF | sudo tee /etc/systemd/system/microshift.service.d/multinode.conf &>/dev/null
[Service]
# Clear previous ExecStart, otherwise systemd would try to run both.
ExecStart=
ExecStart=microshift run --multinode
EOF
sudo systemctl daemon-reload
sudo systemctl enable microshift.service
}

function start_microshift() {
sudo systemctl start microshift.service
}

function run_add_node_commands() {
if ! sudo microshift add-node --kubeconfig="${BOOTSTRAP_KUBECONFIG}"; then
echo "Error: Failed to add node using kubeconfig: ${BOOTSTRAP_KUBECONFIG}"
exit 1
fi
echo "Successfully added node using kubeconfig: ${BOOTSTRAP_KUBECONFIG}"
}

function get_node_ip_from_config() {
# Extract nodeIP from MicroShift running configuration and store in global variable
local node_ip=""

# Use microshift show-config to get the IP address of the node
node_ip=$(sudo microshift show-config 2>/dev/null | awk '/^\s*nodeIP\s*:/ {print $NF; exit}')

if [ -z "${node_ip}" ]; then
echo "Warning: nodeIP not found in MicroShift config"
exit 1
fi

NODE_ADDR="${node_ip}"
}

function copy_bootstrap_kubeconfig() {
local kubeconfig_source="/var/lib/microshift/resources/kubeadmin/${NODE_ADDR}/kubeconfig"
local kubeconfig_dest="${HOME}/kubeconfig-bootstrap"

if ! sudo test -f "${kubeconfig_source}"; then
echo "Error: Kubeconfig file not found at ${kubeconfig_source}"
exit 1
fi

if sudo cp "${kubeconfig_source}" "${kubeconfig_dest}"; then
sudo chown "$(whoami):" "${kubeconfig_dest}"
echo "Kubeconfig copied successfully to ${kubeconfig_dest}"
else
echo "Error: Failed to copy kubeconfig file"
exit 1
fi
}

function run_healthcheck() {
if ! sudo systemctl start greenboot-healthcheck; then
echo "Error: Failed to start greenboot-healthcheck service"
exit 1
fi

greenboot_status=$(systemctl show -p Result --value greenboot-healthcheck)
if [ "${greenboot_status}" != "success" ]; then
echo "Error: greenboot-healthcheck did not complete successfully (Result: ${greenboot_status})"
exit 1
fi
}

# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--bootstrap-kubeconfig)
if [ $# -lt 2 ]; then
echo "Error: --bootstrap-kubeconfig requires an argument"
usage
fi
BOOTSTRAP_KUBECONFIG="$2"
shift 2
;;
-h|--help)
usage
;;
*)
echo "Error: Unknown option '$1'"
usage
;;
esac
done

# Validate BOOTSTRAP_KUBECONFIG if provided
if [ -n "${BOOTSTRAP_KUBECONFIG}" ]; then
if [ ! -f "${BOOTSTRAP_KUBECONFIG}" ]; then
echo "Error: Bootstrap kubeconfig file '${BOOTSTRAP_KUBECONFIG}' does not exist"
exit 1
fi
echo "Using bootstrap kubeconfig: ${BOOTSTRAP_KUBECONFIG}"
fi

configure_system
configure_microshift
if [ -n "${BOOTSTRAP_KUBECONFIG}" ]; then
run_add_node_commands
run_healthcheck
else
start_microshift
fi
echo
echo "Node configuration completed"
if [ -z "${BOOTSTRAP_KUBECONFIG}" ]; then
copy_bootstrap_kubeconfig
echo
echo "To add other nodes to this cluster, copy the following kubeconfig file to other nodes:"
echo " ${HOME}/kubeconfig-bootstrap"
echo
echo "Then run the following command on each node you want to add:"
echo " $(basename "$0") --bootstrap-kubeconfig /path/to/kubeconfig"
fi
echo "Done"
Loading