简体   繁体   English

对使用 kubectl 部署的现有资源使用 Helm 3

[英]Use Helm 3 for existing resources deployed with kubectl

We used to deploy kube.netes resources using the normal kubectl command for services, deployments, configmap...etc.我们曾经使用普通的 kubectl 命令来部署 kube.netes 资源,用于服务、部署、configmap 等。 Now we need to start using Helm 3 and integrate it to our pipelines, but when I try to run the helm upgrade command, it's giving the below error: Error: rendered manifests contain a resource that already exists. Unable to continue with install: existing resource conflict: namespace: default现在我们需要开始使用 Helm 3 并将其集成到我们的管道中,但是当我尝试运行 helm upgrade 命令时,出现以下错误: Error: rendered manifests contain a resource that already exists. Unable to continue with install: existing resource conflict: namespace: default Error: rendered manifests contain a resource that already exists. Unable to continue with install: existing resource conflict: namespace: default

So, these resources were never created with helm as it was created normally with kubcetl apply command.因此,这些资源从未使用 helm 创建,因为它通常是使用 kubcetl apply 命令创建的。

Just need to know how to used Helm in the pipeline without re-create the k8s resources.只需要知道如何在管道中使用 Helm 而无需重新创建 k8s 资源。 As the only workaround I found to get it working was to delete the resources and re-deploy them using Helm.我发现让它工作的唯一解决方法是删除资源并使用 Helm 重新部署它们。

Below is the command I tried: helm upgrade --atomic --debug --install --force test.下面是我试过的命令: helm upgrade --atomic --debug --install --force test.

Thanks, Aly谢谢,阿里

see this feature of helm3 Adopt resources into release with correct instance and managed-by labels看到 helm3 的这个特性采用正确的实例和管理标签将资源发布

Helm will no longer error when attempting to create a resource that already exists in the target cluster if the existing resource has the correct meta.helm.sh/release-name and meta.helm.sh/release-namespace annotations, and matches the label selector app.kube.netes.io/managed-by=Helm.如果现有资源具有正确的 meta.helm.sh/release-name 和 meta.helm.sh/release-namespace 注释,并且与 label 匹配,则在尝试创建目标集群中已存在的资源时,Helm 将不再出错选择器 app.kube.netes.io/managed-by=Helm。 This facilitates zero-downtime migrations to Helm 3 for managing existing deployments, and allows Helm to "adopt" existing resources that it previously created.这有助于零停机时间迁移到 Helm 3 以管理现有部署,并允许 Helm “采用”它之前创建的现有资源。

In order to allow an existing resource to be adopted by Helm, add release metadata and the managed-by label:为了允许 Helm 采用现有资源,请添加发布元数据和 managed-by label:

KIND=deployment
NAME=my-app-staging
RELEASE=staging
NAMESPACE=default
kubectl -n $NAMESPACE annotate $KIND $NAME meta.helm.sh/release-name=$RELEASE
kubectl -n $NAMESPACE annotate $KIND $NAME meta.helm.sh/release-namespace=$NAMESPACE
kubectl -n $NAMESPACE label $KIND $NAME app.kubernetes.io/managed-by=Helm

Honestly while FL3SH's answer is what you are looking for... the best choice would be to just delete your k8s resources.老实说,虽然 FL3SH 的答案正是您正在寻找的……最好的选择是只删除您的 k8s 资源。 There are some exceptions to this:有一些例外:

  1. Your helm chart is trying to create a namespace (eg default)您的掌舵图正在尝试创建名称空间(例如默认)
  2. Your deployments cannot be down for any time您的部署在任何时候都不能停机
  3. Your helm chart has persistent volume claims您的 helm chart 具有持续的体积声明

You could add all helm labels/annotations.您可以添加所有 helm 标签/注释。 You can check all helm labels and anther components with helm template .您可以使用helm template检查所有 helm 标签和花药组件。 Then you could use kubectl label or kubectl annotate to add missing labels/annotations.然后你可以使用kubectl labelkubectl annotate添加缺失的标签/注释。

I personally never tried it, because is too much work and in the end, you have to recreate pods with new labels if they are managed by deployment/statefulset.我个人从未尝试过,因为工作量太大,最后,如果它们由 deployment/statefulset 管理,则必须使用新标签重新创建 pod。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将已部署的 helm 版本与最新版本进行比较 - Compare a deployed helm version to latest version Kubectl apply 命令用于更新现有服务资源 - Kubectl apply command for updating existing service resource 有什么方法可以使用现有的 AWS ELB 在 Kube.netes 中进入 airflow helm chart? - Is there any way to use existing AWS ELB for ingress in Kubernetes for airflow helm chart? 如何在 helm 图表中使用 if 条件 - How to use if condition in helm chart 引用 Cloudformation 中的现有资源 - Reference existing resources in Cloudformation 仅使用 ResourceGroupTaggingAPI 获取现有资源 - Only get existing resources with ResourceGroupTaggingAPI Terraform 想替换现有资源 - Terraform wants to replace existing resources Helm 2.x - 使用子图作为模板 - Helm 2.x - use subchart as template 在 EKS 上部署 Istio bookinfo 应用程序后,`kubectl get svc` 显示应用程序的服务,但 `Kubectl get pods` 返回 `no resources found` - After deploying Istio bookinfo application on EKS, `kubectl get svc` displays the app's services but `Kubectl get pods` returns `no resources found` 将现有 CloudFormation 资源大规模导入 CDK - Importing existing CloudFormation resources into CDK at scale
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM