Skip to content

Commit e37c5a2

Browse files
committed
chore: add upgrade script and docs for it
This change adds an upgrade script which will follow the node upgrade process allowing operators to run a more controlled upgrade experience. Signed-off-by: Kevin Carter <[email protected]>
1 parent 4afef49 commit e37c5a2

File tree

2 files changed

+64
-28
lines changed

2 files changed

+64
-28
lines changed

docs/k8s-kubespray-upgrade.md

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,14 @@ Once the group variables are set, you can proceed with the upgrade execution.
2828

2929
Running an upgrade with Kubespray is fairly simple and executed via `ansible-playbook`.
3030

31-
Before running the playbook be sure to source your environment variables.
31+
* We recoommend running the upgrade from a control node that is not part of the cluster being upgraded. This helps to ensure that the upgrade process is not competing for resources with the cluster being upgraded.
3232

33-
``` shell
34-
source /opt/genestack/scripts/genestack.rc
35-
```
36-
37-
Change to the `kubespary` directory.
38-
39-
``` shell
40-
cd /opt/genestack/submodules/kubespray
41-
```
42-
43-
!!! note
44-
45-
When running an upgrade be sure to set the `kube_version` variable to the desired version number.
46-
47-
Now run the upgrade.
48-
49-
``` shell
50-
ansible-playbook upgrade-cluster.yml -e kube_version=${VERSION_NUMBER}
51-
```
52-
53-
!!! note
54-
55-
While the basic command could work, be sure to include any and all flags needed for your environment before running the upgrade.
56-
57-
### Running an unsafe upgrade
33+
* We also recommend running the upgrade within a `screen` or `tmux` session to help ensure that the upgrade process is not interrupted by network issues.
5834

59-
When running an upgrade, it is possible to force the upgrade by running the cluster playbook with the `upgrade_cluster_setup` flag set to **true**. This option is a lot faster, though does introduce the possibility of service disruption during the upgrade operation.
35+
The script to run the upgrade can be found within the `scripts/kubespray-major-upgrade.sh` file; however, the process is fairly straightforward.
6036

6137
``` shell
62-
ansible-playbook cluster.yml -e upgrade_cluster_setup=true -e kube_version=${VERSION_NUMBER}
38+
--8<-- "scripts/kubespray-major-upgrade.sh"
6339
```
6440

6541
### Upgrade Hangs

scripts/kubespray-major-upgrade.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
function gitRepoVersion() {
6+
# Returns the current git branch name, tag, or commit hash
7+
echo "$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match 2>/dev/null || git rev-parse HEAD)"
8+
}
9+
10+
echo "This script will help you upgrade your Kubernetes cluster managed by Kubespray."
11+
12+
# Ask the user for the target Kubernetes version
13+
read -p "Enter the target Kubernetes version number (e.g., 1.34.0): " VERSION_NUMBER
14+
15+
# Confirm the version number with the user
16+
echo "You have entered Kubernetes version number: ${VERSION_NUMBER}"
17+
18+
echo "Your current setup is as follows:"
19+
# Show checkout version of Genestack and the branch being used
20+
pushd /opt/genestack &>/dev/null
21+
echo "[+] Current Genestack version: $(gitRepoVersion) (SHA:$(git rev-parse HEAD))"
22+
popd &>/dev/null
23+
24+
pushd /opt/genestack/submodules/kubespray &>/dev/null
25+
echo "[+] Current Kubespray version: $(gitRepoVersion) (SHA:$(git rev-parse HEAD))"
26+
popd &>/dev/null
27+
28+
read -p "Is all of this correct? If yes type \`DOTHETHINGNOW\`: " CONFIRMATION
29+
30+
if [[ "$CONFIRMATION" != "DOTHETHINGNOW" ]]; then
31+
echo "Aborting. Please run the script again and enter the correct version number and confirmation."
32+
exit 1
33+
fi
34+
35+
set -v
36+
37+
# Load Genestack environment variables
38+
. /opt/genestack/scripts/genestack.rc
39+
40+
# Navigate to the Kubespray directory and perform the upgrade
41+
pushd /opt/genestack/submodules/kubespray &>/dev/null
42+
echo "Gathering cluster facts"
43+
ansible-playbook playbooks/facts.yml --become
44+
45+
echo "Upgrading cluster to Kubernetes version ${VERSION_NUMBER}"
46+
ansible-playbook upgrade-cluster.yml --become -e kube_version${VERSION_NUMBER} --limit "kube_control_plane:etcd"
47+
48+
echo "Upgrading worker nodes to Kubernetes version ${VERSION_NUMBER}"
49+
ansible-playbook upgrade-cluster.yml --become -e kube_version${VERSION_NUMBER} --limit "!kube_control_plane:!etcd"
50+
popd &>/dev/null
51+
52+
echo "Kubernetes cluster upgrade to version ${VERSION_NUMBER} completed successfully."
53+
54+
if command -v yq &>/dev/null; then
55+
echo "Updating Kubernetes version in inventory files"
56+
yq -i ".kube_version = \"${VERSION_NUMBER}\"" /etc/genestack/inventory/group_vars/k8s_cluster/k8s-cluster.yml
57+
else
58+
echo "yq command not found. Please install yq to update inventory files."
59+
echo "update the Kubernetes version in /etc/genestack/inventory/group_vars/k8s_cluster/k8s-cluster.yml manually to complete the upgrade."
60+
fi

0 commit comments

Comments
 (0)