首页 > 解决方案 > 如何设置INGRESS_HOST和INGRESS_PORT并访问GATEWAY_URL

问题描述

如何为使用自动边车注入创建其 istio 文件的示例 yaml 文件设置 INGRESS_HOST 和 INGRESS_PORT

我正在使用窗口 10 - Docker - kubernetes -Istio 配置。分别安装了 kubectl、istioctl 版本

apiVersion: v1
kind: Service
metadata:
  name: helloworld
  labels:
    app: helloworld
spec:
  ports:
  - port: 5000
    name: http
  selector:
    app: helloworld
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: helloworld-v1
  labels:
    version: v1
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: helloworld
        version: v1
    spec:
      containers:
      - name: helloworld
        image: istio/examples-helloworld-v1
        resources:
          requests:
            cpu: "100m"
        imagePullPolicy: Never
        ports:
        - containerPort: 5000
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: helloworld-v2
  labels:
    version: v2
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: helloworld
        version: v2
    spec:
      containers:
      - name: helloworld
        image: istio/examples-helloworld-v2
        resources:
          requests:
            cpu: "100m"
        imagePullPolicy: Never
        ports:
        - containerPort: 5000




apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: helloworld-gateway
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: helloworld
spec:
  hosts:
  - "*"
  gateways:
  - helloworld-gateway
  http:
  - match:
    - uri:
        exact: /hello
    route:
    - destination:
        host: helloworld
        port:
          number: 5

010

尝试访问我创建的示例服务时出现 503 服务暂时不可用

标签: kubernetes-ingressistio

解决方案


请首先验证您的选择器标签是否完美,并且您的服务已连接到部署 [POD]。

您在部署选择器中有“版本:v1”和“版本:v2”,但它不在服务中。这就是服务导致输出 503 不可用的原因。如果 pod 或服务中的问题,那么我将给出 502 bad gateway 或其他东西。

Istio 流量工作就像

ingress-gateway -> virtual-service -> destination-rule [optional] -> service

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: helloworld
spec:
  hosts:
  - "*"
  gateways:
  - helloworld-gateway
  http:
    - match:
      - uri:
          exact: /hello
      route:
      - destination:
          host: helloworld
          port:
            number: 5000  <--- change

推荐阅读