ArgoCD & Traefik 2.x:如何在禁用 TLS 的情况下将 argocd-server 部署配置为 运行(放置 --insecure 标志的位置)

ArgoCD & Traefik 2.x: How to configure argocd-server Deployment to run with TLS disabled (where to put --insecure flag)

我们有一个使用 Traefik 作为入口控制器/CRD 和 ArgoCD 的设置。我们将 ArgoCD 安装到 our EKS setup as described in the Argo getting stared guide:

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

现在 as the docs state 正确配置 Traefik 的 IngressRoute 对象如下所示:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: argocd-server
  namespace: argocd
spec:
  entryPoints:
    - websecure
  routes:
    - kind: Rule
      match: Host(`argocd.tekton-argocd.de`)
      priority: 10
      services:
        - name: argocd-server
          port: 80
    - kind: Rule
      match: Host(`argocd.tekton-argocd.de`) && Headers(`Content-Type`, `application/grpc`)
      priority: 11
      services:
        - name: argocd-server
          port: 80
          scheme: h2c
  tls:
    certResolver: default
    

现在 there's a bug in the docs - 所以一定要删除 options: {} 让 Traefik 接受配置。

Traefik 在仪表板中显示一切正常:

但是,如果我们尝试在 https://argocd.tekton-argocd.de 访问 ArgoCD 仪表板,我们会得到多个 HTTP 307 重定向,最终无法访问仪表板。您可以在开发者工具中看到重定向:

正在搜索我们已经找到的解决方案 this issue 问题描述如下:

The problem is that by default Argo-CD handles TLS termination itself and always redirects HTTP requests to HTTPS. Combine that with an ingress controller that also handles TLS termination and always communicates with the backend service with HTTP and you get Argo-CD's server always responding with a redirects to HTTPS.

也画出解决方案:

So one of the solutions would be to disable HTTPS on Argo-CD, which you can do by using the --insecure flag on argocd-server.

但是我们如何配置 argocd-server 部署以将 --insecure 标志添加到 argocd-server 命令 - 因为它也是 stated inside the ArgoCD docs?

0。为什么使用 Kustomize 的声明式 ArgoCD 设置是配置自定义参数的好方法

关于如何配置 ArgoCD 有多种选择。一个很好的方法是使用声明式方法,这应该是默认的 Kubernetes-style。浏览 ArgoCD 文档有一个 additional configuration section where the possible flags of the ConfigMap argocd-cmd-params-cm can be found. The flags are described in argocd-cmd-params-cm.yaml。其中之一是标志 server.insecure

## Server properties
# Run server without TLS
server.insecure: "false"

https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml 附带的 argocd-server 部署将使用此参数,如果它在 argocd-cmd-params-cm ConfigMap 中定义。

为了以声明方式配置 ArgoCD 配置,the ArgoCD docs have a great section on how to do that with Kustomize. In fact the ArgoCD team itself uses this approach to deploy their own ArgoCD instances - a live deployment is available here https://cd.apps.argoproj.io/ and the configuration used can be found on GitHub

将此应用于我们的用例,我们需要将 ArgoCD 安装从简单地使用 kubectl apply -f 切换到 Kustomize-based 安装。 ArgoCD 文档也有 a section on how to do this。以下是简要步骤:

1.使用新文件创建一个 argocd/installation 目录 kustomization.yaml

我们略微增强了文档中提出的 kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - https://raw.githubusercontent.com/argoproj/argo-cd/v2.3.3/manifests/install.yaml

## changes to config maps
patchesStrategicMerge:
  - argocd-cmd-params-cm-patch.yml

namespace: argocd

由于文档声明

It is recommended to include the manifest as a remote resource and apply additional customizations using Kustomize patches.

我们使用 patchesStrategicMerge 配置密钥,其中包含我们需要创建的另一个名为 argocd-cmd-params-cm-patch.yml.

的新文件

2。创建一个新文件 argocd-cmd-params-cm-patch.yml

这个新文件只包含我们要在 ConfigMap 中更改的配置 argocd-cmd-params-cm:

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-cmd-params-cm
data:
  server.insecure: "true"

3。使用 Kustomization 文件安装 ArgoCD & kubectl apply -k

有一个单独的 kustomize CLI 可以安装,例如通过 brew install kustomize。但是由于 Kustomize 内置于 kubectl 中,我们只需要使用 kubectl apply -k 并将其指向我们新创建的 argocd/installation 目录,就像这样。我们还需要确保创建了 argocd 命名空间:

kubectl create namespace argocd --dry-run=client -o yaml | kubectl apply -f -    
kubectl apply -k argocd/installation

这将安装 ArgoCD 并配置 argocd-server 部署以根据需要使用 --insecure 标志来阻止 Argo 自行处理 TLS 终止并将该责任交给 Traefik。现在访问 https://argocd.tekton-argocd.de 应该会按预期打开 ArgoCD 仪表板:

您可以使用这个 traefik 规则:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: argocd-server
  namespace: argocd
spec:
  entryPoints:
    - websecure
  routes:
    - kind: Rule
      match: Host(`argocd.example.com`)
      priority: 10
      services:
        - name: argocd-server
          port: 80
    - kind: Rule
      match: Host(`argocd.example.com`) && Headers(`Content-Type`, `application/grpc`)
      priority: 11
      services:
        - name: argocd-server
          port: 80
          scheme: h2c
  tls: {}

使用 traefik 2.6.3 对我有用。

问题出在tls: {}