首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未能打开插件清单/.traefik.yml:打开/.traefik.yml:没有这样的文件或目录

未能打开插件清单/.traefik.yml:打开/.traefik.yml:没有这样的文件或目录
EN

Stack Overflow用户
提问于 2022-03-18 08:00:53
回答 1查看 233关注 0票数 0

我是特雷菲克的新手。我正在尝试开发一个插件,并使用Docker将它“连接”到我的and服务器上。我使用码头构图进行开发。当我试图运行Docker撰写时,我遇到了以下错误:

代码语言:javascript
复制
/dev/echo-docker-compose $ docker-compose up --build
Starting echo-server ... done
Recreating traefik   ... done
Attaching to echo-server, traefik
echo-server    | Echo server listening on port 8080.
traefik        | time="2022-03-18T07:40:11Z" level=info msg="Configuration loaded from flags."
traefik        | time="2022-03-18T07:40:11Z" level=info msg="Traefik version 2.6.1 built on 2022-02-14T16:50:25Z"
traefik        | time="2022-03-18T07:40:11Z" level=debug msg="Static configuration loaded {\"global\":{\"checkNewVersion\":true},\"serversTransport\":{\"maxIdleConnsPerHost\":200},\"entryPoints\":{\"traefik\":{\"address\":\":8080\",\"transport\":{\"lifeCycle\":{\"graceTimeOut\":\"10s\"},\"respondingTimeouts\":{\"idleTimeout\":\"3m0s\"}},\"forwardedHeaders\":{},\"http\":{},\"udp\":{\"timeout\":\"3s\"}},\"web\":{\"address\":\":80\",\"transport\":{\"lifeCycle\":{\"graceTimeOut\":\"10s\"},\"respondingTimeouts\":{\"idleTimeout\":\"3m0s\"}},\"forwardedHeaders\":{},\"http\":{},\"udp\":{\"timeout\":\"3s\"}}},\"providers\":{\"providersThrottleDuration\":\"2s\",\"docker\":{\"watch\":true,\"endpoint\":\"unix:///var/run/docker.sock\",\"defaultRule\":\"Host(`{{ normalize .Name }}`)\",\"swarmModeRefreshSeconds\":\"15s\"}},\"api\":{\"insecure\":true,\"dashboard\":true},\"log\":{\"level\":\"DEBUG\",\"format\":\"common\"},\"pilot\":{\"dashboard\":true},\"experimental\":{\"localPlugins\":{\"traefik-plugin-example\":{\"moduleName\":\"github.com/usergithub/traefik-plugin-example\"}}}}"
traefik        | time="2022-03-18T07:40:11Z" level=info msg="\nStats collection is disabled.\nHelp us improve Traefik by turning this feature on :)\nMore details on: https://doc.traefik.io/traefik/contributing/data-collection/\n"
traefik        | 2022/03/18 07:40:11 traefik.go:79: command traefik error: 1 error occurred:
traefik        |        * failed to open the plugin manifest plugins-local/src/github.com/usergithub/traefik-plugin-example/.traefik.yml: open plugins-local/src/github.com/usergithub/traefik-plugin-example/.traefik.yml: no such file or directory
traefik        | 
traefik        | 
traefik exited with code 1

我想我可以得出结论,这个错误的原因是它找不到.traefik.yml文件,这是很明显的。但是,我已经在那个目录里有文件了。

这是我的完整目录结构

代码语言:javascript
复制
dev/plugins-local/
    └── src
        └── github.com
            └── traefik
                └── traefik-plugin-example
                    ├── plugin.go
                    ├── plugin_test.go
                    ├── .traefik.yml
                    ├── go.mod
                    ├── Dockerfile
                    ├── Makefile
    ├── traefik
    ├── traefik-plugin.go
    ├── rules-plugin.go
dev/echo-docker-compose/
    └── docker-compose.yml
    └── cmd
        └── ....

出于某些原因,我认为Docker撰写不懂.traefik.yml。但是,当我尝试从./traefik --configfile traefik-plugin.yml运行dev/plugins-local时,情况也是一样的。它还在无法读取.traefik.yml的地方抛出相同的错误。

有人知道怎么解决这个问题吗?

以下是有关守则:

服务器回购

代码语言:javascript
复制
# dev/echo-docker-compose/.env
PLUGIN_MODULE=github.com/usergithub/traefik-plugin-example
PLUGIN_NAME=traefik-plugin-example

# dev/echo-docker-compose/docker-compose.yml
version: "3.3"

services:
  traefik:
    image: "traefik:v2.6"
    container_name: "traefik"
    command:
      - "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--experimental.localPlugins.${PLUGIN_NAME}.moduleName=${PLUGIN_MODULE}"
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"

  echo-server:
    image: "usergithub/echo-server"
    container_name: "echo-server"
    labels:
      - "traefik.enable=true"
      # The domain the service will respond to
      - "traefik.http.routers.echoserver.rule=Host(`echoserver.localhost`)"
      # Allow request only from the predefined entry point named "web"
      - "traefik.http.routers.echoserver.entrypoints=web"
      - "traefik.http.routers.echoserver.entrypoints=web"
      - "traefik.http.routers.echoserver.middlewares=echoserver-demo"
      - "traefik.http.middlewares.echoserver-demo.plugin.${PLUGIN_NAME}.headers.DoesPluginWork=YES"
      - "traefik.http.routers.echoserver.tls.certresolver=default"

插件回购

代码语言:javascript
复制
# dev/plugins-local/traefik-plugin.go
pilot:
    token: "token"

api:
  dashboard: true
  insecure: true

experimental:
  localPlugins:
    traefik-plugin-example:
      moduleName: github.com/usergithub/traefik-plugin-example

entryPoints:
  http:
    address: ":8000"
    forwardedHeaders:
      insecure: true
  
providers:
  file:
    filename: rules-plugin.yaml 
代码语言:javascript
复制
# dev/plugins-local/src/github.com/usergithub/traefik-plugin-example/.traefik.yml
displayName: Traefik Example Plugin
type: middleware

import: github.com/usergithub/traefik-plugin-example

summary: 'Write plugin'

testData:
  userAgent:
    - Firefox
    - Mozilla/5.0
EN

回答 1

Stack Overflow用户

发布于 2022-03-18 18:22:02

根据文档,“您的项目的根必须有一个描述插件的.traefik.yml文件”,根据我在您的目录结构中看到的,您将.traefik.yml放置在"src“文件夹中,其中有几个子文件夹。

将文件放在正确的位置可以解决问题,请注意go.mod也应该位于根目录(插件必须使用git标记)。

作为额外的资源,您可以检查演示插件

此外,对于任何阅读者,我必须添加一个免责声明,因为Traefik插件仍然是一个“实验特性”,应该谨慎使用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71523956

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档