受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。
2条答案
按热度按时间6vl6ewon1#
我会放弃这种部署Traefik的方法。
官方的方式更容易部署和管理:
1.安装舵图
1.露出 Jmeter 板
1.访问http://127.0.0.1:9000/dashboard/
shstlldc2#
感谢您发送编修。你教了我如何简化我在网上的搜索。
基于' Helm 安装'的方式,我发现3种方式通过Traefik v2路由流量.我希望你能欣赏在互联网上搜索小时的结果。
1.通过入口
例如:
2.通过IngressRoute(traefik.io/v1alpha1)
您首先必须从Traefik站点加载CRD。
例如:
3.通过traefik.containo.us/v1alpha1.
您首先必须从Traefik站点加载CRD。
举个例子: