Last active
January 23, 2026 20:28
-
-
Save jmarhee/6159b5304e6289bd2360bd0d2533dc5d 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
| # Set store/env-specific k3s_version in pillar | |
| {% set version = pillar.get('k3s_version', 'v1.31.1+k3s1') %} | |
| # Set target datastore for additional disk equipped nodes | |
| {% set datadir = pillar.get('k3s_datadir', '/var/lib/rancher') %} | |
| {% set base_url = 'https://github.com/k3s-io/k3s/releases/download/' ~ version %} | |
| /tmp/k3s-upgrade: | |
| file.directory: | |
| - makedirs: True | |
| k3s_download_and_validate: | |
| cmd.run: | |
| - name: | | |
| cd /tmp/k3s-upgrade | |
| curl -sfL {{ base_url }}/k3s -o k3s | |
| curl -sfL {{ base_url }}/k3s-airgap-images-amd64.tar.zst -o airgap-images.tar.zst | |
| curl -sfL {{ base_url }}/sha256sum-amd64.txt -o checksums.txt | |
| curl -sfL https://get.k3s.io -o install.sh && chmod +x install.sh | |
| BINARY_EXPECTED=$(grep "k3s$" checksums.txt | cut -d' ' -f1) | |
| BINARY_ACTUAL=$(sha256sum k3s | cut -d' ' -f1) | |
| IMAGES_EXPECTED=$(grep "k3s-airgap-images-amd64.tar.zst$" checksums.txt | cut -d' ' -f1) | |
| IMAGES_ACTUAL=$(sha256sum airgap-images.tar.zst | cut -d' ' -f1) | |
| if [ "$BINARY_EXPECTED" != "$BINARY_ACTUAL" ]; then | |
| echo "ERROR: K3S binary checksum mismatch!" | |
| exit 1 | |
| fi | |
| if [ "$IMAGES_EXPECTED" != "$IMAGES_ACTUAL" ]; then | |
| echo "ERROR: Air-gap images checksum mismatch!" | |
| exit 1 | |
| fi | |
| echo "All checksums validated successfully" | |
| - unless: test -f /tmp/k3s-upgrade/k3s && test -f /tmp/k3s-upgrade/airgap-images.tar.zst && test -f /tmp/k3s-upgrade/install.sh | |
| - require: | |
| - file: /tmp/k3s-upgrade | |
| k3s_stage_and_stop: | |
| cmd.run: | |
| - name: | | |
| mkdir -p /usr/local/bin | |
| mkdir -p {{ datadir }}/k3s/agent/images | |
| cp /tmp/k3s-upgrade/k3s /usr/local/bin/k3s | |
| chmod +x /usr/local/bin/k3s | |
| cp /tmp/k3s-upgrade/airgap-images.tar.zst {{ datadir }}/k3s/agent/images/ | |
| systemctl stop k3s || true | |
| echo "Files staged and service stopped" | |
| - require: | |
| - cmd: k3s_download_and_validate | |
| k3s_install_and_start: | |
| cmd.run: | |
| - name: | | |
| export INSTALL_K3S_SKIP_DOWNLOAD=true | |
| export INSTALL_K3S_SKIP_START=true | |
| export INSTALL_K3S_BIN_DIR=/usr/local/bin | |
| /tmp/k3s-upgrade/install.sh | |
| systemctl enable k3s | |
| systemctl start k3s | |
| echo "K3S install completed and service started" | |
| - require: | |
| - cmd: k3s_stage_and_stop | |
| k3s_verify_and_cleanup: | |
| cmd.run: | |
| - name: | | |
| sleep 15 | |
| CURRENT_VERSION=$(/usr/local/bin/k3s --version | head -1 | awk '{print $3}') | |
| if [ "$CURRENT_VERSION" = "{{ version }}" ]; then | |
| echo "SUCCESS: K3S upgraded to {{ version }}" | |
| timeout 30 /usr/local/bin/k3s kubectl get nodes --kubeconfig=/etc/rancher/k3s/k3s.yaml | |
| echo "Cluster is healthy" | |
| rm -rf /tmp/k3s-upgrade | |
| else | |
| echo "ERROR: Expected {{ version }}, got $CURRENT_VERSION" | |
| exit 1 | |
| fi | |
| - require: | |
| - cmd: k3s_install_and_start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment