【问题标题】:istio create external ip for specific serviceistio 为特定服务创建外部 ip
【发布时间】:2020-11-11 06:25:50
【问题描述】:

我已经使用 istio 成功将应用部署到 K8s

我们有我们使用的 gw 和虚拟服务,如下所示:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: bher-virtualservice
  namespace: ba-trail 
spec:
  gateways:
    - bher-gateway 
  hosts:
    - trialio.cloud.str
  http:
    - match:
      - uri:
          prefix: "/"
      - uri:
          prefix: "/login"
      - uri:
          prefix: "/static"
      - uri:
          regex: '^.*\.(ico|png|jpg)$'
      route:
      - destination:
          host: bsa.ba-trail.svc.cluster.local service.namespace.svc.cluster.local
          port:
            number: 5000

我还定义了servicedeployment

我想在外部公开我可以访问的服务 喜欢:

https://myapp.host:5000

当我跑步时:

kubectl get svc istio-ingressgateway -n istio-system


NAME                   TYPE           CLUSTER-IP       EXTERNAL-IP                                                                  PORT(S)                                      AGE
istio-ingressgateway   LoadBalancer   100.61.114.202   a7151b2063cb-200880.eu-central-1.elb.amazonaws.com   150210:31161/TCP,80:31280/TCP,443:31190/TCP   41d

如何实现?

我能够通过端口转发运行应用程序,但我想要一个直接的外部链接。

【问题讨论】:

  • 如果你使用 istio 那么一切都应该通过 istio-ingress-gateway 外部 ip,所以你应该使用kubectl get svc -n istio-system,检查 istio ingress-gateway 外部 ip 并使用它从外部。如果您为您的服务使用端口转发,那么您并没有使用 istio,而只是您的部署服务。顺便删除service.namespace.svc.cluster.local,因为它被注释为向您展示路由目标主机的语法。

标签: amazon-web-services kubernetes istio


【解决方案1】:

因此,在您的情况下,您有一个 ELB 为您的 istio 入口网关提供服务,该 ELB 转到一个将流量引导到容器中的端口 5000 的 VirtualService。

我假设你可以使用 ??:

  • a7151b2063cb-200880.eu-central-1.elb.amazonaws.com:80
  • a7151b2063cb-200880.eu-central-1.elb.amazonaws.com:443

你想要这样的东西:

  • a7151b2063cb-200880.eu-central-1.elb.amazonaws.com:5000

但具有映射到的特定名称

  • myapp.host

首先,您必须创建一个将myapp.host 映射到a7151b2063cb-200880.eu-central-1.elb.amazonaws.com 的DNS CNAME 记录。

那么在 Kubernetes 服务istio-ingressgateway 上你可能有这样的东西:

apiVersion: v1
kind: Service
metadata:
  name: istio-ingressgateway
  namespace: istio-system
  labels:
    name: istio-ingress-service
  annotations:
    ... (❓)
spec:
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: ❓
    protocol: TCP
  - port: 443
    targetPort: ❓
    protocol: TCP
  selector:
    name: something-that-matches-your-istio-ingress

您可以将额外端口添加到服务中,以便它在外部侦听该端口。

apiVersion: v1
kind: Service
metadata:
  name: istio-ingressgateway
  namespace: istio-system
  labels:
    name: istio-ingress-service
  annotations:
    ... (❓)
spec:
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: ❓
    protocol: TCP
  - port: 443
    targetPort: ❓
    protocol: TCP
  - port: 5000
    targetPort: ❓
  selector:
    name: something-that-matches-your-istio-ingress

最后,虚拟服务需要匹配你的主机名myapp.host

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: bher-virtualservice
  namespace: ba-trail 
spec:
  gateways:
    - bher-gateway 
  hosts:
    - myapp.host 
...

✌️

【讨论】:

  • 谢谢 1+,一些问题 1. 我想要的是类似 "myapp.somehost:5000" 所以我必须将 somehost 映射到 a7151b2063cb-200880.eu-central-1.elb.amazonaws.com ,以及如何使用 @ 987654335@ 来自VS 主机? , 2. 你确定我需要type: LoadBalancer 吗,当我在使用istio 之前这样做是为了将我的应用程序暴露在外面,我在使用istio 时是否也需要它?
  • 是的,如果您想从外部公开它,您需要负载均衡器。要公开您的应用,您需要使用 ClusterIP 的内部服务
猜你喜欢
  • 2019-09-29
  • 2017-10-21
  • 1970-01-01
  • 1970-01-01
  • 2022-01-26
  • 2017-01-18
  • 2022-11-04
  • 1970-01-01
相关资源
最近更新 更多