kubernetes - 当同名部署、svcs 等在同一命名空间中运行时,强制部署 helm release

标签 kubernetes kubernetes-helm

当已经有部署、svc 等以相同的名称运行时,如何第一次部署 helm 版本。
有什么方法可以导入运行中的配置,而这不是由 helm 处理的吗?
或者删除同名对象是第一次部署 helm 发布的唯一解决方案?(因为我不想更改发布名称,因为它会中断微服务之间的通信)
删除对象会导致停机,我想避免这种情况。
使用相同名称进行部署时出错:

Error: rendered manifests contain a resource that already exists. Unable to continue with install: Service "abc" in namespace "default" 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 "abc"; annotation validation error: missing key "meta.helm.sh/release-namespace": must be set to "default"
他们还有其他方法吗?
谢谢

最佳答案

解决错误消息和问题的一部分:

How to deploy the helm release for the first time when there's already the deployment, svc, etc. running with the same name.


您不能使用 Helm 部署不是由 Helm 创建的资源。它将为您提供与您遇到的相同的消息。您可以注释 的现有资源不是 由 Helm 添加以“导入”现有资源并对其采取行动。 请先尝试在测试环境上运行您的工作负载,然后再尝试,因为它可能会重新部署一些资源。
关于如何注释资源已经有类似的答案:
  • Stackoverflow.com: Answers: Use Helm 3 for existing resources deployed with kubectl

  • see this feature of helm3 Adopt resources into release with correct instance and managed-by labels

    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.kubernetes.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.

    In order to allow an existing resource to be adopted by Helm, add release metadata and the managed-by label:

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


    假设以下情况:
  • Deployment在 Helm 之外创建(示例如下)。
  • 具有等效模板的 Helm Chart Deploymenttemplates/ (下面的例子)。

  • 下面创建 Deployment没有 Helm :
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx
            ports:
            - containerPort: 80
    
    假设上述文件与 kubectl apply 一起使用它也驻留在 templates/目录(模板化),您将收到以下错误(当您尝试运行 $ helm install release_name . 时):
    Error: rendered manifests contain a resource that already exists. Unable to continue with install: Deployment "nginx" in namespace "default" exists and cannot be imported into the current release: ... 
    
    通过运行我链接的答案中提到的脚本,您可以为 Helm 注释和标记您的资源,以免产生提到的错误消息。
    之后你可以运行 $ helm install release_name .并为您的资源提供所需的更改。

    其他资源:
  • Jacky-jiang.medium.com: Import existing resources in Helm3
  • 关于kubernetes - 当同名部署、svcs 等在同一命名空间中运行时,强制部署 helm release,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63016165/

    相关文章:

    nodes - OpenStack 上 Kubernetes 中节点(minion)的水平自动缩放

    amazon-web-services - 如何解决 cloudflare CNAME 记录上的 521 错误

    kubernetes - 库伯内斯 : How to get the external IP of the service or the DNS attached to it in route53

    docker - GitLab Runner 使用 Helm Chart - 指向私有(private)仓库

    Helm 中的 PostgreSQL : initdbScripts Parameter

    python - 通过 Python 替换 Kubernetes 中的作业

    kubernetes - kubectl apply -f可在PC上运行,但不能在Gitlab Runner中运行

    Terraform - 如何创建 GKE 集群并安装 Helm Charts?

    kubernetes - 序列化 Pod/Helm Chart 的部署

    kubernetes nginx ingress server-snippet 注释没有生效