Istio + minikube + Nginx (React). 无法从浏览器或CURL获取访问

当我没有使用ingress-gateway部署时,我可以通过端口转发直接在浏览器中访问应用程序的LoadBalancer。但通过ingress-gateway,它无法工作。 启用了Sidecar注入!

Istio v1.4.0

Minukube v1.5.2

Kubernetes v1.16.0

Istio安装:

istioctl manifest apply \
  --set values.global.mtls.enabled=false \
  --set values.tracing.enabled=true \
  --set values.kiali.enabled=true \
  --set values.grafana.enabled=true \
--namespace istio-system

然后部署使用NGINX的React。

# 前端服务
apiVersion: v1
kind: Service
metadata:
  name: front-web
  namespace: demo
spec:
  type: NodePort
  selector:
    app: front-web
  ports:
    - name: http
      port: 80

---
# 前端应用程序
apiVersion: apps/v1
kind: Deployment
metadata:
  name: front-web
  namespace: demo
  labels:
    app: front-web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: front-web
  template:
    metadata:
      labels:
        app: front-web
    spec:
      containers:
      - name: front-web
        image: sergeygreat/front-web:v1.0.3
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80

网关


apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: demo-gw
  namespace: demo
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: demo-vs
  namespace: demo
spec:
  hosts:
  - "*"
  gateways:
  - demo-gw
  http:
  - match:
    - uri:
        exact: /
    route:
    - destination:
        port:
          number: 80
        host: front-web.default.svc.cluster.local  # <- 尝试只使用 `front-web`,但没有成功
>> kubectl get svc -n istio-system

istio-ingressgateway LoadBalancer 10.104.158.110 <pending> 80:31332/TCP,...

一切都在运行中,但无法通过http://minikube ip:31332访问?

对于浏览器中的端口80:http://minikube_ip - 404 Not Found openresty/1.15.8.2

对于浏览器中的端口31332:http://minikube_ip:31332 - 503错误

minikube ssh

$ curl -i http://localhost:31332
HTTP/1.1 503 Service Unavailable
date: Mon, 16 Dec 2019 16:04:32 GMT
server: istio-envoy
content-length: 0

$ curl -i http://192.168.99.101:31332
HTTP/1.1 503 Service Unavailable
date: Mon, 16 Dec 2019 16:04:45 GMT
server: istio-envoy
content-length: 0

请问有人能帮帮忙吗?

点赞
用户1366056
用户1366056

如果您使用的是nginx ingress,则以下是步骤。我假设启用istio ingress的方法类似

minikube addons enable ingress

通过验证以下命令的输出,检查您的ingress控制器是否正在运行

kubectl get pods -n kube-system
nginx-ingress-controller-5984b97644-rnkrg   1/1       Running   0          1m

将服务公开为节点端口。以下是示例命令

kubectl expose deployment web --target-port=8080 --type=NodePort

kubectl get service web
web       NodePort   10.104.133.249   <none>        8080:31637/TCP   12m

然后获取minikube URL

minikube service web --url
http://172.17.0.15:31637
2019-12-16 16:33:15
用户2160537
用户2160537

尝试重新创建 minikube:

>>minikube stop
>>minikube delete
>>minikube start --memory=16384 --cpus=4 --vm-driver=virtualbox --kubernetes-version=v1.16.0

如果没有帮助,请尝试绑定到另一个端口:

- 部署设置为80
- 服务类型应为NodePort,并将其绑定到端口8080 targetPort:80
- VirtualService主机“*”端口8080

它应该能够工作!

如果还不行,请尝试从VirtualService中删除此部分:

- match:
    - uri:
        exact: /
2019-12-17 11:28:26
用户19039261
用户19039261

在设置好你的 ingress 之后,运行 minikube service。这将在使用 minikube 标识的 nodeport 上启动 HTTP2 流量。

最后,你可以通过 minikube 标识的 minikubeIP:<nodeport> 访问你的应用。我曾经遇到过很多问题!官方文档说要使用 minikube tunnel,但它总是失败。

After you have set up your ingress, run `minikube service`. This will start the traffic flow over the `minikube` identified `nodeport` for `HTTP2`.

Finally, you can access your application over the `minikubeIP:<nodeport>` identified by `minikube`. I struggled alot! Official doc said to use `minikube tunnel`, but it fails.
2022-05-05 03:59:42