【问题标题】:Can I use istio for services which access by nodeport in kubernetes?我可以将 istio 用于 kubernetes 中通过 nodeport 访问的服务吗?
【发布时间】:2019-04-08 19:04:25
【问题描述】:

问题

我在 kubernetes 中使用相同的服务创建两个部署,类型是 NodePort,

apiVersion: v1
kind: Service
metadata:
  name: devo-159239e607c694e08b146c855b393652
  namespace: devo-bsg-dev
  labels:
    app: devo
spec:
  ports:
  - name: http-app
    nodePort: 31012
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: devo-159239e607c694e08b146c855b393652
  type: NodePort

我可以通过 NodePort 访问我的服务,kiali 也可以显示流量

然后我希望所有流量都转到 v1 版本,所以我创建了一个 virtualservice 和 destinationrule,

[root@master104 beego2]# cat beego2-virtual-service.yml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: devo-159239e607c694e08b146c855b393652
  namespace: devo-bsg-dev
spec:
  hosts:
  - devo-159239e607c694e08b146c855b393652
  http:
  - route:
    - destination:
        host: devo-159239e607c694e08b146c855b393652
        subset: v1
[root@master104 beego2]# cat beego2-destination.yml
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: devo-159239e607c694e08b146c855b393652
  namespace: devo-bsg-dev
spec:
  host: devo-159239e607c694e08b146c855b393652
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2

但结果未按预期显示

问题是:是我的规则错了还是 istio 不能与 nodeport 一起工作?

环境

kubernetes 1.13.3

istio 1.1.2

【问题讨论】:

  • 您的方法似乎不对。

标签: kubernetes istio


【解决方案1】:

我在您的 Istio 设置中没有看到任何 Gateway 配置。 Istio Gateway 代表 Kuberentes 微服务前面的外部 IP 地址,允许通过指定端口、协议和主机传入流量。可以在通用网关资源定义中使用默认的istio-ingressgateway,然后绑定对应的VirtualService,即:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: http-gateway
  namespace: devo-bsg-dev
spec:
  selector:
    istio: ingressgateway #Default Istio Ingressgateway controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - devo-159239e607c694e08b146c855b393652
---

kind: VirtualService
metadata:
  name: devo-159239e607c694e08b146c855b393652
  namespace: devo-bsg-dev
spec:
  hosts:
  - devo-159239e607c694e08b146c855b393652
  gateways:
  - http-gateway
  http:
  - route:
    - destination:
        host: devo-159239e607c694e08b146c855b393652
        subset: v1

在上述场景中,我们希望允许端口 80 上的 HTTP 流量,用于主机 devo-159239e607c694e08b146c855b393652

您可以在演示 Booking 应用程序example 中找到更多关于通过 Istio 网格公开 Kubernetes 微服务的相关实用材料。

【讨论】:

    猜你喜欢
    • 2019-07-26
    • 2019-07-26
    • 2021-06-27
    • 1970-01-01
    • 2018-10-29
    • 1970-01-01
    • 2017-10-06
    • 2023-01-18
    • 1970-01-01
    相关资源
    最近更新 更多