创建 yaml 配置文件 Secret
- 官方配置样例
- headplane agent 组件
vim /tmp/config.headscale.yam- 官方样例注释很全就不贴了
vim /tmp/config.headplane.yaml- headscale.url 格式
- http://headscale-svc.tailscale.svc.cluster.local:80
kubectl create secret generic headscale-secret \ -n tailscale \ --from-file=noise_private.key=/tmp/noise_private.key \ --from-file=config.headscale.yaml=/tmp/config.headscale.yaml \ --from-file=config.headplane.yaml=/tmp/config.headplane.yaml- 如果是迁移配置的话 noise_private.key 也需要迁移
- 但实测仍需要重新认证一遍
kubectl get secret -n tailscale headscale-secret -o yaml
kubectl get secret -n tailscale headscale-secret -o jsonpath='{.data.config\.headscale\.yaml}' | base64 --decode- 查看解码后的情况
rm /tmp/{config.headscale.yaml,config.headscale.yaml}
创建 configmap 挂载 derp yaml 配置文件
- 官方样例
vim ~/.config/k3s/cm.headscale.derp.yaml
kubectl apply -f ~/.config/k3s/cm.headscale.derp.yaml
kubectl get -n tailscale cm/headscale-config -o yaml
部署 longhorn RWO PVC 作为主机卷
kubectl get -n longhorn-system storageclass -o wide- 可自行修改 storageClassName 为自定义的 longhorn 存储类
- 这里采用默认的 longhorn
vim ~/.config/k3s/pvc.longhorn.headscale.yaml
kubectl apply -f ~/.config/k3s/pvc.longhorn.headscale.yaml
创建 headscale 服务账户用于 headplane k8s 集成
- headplane kubertenes 集成源码
vim ~/.config/k3s/sa.headplane.integration.yaml
kubectl apply -f ~/.config/k3s/sa.headplane.integration.yaml
部署 headscale 和对应 traefik 路由
vim ~/.config/k3s/statefulset.headscale.yaml
- 通过 initContainers 来传递配置文件
- 配置服务账户启用 headplane k8s 集成
- serviceAccountName: headplane
- shareProcessNamespace: true
kubectl apply -f ~/.config/k3s/statefulset.headscale.yaml
kubectl describe -n kube-system deploy/traefik | grep namespace- 检查 traefik 是否已经为 bangumi 命名空间提供路由
添加 DNS 记录到 /etc/hosts
- 获取 traefik 的 external-ip
kubectl get svc -n kube-system traefik -o wide
查看运行情况并访问 headplane webui
kubectl get -n tailscale statefulset/headscale
kubectl logs -n tailscale statefulset/headscale -c headscale
kubectl logs -n tailscale statefulset/headscale -c headplane
kubectl logs -n kube-system deployment/traefik --since 1h -f
- curl 测试首页
curl -vk https://headscale.traefik.cluster.local/healthcurl -vk https://headplane.traefik.cluster.local
- 登录 headplane 需要生成 headscale api
kubectl -n tailscale exec -i -t headscale-0 -c headscale -- headscale apikey create --expiration 40d
- Author:白鸟3
- URL:https://blog.kun2peng.top/operation/k8s_headscale_headplane
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
