我曾经使用类型:LoadBalancer 通过反向代理公开我的服务。没有 Istio 一切都运行良好。 但是,当我将 Istio 应用到集群时,发生了错误。
我尝试使用 Istio Ingress 在 Kubernetes 中公开我的服务,但我认为在使用 Istio 路由服务时我误解了一些内容。
我在同一命名空间中有 2 个部署(见下图):
1:应用程序(总线 ID)
2:应用程序的反向代理(Bus-Proxy):将HTTP转换为gRPC
https://drive.google.com/file/d/1tby9_taJb9WMHi0ssO9Os7MQAWRMga6k/view?usp=sharing
版本:
Kubernetes 版本(启用 RBAC 的 AKS):
客户端版本:v1.15.0
服务器版本:v1.12.8
Istio 版本:1.1.3(AKS 表示他们在 1.1.3 上进行了测试)
Helm :
客户端:&version.Version{SemVer:“v2.13.0”,GitCommit:“79d07943b03aea2b76c12644b4b54733bc5958d6”,GitTreeState:“clean”}
服务器:&version.Version{SemVer:“v2.14.1”,GitCommit:“5270352a09c7e8b6e8c9593002a73535276507c0”,GitTreeState:“clean”}
我在 Istio ( https://istio.io/docs/examples/bookinfo/ ) 中尝试了 BookInfo 示例,它有效。
但是,我尝试了 AKS 中的投票示例 ( https://learn.microsoft.com/en-us/azure/aks/istio-scenario-routing ),我无法使用外部负载均衡器的 IP 访问示例,它会重新设置“超时”
部署文件:
<强>1。总线 id.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: bus-id
namespace: smart-id
labels:
k8s-app: bus-id
spec:
selector:
matchLabels:
k8s-app: bus-id
template:
metadata:
name: bus-id
labels:
k8s-app: bus-id
spec:
containers:
- name: bus-id
image: mydockerhub/mydockerhub:bus-id
ports:
- containerPort: 50001
env:
- name: APP_NAME
value: bus-id
---
apiVersion: v1
kind: Service
metadata:
name: bus-id
namespace: smart-id
labels:
service: bus-id
spec:
ports:
- name: http
port: 50001
targetPort: 50001
protocol: TCP
selector:
k8s-app: bus-id
<强>2。总线代理.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
k8s-app: bus-proxy
name: bus-proxy
namespace: smart-id
spec:
selector:
matchLabels:
k8s-app: bus-proxy
replicas: 1
template:
metadata:
labels:
k8s-app: bus-proxy
spec:
imagePullSecrets:
- name: duynd
containers:
- image: mydockerhub/mydockerhub:bus-proxy
name: bus-proxy
ports:
- containerPort: 40001
name: http
env:
- name: APP_NAME
value: bus-proxy
---
apiVersion: v1
kind: Service
metadata:
name: bus-proxy
namespace: smart-id
labels:
service: bus-proxy
spec:
ports:
- port: 8080
targetPort: 40001
protocol: TCP
selector:
k8s-app: bus-proxy
<强>3。 ingress.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: smartid-gateway
namespace: smart-id
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: smartid
namespace: smart-id
spec:
hosts:
- "*"
gateways:
- smart-id/smartid-gateway
http:
- match:
- uri:
prefix: /api
route:
- destination:
host: bus-proxy.smart-id.svc.cluster.local
port:
number: 8080
我希望它可以与 ingress-ip:ingress-port/api/my-function (方法 POST)一起使用。但是,它返回错误500,bus-proxy的POD也打印日志(我认为请求成功到达bus-proxy,但可以通过bus-proxy>总线 ID)。
- 我还在 github 上发布了相关问题 ( https://github.com/istio/istio/issues/16069 )
最佳答案
首先,如果您使用 Istio 运行 AKS 中的所有应用程序,我建议您按照 AKS 在Install and use Istio in Azure Kubernetes Service (AKS)中提供的步骤安装 Istio。 .
现在,看一下 AKS 提供的示例 here有件事你需要知道:
The Istio has the proxy itself. So you need to choose which to use or use both proxies, but you need to make sure it supports two proxies.
如果您使用 Istio 的代理,那么您还需要为您的应用程序的命名空间启用 istio-injection
,就像示例一样:
kubectl label namespace voting istio-injection=enabled
此标签指示 Istio 自动将 istio-proxies 作为 sidecar 注入(inject)到此命名空间中的所有 pod 中。您应该在 ingress.yaml 中为您的虚拟服务使用正确的网关。
关于azure - 如何使用 Istio Ingress 在 AKS 中公开服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57356436/