-
Notifications
You must be signed in to change notification settings - Fork 61
chore: add upgrade script and docs for it #1341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -e | ||
|
|
||
| function gitRepoVersion() { | ||
| # Returns the current git branch name, tag, or commit hash | ||
| echo "$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match 2>/dev/null || git rev-parse HEAD)" | ||
| } | ||
|
|
||
| echo "This script will help you upgrade your Kubernetes cluster managed by Kubespray." | ||
|
|
||
| # Ask the user for the target Kubernetes version | ||
| read -p "Enter the target Kubernetes version number (e.g., 1.34.0): " VERSION_NUMBER | ||
|
|
||
| # Confirm the version number with the user | ||
| echo "You have entered Kubernetes version number: ${VERSION_NUMBER}" | ||
|
|
||
| echo "Your current setup is as follows:" | ||
| # Show checkout version of Genestack and the branch being used | ||
| pushd /opt/genestack &>/dev/null | ||
| echo "[+] Current Genestack version: $(gitRepoVersion) (SHA:$(git rev-parse HEAD))" | ||
| popd &>/dev/null | ||
|
|
||
| pushd /opt/genestack/submodules/kubespray &>/dev/null | ||
| echo "[+] Current Kubespray version: $(gitRepoVersion) (SHA:$(git rev-parse HEAD))" | ||
| popd &>/dev/null | ||
|
|
||
| read -p "Is all of this correct? If yes type \`DOTHETHINGNOW\`: " CONFIRMATION | ||
|
|
||
| if [[ "$CONFIRMATION" != "DOTHETHINGNOW" ]]; then | ||
| echo "Aborting. Please run the script again and enter the correct version number and confirmation." | ||
| exit 1 | ||
| fi | ||
|
|
||
| set -v | ||
|
|
||
| # Load Genestack environment variables | ||
| . /opt/genestack/scripts/genestack.rc | ||
|
|
||
| # Navigate to the Kubespray directory and perform the upgrade | ||
| pushd /opt/genestack/submodules/kubespray &>/dev/null | ||
| echo "Gathering cluster facts" | ||
| ansible-playbook playbooks/facts.yml --become | ||
|
|
||
| echo "Upgrading cluster to Kubernetes version ${VERSION_NUMBER}" | ||
| ansible-playbook upgrade-cluster.yml --become -e kube_version${VERSION_NUMBER} --limit "kube_control_plane:etcd" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We discussed upgrade-cluster.yml will attempt to drain the node(s) vs cluster.yml with the -e var will not. What's the preference? The documentation mentions that "components will be upgraded in the same order they were installed", which does present an issue with kubelet being upgraded prior to kube-apiserver. Kubelet does still run on these control plane nodes, so I wonder if there is some logic that could be added to the playbooks to ensure ordering or a validation that kube-apiserver is >= new kubelet prior to upgrade.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should look into that. |
||
|
|
||
| echo "Upgrading worker nodes to Kubernetes version ${VERSION_NUMBER}" | ||
| ansible-playbook upgrade-cluster.yml --become -e kube_version${VERSION_NUMBER} --limit "!kube_control_plane:!etcd" | ||
| popd &>/dev/null | ||
|
|
||
| echo "Kubernetes cluster upgrade to version ${VERSION_NUMBER} completed successfully." | ||
|
|
||
| if command -v yq &>/dev/null; then | ||
| echo "Updating Kubernetes version in inventory files" | ||
| yq -i ".kube_version = \"${VERSION_NUMBER}\"" /etc/genestack/inventory/group_vars/k8s_cluster/k8s-cluster.yml | ||
| else | ||
| echo "yq command not found. Please install yq to update inventory files." | ||
| echo "update the Kubernetes version in /etc/genestack/inventory/group_vars/k8s_cluster/k8s-cluster.yml manually to complete the upgrade." | ||
| fi | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we pass the k8s desired version here, will the playbook ignore whats in group_vars/k8s_cluster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. but the script updates the group vars as soon as the upgrade is complete.