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。