在Windows上使用Traefik v2.5基本设置的Kubernetes-无法访问Traefik Jmeter 板和第二个组件

alen0pnh  于 2023-10-17  发布在  Kubernetes
关注(0)|答案(2)|浏览(122)

this nice article的启发,我尝试在Kubernetes上设置一个非常基本的Traefik环境。我知道这是最低限度的设置,没有安全,等等。我们在Docker Swarm上使用Traefik很多年了,现在想转向Kubernetes。
简而言之:这是一个基本的traefik yml文件,包含了deployment、service和ingressroute:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: traefik
spec:
  selector:
    matchLabels:
      app: traefik
  replicas: 1
  template:
    metadata:
      labels:
        app: traefik
    spec:
      containers:
      - name: traefik
        image: traefik:v2.5
        ports:
        - name: http
          containerPort: 80
        - name: admin
          containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: traefik
spec:
  selector:
    app: traefik
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: http
  - name: admin
    port: 8080
    protocol: TCP
    targetPort: admin
  type: NodePort
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: traefik-web-ui
spec:
  entryPoints:
    - web
  routes:
  - match: PathPrefix(`/dashboard`)
    kind: Rule
    services:
    - name: traefik
      port: 8080

NgInx yaml是:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - name: http
          containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  selector:
    app: nginx
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: http
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: nginx
spec:
  entryPoints:
    - web
  routes:
  - match: PathPrefix(`/nginx`)
    kind: Rule
    services:
    - name: nginx
      port: http

应用我做:

$ kubectl apply -f traefik.yaml
$ kubectl apply -f nginx.yaml

一切都在运行:

浏览到http://localhost/dashboard、http://localhost/dashboard/、http://localhost/nginx或http://localhost/nginx/都不会给出结果,但会给出ERR_CONNECTION_REFUSED。

6vl6ewon

6vl6ewon1#

我会放弃这种部署Traefik的方法。
官方的方式更容易部署和管理:
1.安装舵图

helm repo add traefik https://traefik.github.io/charts
helm repo update
helm install traefik traefik/traefik

1.露出 Jmeter 板

kubectl port-forward $(kubectl get pods --selector "app.kubernetes.io/name=traefik" --output=name) 9000:9000

1.访问http://127.0.0.1:9000/dashboard/

shstlldc

shstlldc2#

感谢您发送编修。你教了我如何简化我在网上的搜索。
基于' Helm 安装'的方式,我发现3种方式通过Traefik v2路由流量.我希望你能欣赏在互联网上搜索小时的结果。

1.通过入口

例如:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: whoami-ingress
spec:
  rules:
    - http:
        paths:
          - path: /whoami
            pathType: Prefix
            backend:
              service:
                name: whoami
                port:
                  name: web

2.通过IngressRoute(traefik.io/v1alpha1)

您首先必须从Traefik站点加载CRD。
例如:

apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: nginx
  namespace: default
spec:
  entryPoints:
    - web
  routes:
    - match: PathPrefix(`/nginx`)
      kind: Rule
      middlewares:
        - name: nginx-stripprefix
      services:
        - name: nginx
          port: 80
---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: nginx-stripprefix
spec:
  stripPrefix:
    prefixes:
      - /nginx

3.通过traefik.containo.us/v1alpha1.

您首先必须从Traefik站点加载CRD。
举个例子:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: nginx3
  namespace: default
spec:
  entryPoints:
    - web
  routes:
    - kind: Rule
      match: PathPrefix(`/third`)
      middlewares:
        - name: nginx3-stripprefix
      services:
        - name: nginx
          port: 80
    - kind: Rule
      match: PathPrefix(`/fourth`)
      middlewares:
        - name: nginx4-pathreplace
      services:
        - name: nginx
          port: 80
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: nginx3-stripprefix
spec:
  stripPrefix:
    prefixes:
      - /third
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: nginx4-pathreplace
spec:
  replacePathRegex:
    regex: ^/fourth/(.*)
    replacement: /third/$1

相关问题