[英]How do I forward port 80 to a service port 3000 using Traefik on K3s?
這是關於Traefik的,而不是關於它與K3s Kubernetes 一起工作的方式,所以請不要給我一般的 K8s 答案。
我有一個簡單的 k3s 部署和服務,看起來像這樣......
apiVersion: v1
kind: Service
metadata:
labels:
app: hello-express
name: app-tier
spec:
type: LoadBalancer
ports:
- protocol: TCP
port: 3000
targetPort: 3000
selector:
tier: app
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-express-deployment
labels:
app: hello-express
tier: app
spec:
replicas: 1
selector:
matchLabels:
tier: app
template:
metadata:
labels:
app: hello-express
tier: app
spec:
containers:
- name: server
image: partyk1d24/hello-express:latest
ports:
- containerPort: 3000
然后我可以使用外部 ip 和端口 3000 訪問應用程序。現在我想將該端口從 3000 更改為 80。顯然這是使用Traefik
在 K3s 上本地控制的。 我在看這里時嘗試了以下...
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hello-express-ingress
annotations:
kubernetes.io/ingress.class: "traefik"
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: app-tier
port:
number: 80
但是當我嘗試 go 到該站點時,我得到...
curl 192.168.X.XXX
Service Unavailable%
該博客有點舊,所以我確定我做錯了什么,有人可以幫我識別它嗎?
您應該將服務端口更改為 80。
ports:
- protocol: TCP
port: 80
targetPort: 3000
保持目標端口為 3000。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.