Argo CD 项目中的 Ingress 配置详解
前言
在现代 Kubernetes 环境中,Ingress 是暴露服务到集群外部的重要方式。Argo CD 作为一个 GitOps 持续交付工具,其 API 服务器同时运行 gRPC 服务(供 CLI 使用)和 HTTP/HTTPS 服务(供 UI 使用)。本文将深入探讨如何在 Argo CD 中配置各种 Ingress 控制器,帮助您根据实际需求选择最适合的方案。
Argo CD 服务端口概述
Argo CD 服务器通过 argocd-server 服务对象暴露以下端口:
- 443 端口:gRPC/HTTPS 服务
- 80 端口:HTTP 服务(会自动重定向到 HTTPS)
主流 Ingress 控制器配置方案
1. Ambassador 边缘栈配置
Ambassador 可以作为 Kubernetes Ingress 控制器,支持自动 TLS 终止和路由功能。
关键配置步骤
-
禁用 Argo CD 服务器 TLS:
- 在
argocd-server
部署中添加--insecure
标志 - 或者在
argocd-cmd-params-cm
ConfigMap 中设置server.insecure: "true"
- 在
-
两种路由方式选择:
方案一:基于主机的路由
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
name: argocd-server-ui
namespace: argocd
spec:
host: argocd.example.com
prefix: /
service: https://argocd-server:443
方案二:基于路径的路由
需要配置非根路径(如 /argo-cd
),并在 argocd-server
部署中添加 --rootpath=/argo-cd
标志。
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
name: argocd-server
namespace: argocd
spec:
prefix: /argo-cd
rewrite: /argo-cd
service: https://argocd-server:443
2. Contour Ingress 控制器配置
Contour 可以在边缘终止 TLS 入口流量。
部署建议
- 可以部署两个 Contour 实例:一个用于内部访问,一个用于外部访问
- 内部部署通过
contour-internal
注解识别 - 外部部署通过
contour-external
注解识别
典型配置示例
apiVersion: projectcontour.io/v1
kind: HTTPProxy
metadata:
name: argocd-server
namespace: argocd
spec:
ingressClassName: contour
virtualhost:
fqdn: path.to.argocd.io
tls:
secretName: wildcard-tls
routes:
- conditions:
- prefix: /
- header:
name: Content-Type
contains: application/grpc
services:
- name: argocd-server
port: 80
protocol: h2c
3. Nginx Ingress 控制器配置
方案一:SSL 透传
适用于需要在同一主机名上同时支持 gRPC 和 HTTP/HTTPS 的场景。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: argocd-server-ingress
namespace: argocd
annotations:
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
spec:
ingressClassName: nginx
rules:
- host: argocd.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: argocd-server
port:
name: https
方案二:在 Ingress 控制器终止 SSL
需要为 HTTP 和 gRPC 分别创建 Ingress 资源,使用不同的子域名。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: argocd-server-http-ingress
namespace: argocd
annotations:
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
spec:
ingressClassName: nginx
rules:
- host: argocd.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: argocd-server
port:
name: http
4. Traefik 配置
Traefik 的优势在于可以在同一端口上同时终止 TCP 和 HTTP 连接。
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: argocd-server
namespace: argocd
spec:
entryPoints:
- websecure
routes:
- kind: Rule
match: Host(`argocd.example.com`)
services:
- name: argocd-server
port: 80
- kind: Rule
match: Host(`argocd.example.com`) && Header(`Content-Type`, `application/grpc`)
services:
- name: argocd-server
port: 80
scheme: h2c
tls:
certResolver: default
5. AWS 负载均衡器配置
ALB 配置要点
- 为 gRPC 流量创建单独的服务
- 使用
alb.ingress.kubernetes.io/conditions
注解路由 gRPC 流量
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
alb.ingress.kubernetes.io/conditions.argogrpc: |
[{"field":"http-header","httpHeaderConfig":{"httpHeaderName": "Content-Type", "values":["application/grpc"]}}]
name: argocd
namespace: argocd
spec:
rules:
- host: argocd.argoproj.io
http:
paths:
- path: /
backend:
service:
name: argogrpc
port:
number: 443
6. Istio 配置
关键配置步骤
- 使用 Kustomize 修改 Argo CD 部署,添加
--insecure
和--basehref
参数 - 创建 Istio Gateway 和 VirtualService 资源
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: argocd-gateway
namespace: argocd
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
hosts:
- "*"
tls:
credentialName: argocd-server-tls
mode: SIMPLE
总结
本文详细介绍了 Argo CD 在各种 Ingress 控制器下的配置方法。选择哪种方案取决于您的具体需求:
- 如果需要简单部署,Traefik 或 Nginx SSL 透传是不错的选择
- 如果需要高级路由功能,可以考虑 Ambassador 或 Contour
- 在 AWS 环境中,ALB 提供了原生的 gRPC 支持
- Istio 适合已经使用服务网格的环境
无论选择哪种方案,都要注意安全配置,特别是 TLS 证书的管理。希望本文能帮助您在 Argo CD 中实现安全、高效的 Ingress 配置。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考