Kubernetes Service APIs
调用 Service APIs 创建 CRDs:
安装 Istio 或重新配置 Istio,启动 Service APIs 控制器:
配置网关
参见 文档中的 APIs 信息.
部署一个测试应用:
部署 Service APIs 配置:
$ kubectl apply -f - <<EOF
apiVersion: networking.x-k8s.io/v1alpha1
kind: GatewayClass
metadata:
name: istio
spec:
controller: istio.io/gateway-controller
---
apiVersion: networking.x-k8s.io/v1alpha1
kind: Gateway
metadata:
name: gateway
namespace: istio-system
gatewayClassName: istio
listeners:
- hostname: "*"
port: 80
routes:
namespaces:
from: All
selector:
matchLabels:
selected: "yes"
kind: HTTPRoute
---
apiVersion: networking.x-k8s.io/v1alpha1
kind: HTTPRoute
metadata:
name: http
namespace: default
labels:
selected: "yes"
spec:
allow: All
rules:
- matches:
- path:
type: Prefix
value: /get
filters:
- type: RequestHeaderModifier
requestHeaderModifier:
add:
my-added-header: added-value
forwardTo:
- serviceName: httpbin
port: 8000
EOF
使用 curl 访问刚才部署的 httpbin 服务:
访问尚未显式公开的任何其他 URL,将会收到 HTTP 404 错误:
$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/headers"
HTTP/1.1 404 Not Found