【问题标题】:How to expose traefik v2 dashboard in k3d/k3s via configuration?如何通过配置在 k3d/k3s 中公开 traefik v2 仪表板?
【发布时间】:2021-07-28 17:39:50
【问题描述】:

*交叉发布到k3d github discussionsRancher forums 中的线程和traefik's community discussion board

Tutorials from 2020 指编辑 traefik configmap。去哪儿了?

traefik installation instructions 指的是几种暴露仪表板的方法:

  1. 这有效,但不是持久的:使用 1-time 命令kubectl -n kube-system port-forward $(kubectl -n kube-system get pods --selector "app.kubernetes.io/name=traefik" --output=name) 9000:9000

  2. 我无法让它工作:创建一个“IngressRoute”yaml 文件并将其应用到集群。这可能是由于 Klipper LB 和/或我的无知。

traefik 部署没有使用配置映射

对于 2-server、2-agent 集群...kubectl -n kube-system describe deploy traefik 不显示任何 configmap:

  Volumes:
   data:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:     
    SizeLimit:  <unset>
   tmp:
    Type:               EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:             
    SizeLimit:          <unset>
  Priority Class Name:  system-cluster-critical

没有“traefik”配置图

而且,kubectl get -n kube-system cm 显示:

NAME                                 DATA   AGE
chart-content-traefik                0      28m
chart-content-traefik-crd            0      28m
chart-values-traefik                 1      28m
chart-values-traefik-crd             0      28m
cluster-dns                          2      28m
coredns                              2      28m
extension-apiserver-authentication   6      28m
k3s                                  0      28m
k3s-etcd-snapshots                   0      28m
kube-root-ca.crt                     1      27m
local-path-config                    4      28m

traefik pod 没有使用配置映射

描述 pod 也不会出现任何问题。 kubectl -n kube-system describe pod traefik-.... 也没有配置映射。

Traefik 端口正在使用,但没有响应

但是,我确实看到了使用端口的 traefik pod 的参数:

      --entryPoints.traefik.address=:9000/tcp
      --entryPoints.web.address=:8000/tcp
      --entryPoints.websecure.address=:8443/tcp

但是,这些端口并未暴露。所以,我尝试使用kubectl port-forward pods/traefik-97b44b794-r9srz 9000:9000 8000:8000 8443:8443 -n kube-system --address 0.0.0.0 进行端口转发,但是当我使用curl -v localhost:9000(或8000 或8443)和curl -v localhost:9000/dashboard 时,我得到“404 Not Found”。

将终端连接到 traefik 后,我发现本地端口已打开,但似乎没有任何响应:

/ $ netstat -lntu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
tcp        0      0 :::8443                 :::*                    LISTEN      
tcp        0      0 :::8000                 :::*                    LISTEN      
tcp        0      0 :::9000                 :::*                    LISTEN      
/ $ wget localhost:9000
Connecting to localhost:9000 ([::1]:9000)
wget: server returned error: HTTP/1.1 404 Not Found
/ $ wget localhost:8000
Connecting to localhost:8000 ([::1]:8000)
wget: server returned error: HTTP/1.1 404 Not Found
/ $ wget localhost:8443
Connecting to localhost:8443 ([::1]:8443)
wget: server returned error: HTTP/1.1 404 Not Found

版本

k3d version v4.4.7
k3s version v1.21.2-k3s1 (default)

【问题讨论】:

  • 我认为你需要在 pod 上做kubectl describe
  • 谢谢@P....我已经用那里的发现更新了这个问题。我看到了潜在的端口。也许我只需要弄清楚如何暴露它们......
  • 您好,我遇到了同样的问题,我认为它不起作用,但事实证明我需要在 URL 中附加 /dashboard/。尝试检查http://localhost:9000/dashboard/#/http/routers 是否反映了来自dashboard.yml 的新应用入口路由。如果是,那么你只需要访问http://&lt;domain&gt;/dashboard/

标签: kubernetes traefik configmap k3s k3d


【解决方案1】:

我找到了解决方案,希望有人能尽快找到更好的解决方案

  1. 您需要从您的 PC 控制您的 k3s 集群,而不是通过 ssh 连接到主节点,因此将 /etc/rancher/k3s/k3s.yaml 添加到您的本地 ~/.kube/config(以便在最后一步中将端口转发到您的 PC)
  2. 现在获取您的 pod 名称,如下所示:

kubectl get pod -n kube-system

并搜索traefik-something-somethingElse 我的是traefik-97b44b794-bsvjn

  1. 现在需要本地电脑上的这部分

kubectl port-forward traefik-97b44b794-bsvjn -n kube-system 9000:9000

  1. 在您最喜欢的浏览器中获取http://localhost:9000/dashboard/,并且不要忘记第二个斜线
  2. 享受仪表板

请注意,您必须先在/var/lib/rancher/k3s/server/manifests/traefik.yaml 中通过添加启用仪表板

dashboard:
  enabled: true

【讨论】:

  • 能否请您将重点放在 don't forget the last (/) slash 上的第 4 步加粗,因为我浪费了半个小时,因为我没有从乞讨中看到这一点。谢谢
  • 您确定dashboard 是顶级元素吗?根据values.yaml,它是pilotingressRoute 的孩子...
  • @Marc 它实际上是一个顶级元素。莫名其妙我知道。
【解决方案2】:

Jakub 的回答非常好。但不幸的是,如果 k3s 重新启动,配置会被重置。根据k3s docs,如果您创建一个名为/var/lib/rancher/k3s/server/manifests/traefik-config.yaml 的自定义文件,k3s 的 traefik 将使用这个新配置自动更新并使用它的值。这是我所拥有的:

apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
  name: traefik
  namespace: kube-system
spec:
  valuesContent: |-
    dashboard:
      enabled: true
    ports:
      traefik:
        expose: true # this is not recommended in production deployments, but I want to be able to see my dashboard locally
    logs:
      access:
        enabled: true

使用此设置,您可以跳过port-forwarding,直接转到http://localhost:9000/dashboard/

【讨论】:

  • 经过测试,它可以工作并且持久。您也可以使用http://traefik.localhost/dashboard 访问仪表板谢谢。
【解决方案3】:

对于当前最新版本的k3s(1.21.4):

  1. 根据 traefik 的安装指南 (https://doc.traefik.io/traefik/getting-started/install-traefik/#exposing-the-traefik-dashboard),使用正确的 CRD 内容创建 dashboard.yaml,然后运行 kubectl apply -f dashboard.yaml

  2. 创建 DNS 记录或修改主机名的主机文件 - 为您在上一步中设置的 IP 映射

【讨论】:

    猜你喜欢
    • 2022-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    相关资源
    最近更新 更多