Last active
February 13, 2024 22:52
-
-
Save agup006/ca196912ddfd8e385544c0ee96e464e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Taken from https://docs.k3s.io/installation/airgap#prepare-the-images-directory-and-k3s-binary | |
runAsRoot mkdir -p /var/lib/rancher/k3s/agent/images/ "$BINARY_DIR"/ | |
runAsRoot cp -fv "$CALYPTIA_ROOT/k3s/k3s-airgap-images-$ARCH.tar" /var/lib/rancher/k3s/agent/images/ | |
runAsRoot chmod a+r /var/lib/rancher/k3s/agent/images/*.tar | |
local k3s_exe=k3s | |
if [[ "$ARCH" != "amd64" ]]; then | |
k3s_exe="k3s-$ARCH" | |
fi | |
runAsRoot cp -f "$CALYPTIA_ROOT/k3s/$k3s_exe" "$BINARY_DIR"/ | |
runAsRoot chmod 755 "$BINARY_DIR/$k3s_exe" | |
# Add a default route if none exists | |
if ! command -v ip &> /dev/null ; then | |
warn "Unable to check for default route automatically, ensure one is provided" | |
elif ! ip route show 2>&1 | grep -q "default" ; then | |
if setupDummyRoute ; then | |
info "Set up dummy route" | |
else | |
warn "Unable to set up dummy route automatically, ensure a default route is provided" | |
fi | |
fi | |
runAsRoot chmod 755 "$CALYPTIA_ROOT/k3s/install.sh" | |
# Install | |
INSTALL_K3S_SKIP_DOWNLOAD=true \ | |
INSTALL_K3S_SKIP_SELINUX_RPM=true \ | |
INSTALL_K3S_SELINUX_WARN=true \ | |
INSTALL_K3S_BIN_DIR="$BINARY_DIR" \ | |
"$CALYPTIA_ROOT/k3s/install.sh" \ | |
--write-kubeconfig-mode 644 \ | |
--prefer-bundled-bin \ | |
--kubelet-arg='eviction-hard=imagefs.available<1%,nodefs.available<1%' \ | |
--kubelet-arg='eviction-minimum-reclaim=imagefs.available=1%,nodefs.available=1%' \ | |
--cluster-cidr "$CLUSTER_CIDR" \ | |
--service-cidr "$SERVICE_CIDR" \ | |
--cluster-dns "$CLUSTER_DNS" \ | |
--service-node-port-range "$SERVICE_NODE_PORT_RANGE" \ | |
--cluster-domain "$CLUSTER_DOMAIN" | |
runAsRoot mkdir -p /root/.kube/ | |
runAsRoot cp -f /etc/rancher/k3s/k3s.yaml /root/.kube/config | |
echo "export KUBECONFIG=/etc/rancher/k3s/k3s.yaml" | runAsRoot tee -a /etc/environment > /dev/null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
# Helper script to move K3S data to another location - not intended to be run multiple times. | |
NEW_LOCATION=${NEW_LOCATION:-$1} | |
# use sudo if we are not already root | |
SUDO=sudo | |
if [[ $(id -u) -eq 0 ]]; then | |
SUDO='' | |
fi | |
if [[ -d "$NEW_LOCATION"/k3s ]]; then | |
echo "Existing data already found at $NEW_LOCATION/k3s" | |
exit 1 | |
fi | |
if [[ -d "$NEW_LOCATION"/k3s-pods ]]; then | |
echo "Existing data already found at $NEW_LOCATION/k3s-pods" | |
exit 1 | |
fi | |
if [[ -d "$NEW_LOCATION"/k3s-rancher ]]; then | |
echo "Existing data already found at $NEW_LOCATION/k3s-rancher" | |
exit 1 | |
fi | |
"$SUDO" systemctl stop k3s | |
"$SUDO" sh -c /usr/local/bin/k3s-killall.sh | |
"$SUDO" mkdir -p "$NEW_LOCATION" | |
"$SUDO" mv /run/k3s "$NEW_LOCATION"/k3s | |
"$SUDO" mv /var/lib/kubelet/pods "$NEW_LOCATION"/k3s-pods | |
"$SUDO" mv /var/lib/rancher "$NEW_LOCATION"/k3s-rancher | |
"$SUDO" ln -s "$NEW_LOCATION"/k3s/ /run/k3s | |
"$SUDO" ln -s "$NEW_LOCATION"/k3s-pods/ /var/lib/kubelet/pods | |
"$SUDO" ln -s "$NEW_LOCATION"/k3s-rancher/ /var/lib/rancher | |
"$SUDO" chmod -R a+r "$NEW_LOCATION"/k3s*/ | |
"$SUDO" systemctl start k3s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment