外部访问
提示
Gateway网关的流量在默认是由LoadBalancer的Service
来支撑,但是测试环境没有搭建外部负载均衡器,我们也可以通过NodePort
的方式来对外暴露网关。
暴露端口
因为使用了Kind搭建测试环境集群,我只暴露了30000-30020范围的端口,所以需要手动修改下ingressgateway下的NodePort端口。
bash
$ kubectl -n istio-system patch svc istio-ingressgateway --type='json' -p='[
{"op":"replace","path":"/spec/ports/1/nodePort","value":30001},
{"op":"replace","path":"/spec/ports/2/nodePort","value":30003}
]'
声明变量
bash
$ export INGRESS_NAME=istio-ingressgateway
$ export INGRESS_NS=istio-system
# http访问端口
$ export INGRESS_PORT=$(kubectl -n "${INGRESS_NS}" get service "${INGRESS_NAME}" -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
# https访问端口
$ export SECURE_INGRESS_PORT=$(kubectl -n "${INGRESS_NS}" get service "${INGRESS_NAME}" -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')
# 网关地址
$ export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n "${INGRESS_NS}" -o jsonpath='{.items[0].status.hostIP}')