Kubernetes 的 MySQL Operator 手冊  /  升級 MySQL Operator

第 4 章 升級 MySQL Operator

升級 MySQL Operator

套用 MySQL Operator 最新發佈的 CRD,以建立取代舊有部署的新 MySQL Operator 部署。舊的 Operator 會在新 Operator 啟動並就緒後終止,這不應導致停機。

kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-crds.yaml
kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-operator.yaml
注意

這只會更新 MySQL Operator,而不會更新相關聯的 MySQL InnoDB Cluster。

在 URL 中使用 trunk 表示 Kubernetes 的最新 MySQL Operator 版本,因為 Github 會在發佈時更新。或者,將 URL 中的 trunk 替換為特定的標記發佈版本

升級 MySQL InnoDB Cluster

假設您已升級 MySQL Operator。

我們建議使用 MySQL Shell 的 checkForServerUpgrade() 公用程式,確認 MySQL InnoDB Cluster 已準備好升級。此範例建立一個暫時的 8.4.0 pod (包含 MySQL Shell 8.4.0),以檢查名為 mycluster 的 InnoDB Cluster 是否與升級至 MySQL 8.4.0 相容

$> kubectl run --image=container-registry.oracle.com/mysql/community-operator:8.4.0-2.1.3 \
    --rm -it mysh -- mysqlsh -uroot -p -hmycluster -- util checkForServerUpgrade

...

If you don't see a command prompt, try pressing enter.
******
Save password for 'root@mycluster'? [Y]es/[N]o/Ne[v]er (default No): N
The MySQL server at mycluster:33060, version 8.3.0 - MySQL Community Server -
GPL, will now be checked for compatibility issues for upgrade to MySQL 8.4.0.
To check for a different target server version, use the targetVersion option...

1) Issues reported by 'check table x for upgrade' command
  No issues found

Errors:   0
Warnings: 0
Notices:  0

No known compatibility errors or issues were found.
Session ended, resume using 'kubectl attach mysh -c mysh -i -t' command when the pod is running
pod "mysh" deleted

常見的升級方法是修補 MySQL 伺服器版本。例如,這會將名為 mycluster 的 MySQL InnoDB Cluster 的 MySQL 伺服器版本更新為 8.4.0

kubectl patch ic mycluster -p '{"spec": { "version": "8.4.0" } }' --type=merge

對 MySQL InnoDB Cluster 的 spec.version 進行更新會更新以下項目

  • 每個 MySQL 伺服器,以滾動更新方式進行

    更新 MySQL InnoDB Cluster 會啟動 MySQL 伺服器的滾動重新啟動;升級會依名稱中最高值到最低值的順序替換 MySQL 伺服器。這可能會導致主要伺服器多次容錯移轉,具體取決於目前和指派的主要伺服器。

  • MySQL Router 至指定的 spec.version,除非 spec.router.version 也明確設定在修補程式中

  • 每個伺服器的 MySQL Sidecar 容器至已安裝的 MySQL Operator 版本

  • MySQL Shell 至指定的 spec.version

MySQL InnoDB Cluster 在升級過程中仍可使用,但相關的重新啟動可能會中斷現有的連線。