Skip to content

04 公网接入(frp + 公网 Traefik)

访问链路

浏览器 https://ai-ear.cn:9020
  → 公网机 8.153.84.140 Traefik(entryPoint ep9020,TLS 证书 ai-ear.cn)
  → 127.0.0.1:19020(frps 隧道端口)
  → frp 隧道(token 认证,serverAddr 8.153.84.140:7000)
  → 宿主机 192.168.122.1 frpc 代理 gitlab-web-30080
  → RKE2 集群 NodePort 192.168.122.28:30080
  → Service gitlab-web-nodeport:80 → webservice workhorse:8181(×2)

git ssh ssh://git@ai-ear.cn:19022
  → 公网机 frps 直出 19022(不经 Traefik,纯 TCP)
  → 宿主机 frpc 代理 gitlab-ssh-30022
  → NodePort 192.168.122.28:30022 → gitlab-shell×2

公网机 443 已被主站(ai-ear.cn apex → 本地 nginx)占用,故沿用 ep9xxx 高端口惯例。

1) 宿主机(192.168.122.1,即本机)frpc

/etc/frp/frpc.toml 追加:

toml
# GitLab Web (RKE2 NodePort 30080) → 公网 19020 → Traefik ep9020
[[proxies]]
name = "gitlab-web-30080"
type = "tcp"
localIP = "192.168.122.28"
localPort = 30080
remotePort = 19020

# GitLab SSH (RKE2 NodePort 30022) → 公网 19022 直出
[[proxies]]
name = "gitlab-ssh-30022"
type = "tcp"
localIP = "192.168.122.28"
localPort = 30022
remotePort = 19022
bash
sudo systemctl restart frpc

2) 公网机 Traefik(8.153.84.140)

静态配置 /etc/traefik/traefik.yaml entryPoints 增加:

yaml
  ep9020:
    address: ":9020"

动态配置 /etc/traefik/dynamic.yaml 增加:

yaml
    svc-9020:
      entryPoints: [ep9020]
      rule: "Host(`ai-ear.cn`)"
      service: svc-19020
      tls: {}

services 段增加:

yaml
    svc-19020:
      loadBalancer:
        servers:
          - url: "http://127.0.0.1:19020"
bash
systemctl restart traefik        # 新增 entryPoint 需重启(秒级中断,主站瞬断)
ss -tlnp | grep -E '9020|19020|19022'

3) GitLab 侧配置(已在 values 中内置)

  • global.hosts.gitlab.name: ai-ear.cnglobal.hosts.https: trueglobal.hosts.tls.enabled: false(TLS 在 Traefik 终止)
  • gitlab.yml 覆盖模板加 port: 9020deploy/gitlab/30-gitlab-yml-override-cm.yaml)→ 页面跳转/clone URL 均为 https://ai-ear.cn:9020
  • global.hosts.ssh: ai-ear.cn + global.shell.port: 19022 → SSH clone URL ssh://git@ai-ear.cn:19022

4) 验证

bash
curl -k -o /dev/null -w "%{http_code}\n" https://ai-ear.cn:9020/users/sign_in   # 200
ssh -p 19022 -o StrictHostKeyChecking=no git@ai-ear.cn   # 期望: Welcome to GitLab, @<user>!(需先绑定 key)

内网兜底(不经过公网):

bash
curl -s -o /dev/null -w "%{http_code}\n" http://192.168.122.31:30080/users/sign_in
git clone ssh://git@192.168.122.31:30022/<group>/<proj>.git