Use o helm-mapkubeapis para substituir APIs do Kubernetes obsoletas ou removidas nos metadados de uma release do Helm por versões compatíveis. Essa ferramenta reduz a carga de trabalho e os riscos, garantindo a estabilidade do serviço. Este tópico descreve como atualizar a versão da API de um recurso do Kubernetes com o helm-mapkubeapis para fazer uma atualização in-place.
Cenários
A partir do Kubernetes 1.22, novas versões de API foram introduzidas para objetos de recursos do Kubernetes. Ao atualizar charts do Helm, as seguintes mensagens de erro podem ser exibidas. Para corrigir esses problemas, atualize as versões de API dos recursos do Kubernetes.
-
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"
Pré-requisitos
Instale o Go 1.13 ou posterior. Para mais informações, consulte Go 1.13.
Etapa 1: Baixe e instale o helm-mapkubeapis
Execute o comando a seguir para baixar e instalar o 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
Etapa 2: Atualize a versão da API
Este exemplo demonstra como atualizar a versão da API do recurso MutatingWebhookConfiguration na release ack-node-local-dns.
-
Execute o comando a seguir para visualizar o histórico de versões da API do recurso MutatingWebhookConfiguration:
vim ${GOPATH}/src/github.com/helm-mapkubeapis/config/Map.yamlSaída esperada:
- deprecatedAPI: "apiVersion: admissionregistration.k8s.io/v1beta1\nkind: MutatingWebhookConfiguration" newAPI: "apiVersion: admissionregistration.k8s.io/v1\nkind: MutatingWebhookConfiguration" deprecatedInVersion: "v1.17" removedInVersion: "v1.20"A saída indica que a versão da API do recurso MutatingWebhookConfiguration será atualizada de v1beta1 para v1 no Kubernetes 1.20 e em versões posteriores.
-
Verifique se a versão da API na release ack-node-local-dns precisa de atualização executando o comando a seguir:
helm mapkubeapis ack-node-local-dns --namespace kube-system --dry-runSaída esperada:
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.Se a saída retornar
Found deprecated or removed Kubernetes API, será necessário atualizar a versão da API. -
Atualize a versão da API do recurso MutatingWebhookConfiguration de v1beta1 para v1 com o comando a seguir:
helm mapkubeapis ack-node-local-dns --namespace kube-systemSaída esperada:
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.A mensagem
Release 'ack-node-local-dns' with deprecated or removed APIs updated successfully to new version.na saída confirma a atualização da versão da API do recurso MutatingWebhookConfiguration de v1beta1 para v1.