ArgoCD 域名访问配置指南:内网HTTP与外网HTTPS两种场景实践
实际应用场景
在企业环境中,我们经常需要通过域名访问 ArgoCD 控制台,而不是直接使用 IP 地址。本文详细介绍了如何在内网环境下使用 HTTP 协议,以及在外网环境下使用 HTTPS 协议访问 ArgoCD 的完整配置方案。
概述
ArgoCD Server 默认使用 HTTPS 协议提供服务,通常可以通过 https://IP+NodePort 访问前端界面。但在实际生产环境中,我们更希望使用友好且固定的域名来访问 ArgoCD。本文将详细介绍两种不同场景下的配置方法:
- 内网环境下的 HTTP 域名访问
- 外网环境下的 HTTPS 域名访问
内网 HTTP 域名访问配置
问题背景
当使用 APISIX 进行转发时,虽然前端页面可以正常显示,但登录后会重定向到首页。这是因为 ArgoCD 默认启用安全连接,而 HTTP 协议无法满足安全验证要求。
解决方案
要使内网环境支持 HTTP 域名访问,需要对 ArgoCD Server 进行特殊配置。
ArgoCD Server 配置
在 ArgoCD Server 的 Deployment 中,在 command 参数末尾添加 --insecure 标志,允许通过域名进行 HTTP 登录:
apiVersion: apps/v1
kind: Deployment
metadata:
name: argocd-server
spec:
template:
spec:
containers:
- name: argocd-server
command:
- /argocd-server
# ... 其他配置 ...
- --insecure # 关键参数:启用非安全模式
APISIX 路由配置
配置 APISIX 以支持 HTTP 协议转发:
{
"uri": "/*",
"name": "cd.inhowlaisi.com",
"methods": [
"GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"HEAD",
"OPTIONS",
"CONNECT",
"TRACE",
"PURGE"
],
"host": "cd.inhowlaisi.com",
"upstream": {
"nodes": [
{
"host": "192.168.109.88",
"port": 32417,
"weight": 1
}
],
"timeout": {
"connect": 6,
"send": 6,
"read": 6
},
"type": "roundrobin",
"scheme": "http",
"pass_host": "pass",
"keepalive_pool": {
"idle_timeout": 60,
"requests": 1000,
"size": 320
}
},
"enable_websocket": true,
"status": 1
}
参数说明表
| 参数 | 含义 | 可选值 | 默认值 |
|---|---|---|---|
uri | 匹配路径 | /* 表示匹配所有路径 | - |
scheme | 上游协议 | http, https | - |
pass_host | 是否透传 Host 头 | pass, rewrite | - |
enable_websocket | 是否启用 WebSocket | true, false | false |
外网 HTTPS 域名访问配置
配置步骤
外网环境下的 HTTPS 访问配置相对简单,无需修改 ArgoCD Server 本身:
- 保持 ArgoCD Server 配置不变(不添加
--insecure参数) - 在 APISIX 上配置域名 SSL 证书
- 配置相应的路由规则
APISIX 路由配置
以下是外网 HTTPS 访问的 APISIX 配置示例:
{
"uri": "/*",
"name": "cd.howlaisi.com",
"methods": [
"GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"HEAD",
"OPTIONS",
"CONNECT",
"TRACE",
"PURGE"
],
"host": "cd.howlaisi.com",
"plugins": {
"proxy-rewrite": {
"scheme": "https"
},
"redirect": {
"http_to_https": true
}
},
"upstream": {
"nodes": [
{
"host": "10.147.18.203",
"port": 8084,
"weight": 1
}
],
"timeout": {
"connect": 600,
"send": 600,
"read": 600
},
"type": "roundrobin",
"scheme": "https",
"pass_host": "pass",
"keepalive_pool": {
"idle_timeout": 60,
"requests": 1000,
"size": 320
}
},
"enable_websocket": true,
"status": 1
}
插件说明
| 插件名称 | 功能 | 参数说明 |
|---|---|---|
proxy-rewrite | 重写代理请求 | scheme: 设置上游协议为 https |
redirect | 重定向配置 | http_to_https: 将 HTTP 请求重定向到 HTTPS |
总结
通过以上配置,我们可以在不同环境下灵活地使用域名访问 ArgoCD:
- 内网环境:通过添加
--insecure参数并配合 APISIX HTTP 转发 - 外网环境:直接通过 APISIX 配置 HTTPS 证书和路由
这种配置方式既保证了内外网环境的一致性,又满足了安全访问的需求,是企业级 GitOps 实践的重要组成部分。
参考文档
更多技术文章,请访问 好来斯博客
评论区