istio ingress gataway

发布时间 2023-05-26 21:52:42作者: FLOWERS_WAN

在kubernetes中,kubernetes ingress resource常用来指定应该暴露给集群外部服务,在一个istio中,最好的办法就是使用不同配置模型,也就是istio gateway,

一个gateway允许istio的功能,比如监控和路由规则去应用到进入集群的流量。

 

1.准备工作

[root@k8s-master01 httpbin]# kubectl apply -f httpbin.yaml -n istio
serviceaccount/httpbin created
service/httpbin created
deployment.apps/httpbin created
[root@k8s-master01 httpbin]#
2.  确定ingress的IP和端口

 

[root@k8s-master01 httpbin]# kubectl get svc   -n istio-system istio-ingressgateway
NAME                   TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                                                                      AGE
istio-ingressgateway   LoadBalancer   10.107.131.1   192.168.30.240   15021:31996/TCP,80:31612/TCP,443:31718/TCP,31400:32280/TCP,15443:31182/TCP   91d


如果 EXTERNAL-IP 有值(IP 地址或主机名),则说明您的环境具有可用于 Ingress 网关的外部负载均衡器。如果 EXTERNAL-IP 值是 <none>(或一直是 <pending> ),则说明可能您的环境并没有为 Ingress 网关提供外部负载均衡器的功能。在这种情况下,您可以使用 Ingress Service 的 node port 方式访问网关。

[root@k8s-master01 httpbin]# export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
[root@k8s-master01 httpbin]# export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
[root@k8s-master01 httpbin]# export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].port}')
[root@k8s-master01 httpbin]#
[root@k8s-master01 httpbin]# echo $INGRESS_HOST
192.168.30.240
[root@k8s-master01 httpbin]# echo $INGRESS_PORT
80
[root@k8s-master01 httpbin]# echo $SECURE_INGRESS_PORT
443

export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')

方式二:确定使用 Node Port 时的 ingress IP 和端口

注,如果环境没有外部负载均衡器,请按照此说明操作。

确认端口:

    export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
    export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')

确认IP,不同的平台环境IP不同,如本机局域网IP:10.11.0.100,则执行:

export INGRESS_HOST=10.11.0.100