Skip to content

Instantly share code, notes, and snippets.

@bgulla
Last active September 23, 2022 14:15
Show Gist options
  • Save bgulla/103f02521b90c38ba9975a1f3733edfe to your computer and use it in GitHub Desktop.
Save bgulla/103f02521b90c38ba9975a1f3733edfe to your computer and use it in GitHub Desktop.
Example scripts to get Rancher & Rancher Kubernetes Distributions in an air-gap environment

Rancher | Airgap all teh things.

k3s

k3s with private (authenticated) registry

### Assumptions:
# - Registry: You have a private registry (ex: harbor.air-gap.dev) pre-seeded with required images
# - File Dependencies:
#   - SELinuxRPM: k3s requires an selinux rpm. You can grab it ahead of time from here: https://github.com/k3s-io/k3s-selinux/releases
#   - k3s binary: (example) https://github.com/k3s-io/k3s/releases/download/v1.24.4%2Bk3s1/k3s

### Install

# create the rancher directory
mkdir -p /etc/rancher/k3s

# write out a standard config file
echo 'write-kubeconfig-mode: "0644"' > /etc/rancher/k3s/config.yaml

# create registries.yaml with credentials of private container registry
cat <<EOT >> /etc/rancher/k3s/registries.yaml
configs:
  "harbor.air-gap.dev":
    auth:
      username: admin
      password: Harbor12345
EOT

# copy the required k3s binary into place
cp ./k3s /usr/local/bin/k3s

# install the required SELINUX rpm dependency
yum localinstall -y k3s-selinux-1.2-2.el7.noarch.rpm

# lets go k3s! clap clap, clap clap clap
K3S_VERSION="v1.22.5+k3s2" \
  INSTALL_K3S_SKIP_SELINUX_RPM=true \
  INSTALL_K3S_SKIP_DOWNLOAD=true \
  K3S_SYSTEM_DEFAULT_REGISTRY="harbor.air-gap.dev/carbide" \
  sh install.sh

echo sleeping
sleep 3

KUBECONFIG=/etc/rancher/k3s/k3s.yaml /usr/local/bin/kubectl get pods -A -w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment