基础设置
此示例展示了一个简单的反向代理 Ingress 配置。
配置文件仓库路径:examples/basic/。
最小配置
yaml
version: v1
port: 8080
# Same inferred mode (service); compare spelling explicit backend.type vs omission.
rules:
- host: app-with-type.example.com
backend:
type: service
service:
name: backend-service
port: 8080
- host: app-inferred.example.com
backend:
service:
name: backend-service
port: 8080说明
- port:Ingress 监听端口 8080
- rules:定义路由规则
- host:匹配
Host: example.com的请求 - backend.service:路由到端口 8080 上的
backend-service
测试
bash
ingress run -c examples/basic/ingress.yamlbash
curl -H "Host: example.com" http://localhost:8080多服务
yaml
version: v1
port: 8080
# Explicit type on one host, inferred on the other — equivalent once validated.
rules:
- host: web.example.com
backend:
type: service
service:
name: web-service
port: 8080
- host: api.example.com
backend:
service:
name: api-service
port: 8081禁用规则
yaml
version: v1
port: 8080
rules:
- host: disabled.example.com
enabled: false
backend:
redirect:
url: https://old.example.com
- host: disabled.example.com
backend:
handler:
body: "still live\n"当 disabled.example.com 的第一条规则 enabled: false 时,流量会落到下一条已启用规则(示例中为 handler 响应 still live)。