简图(逻辑)
[边缘主机们] <--tailscale(100.x)--> [阿里云主机(云K8s节点)] <—NodePort—> [K8s服务/Pod]
\\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Headscale 控制面 (http://124.124.124.124:8899)目录以
/data/workspace/software/headscale为例。
docker-compose.yml(固定镜像版本,避免 latest 漂移)services:
headscale:
image: headscale/headscale:0.26.1
command: ["serve"]
restart: unless-stopped
ports:
- "8899:8899"
volumes:
- "/data/workspace/software/headscale/config:/etc/headscale"
- "/data/workspace/software/headscale/data:/var/lib/headscale"config/config.yaml(v0.26.1 正确字段;仅 IPv4;关 MagicDNS)server\_url: http://124.124.124.124:8899
listen\_addr: 0.0.0.0:8899
metrics\_listen\_addr: 127.0.0.1:9090
database:
type: sqlite
sqlite:
path: /var/lib/headscale/db.sqlite
# v0.26 必需:TS v2 协议的 Noise 私钥(文件首次启动会自动生成)
noise:
private\_key\_path: /var/lib/headscale/noise\_private.key
prefixes:
v4: 100.64.0.0/10
dns:
magic\_dns: false
override\_local\_dns: false # 先关掉覆盖;若设 true 就必须提供 nameservers.global
# 先不拉官方 DERP,避免访问外网
derp:
urls:
- https://controlplane.tailscale.com/derpmap/default
auto\_update\_enabled: true
update\_frequency: 24h
paths: []
acl:
policy\_path: /etc/headscale/acl.jsonconfig/acl.json(双向放行;可继续细化){
"tagOwners": {
"tag:cloud": ["\*"],
"tag:edge": ["\*"],
"tag:supcon": ["\*"]
},
"acls": [
{ "action": "accept", "src": ["tag:edge"], "dst": ["tag:cloud:\*"] },
{ "action": "accept", "src": ["tag:cloud"], "dst": ["tag:edge:\*"] }
]
}cd /data/workspace/software/headscale
chmod 0777 ./data
docker compose up -d
docker compose logs -f headscale | tail -n 100
# 看到生成 noise 私钥 + 监听 0.0.0.0:8899 即成功v0.26.1 的
--user要传 数值 ID。你的default为 1(已确认)。
cd /data/workspace/software/headscale
# 幂等创建一个 ns,名字叫 default(已经存在会忽略)
docker compose exec -T headscale headscale users create default || true
# 查看用户对应的id,后面创建key的时候需要用 --user 后跟的就是这个id
docker compose exec -T headscale headscale users list
# 云端 key(可复用,100年)
docker compose exec -T headscale \
headscale preauthkeys create --user 1 --reusable --expiration 876000h --tags tag:cloud -o json \
| python3 -c 'import sys,json; print(json.load(sys.stdin)["key"])' \
| tee cloud\_authkey.txt
# 边缘 key(可复用,100年)
docker compose exec -T headscale \
headscale preauthkeys create --user 1 --reusable --expiration 876000h --tags tag:edge,tag:supcon -o json \
| python3 -c 'import sys,json; print(json.load(sys.stdin)["key"])' \
| tee edge\_authkey.txt
# 查看/确认
docker compose exec -T headscale headscale preauthkeys list --user 1两端都装,用同一台 Headscale,即可进入同一 100.x 私网。
curl -fsSL https://tailscale.com/install.sh | sudo sh
sudo systemctl enable --now tailscaled
sudo tailscale up \
--login-server=http://124.124.124.124:8899 \
--authkey "$(cat /data/workspace/software/headscale/cloud\_authkey.txt)" \
--hostname hos-cloud-master \
--advertise-tags=tag:cloud \
--ssh=false
tailscale ip -4
tailscale statuscurl -fsSL https://tailscale.com/install.sh | sudo sh
sudo systemctl enable --now tailscaled
sudo tailscale up \
--login-server=http://112.124.10.230:8899 \
--authkey "<把 edge\_authkey.txt 里那串粘过来>" \
--hostname edge-supcon-robot01 \
--advertise-tags=tag:edge,tag:supcon \
--accept-routes --ssh=false
tailscale ip -4
tailscale status说明:
--ssh=false关闭 Tailscale SSH,避免 ACL 提示;不影响隧道连通。
# 在云主机查 100.x
tailscale ip -4 # 假设是 100.64.0.1curl -i http://100.64.0.1:30080/health(你容器是 host 模式,所以端口直接暴露在边缘宿主上。)
tailscale ping -c 5 hos-cloud-master
tailscale ping -c 5 edge-supcon-robot01原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。