helm-mapkubeapis外掛程式可用於更新Helm發布版本中繼資料,以替換到期或已移除的K8s API,幫您減少工作量的同時,還可降低風險確保服務的平穩運行。本文介紹如何通過helm-mapkubeapis外掛程式原地升級apiVersion。
使用情境
由於1.22及以上版本的叢集資來源物件可能有多個apiVersion與歷史版本不同,當Chart升級時,會出現如下資源已存在的異常提示。此時,可通過升級歷史的apiVersion版本解決。
rendered manifests contain a new resource that already exists. Unable to continue with update: existing resource conflict: kind: MutatingWebhookConfiguration, namespace: , name: mse-pilot-ack-mse-pilot
Error: UPGRADE FAILED: rendered manifests contain a resource that already exists. Unable to continue with update: MutatingWebhookConfiguration "ack-node-local-dns-admission-controller" in namespace "" exists and cannot be imported into the current release: invalid ownership metadata; label validation error: missing key "app.kubernetes.io/managed-by": must be set to "Helm"; annotation validation error: missing key "meta.helm.sh/release-name": must be set to "ack-node-local-dns"; annotation validation error: missing key "meta.helm.sh/release-namespace": must be set to "kube-system"
前提條件
已安裝Go v1.13及以上版本。更多資訊,請參見Go v1.13。
步驟一:下載安裝helm-mapkubeapis外掛程式
執行以下命令,下載安裝helm-mapkubeapis外掛程式。
mkdir -p ${GOPATH}/src/github.com
cd $_
git clone git@github.com:helm/helm-mapkubeapis.git
cd helm-mapkubeapis
make
export HELM_LINTER_PLUGIN_NO_INSTALL_HOOK=true
helm plugin install <your_path>/helm-mapkubeapis
步驟二:升級apiVersion
本文以Release ack-node-local-dns為例,介紹如何升級MutatingWebhookConfiguration資源的apiVersion。
執行以下命令,查看資源對應的apiVersion版本變更資訊。
vim ${GOPATH}/src/github.com/helm-mapkubeapis/config/Map.yaml
部分預期輸出:
- deprecatedAPI: "apiVersion: admissionregistration.k8s.io/v1beta1\nkind: MutatingWebhookConfiguration" newAPI: "apiVersion: admissionregistration.k8s.io/v1\nkind: MutatingWebhookConfiguration" deprecatedInVersion: "v1.17" removedInVersion: "v1.20"
預期輸出表明,MutatingWebhookConfiguration資源在v1.20版本後將從v1beta1升級至v1。
執行以下命令,查看Release中是否有apiVersion需要升級。
helm mapkubeapis ack-node-local-dns --namespace kube-system --dry-run
預期輸出:
2022/01/18 14:21:57 NOTE: This is in dry-run mode, the following actions will not be executed. 2022/01/18 14:21:57 Run without --dry-run to take the actions described below: 2022/01/18 14:21:57 2022/01/18 14:21:57 Release 'ack-node-local-dns' will be checked for deprecated or removed Kubernetes APIs and will be updated if necessary to supported API versions. 2022/01/18 14:21:57 Get release 'ack-node-local-dns' latest version. 2022/01/18 14:21:57 Check release 'ack-node-local-dns' for deprecated or removed APIs... 2022/01/18 14:21:57 Found deprecated or removed Kubernetes API: "apiVersion: admissionregistration.k8s.io/v1beta1 kind: MutatingWebhookConfiguration" Supported API equivalent: "apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration" 2022/01/18 14:21:57 Finished checking release 'ack-node-local-dns' for deprecated or removed APIs. 2022/01/18 14:21:57 Deprecated or removed APIs exist, updating release: ack-node-local-dns. 2022/01/18 14:21:57 Map of release 'ack-node-local-dns' deprecated or removed APIs to supported versions, completed successfully.
預期輸出表明,Release中存在
Found deprecated or removed Kubernetes API
,表示有apiVersion需要升級。執行以下命令,將對應Release的MutatingWebhookConfiguration資源的apiVersion從v1beta1升級至v1。
helm mapkubeapis ack-node-local-dns --namespace kube-system
預期輸出:
2022/01/18 14:31:38 Release 'ack-node-local-dns' will be checked for deprecated or removed Kubernetes APIs and will be updated if necessary to supported API versions. 2022/01/18 14:31:38 Get release 'ack-node-local-dns' latest version. 2022/01/18 14:31:38 Check release 'ack-node-local-dns' for deprecated or removed APIs... 2022/01/18 14:31:38 Found deprecated or removed Kubernetes API: "apiVersion: admissionregistration.k8s.io/v1beta1 kind: MutatingWebhookConfiguration" Supported API equivalent: "apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration" 2022/01/18 14:31:38 Finished checking release 'ack-node-local-dns' for deprecated or removed APIs. 2022/01/18 14:31:38 Deprecated or removed APIs exist, updating release: ack-node-local-dns. 2022/01/18 14:31:38 Set status of release version 'ack-node-local-dns.v9' to 'superseded'. 2022/01/18 14:31:38 Release version 'ack-node-local-dns.v9' updated successfully. 2022/01/18 14:31:38 Add release version 'ack-node-local-dns.v10' with updated supported APIs. 2022/01/18 14:31:38 Release version 'ack-node-local-dns.v10' added successfully. 2022/01/18 14:31:38 Release 'ack-node-local-dns' with deprecated or removed APIs updated successfully to new version. 2022/01/18 14:31:38 Map of release 'ack-node-local-dns' deprecated or removed APIs to supported versions, completed successfully.
預期輸出表明,Release中存在
Release 'ack-node-local-dns' with deprecated or removed APIs updated successfully to new version.
,表示對應資源已從v1beta1升級至v1。