Istio VirtualService和Kubernetes Service有什么区别?

kol*_*oly 5 kubernetes istio

据我了解,Istio VirtualService是一种抽象的事物,它试图向实际的实现中添加接口,例如Kubernetes中的服务或Consul中的类似东西。

我的问题是:

当使用Kubernetes作为Istio的基础平台时,Istio VirtualService和Kubernetes Service有什么区别?还是一样?

Ste*_*eve 15

Istio 的 VirtualServices 作为每个 Istio 的扩展提供了一些附加功能,例如外部流量路由/管理(Pod 到外部通信、HTTPS 外部通信、路由、url 重写...)。

有关更多详细信息,请查看此文档:https : //istio.io/docs/reference/config/networking/virtual-service

它们都很有用,因为您需要“经典”服务来管理入口流量或服务到服务的通信。

史蒂夫。

  • 那么在使用kubernetes时,虚拟服务是否使用k8s服务来路由流量?两者如何合作? (7认同)

Vic*_*ong 6

Kubernetes 服务

Kubernetesservice管理 Pod 的网络。它指定您的 pod 是在内部 ( ClusterIP)、外部 (NodePortLoadBalancer) 还是作为其他 DNS 条目的 CNAME ( )公开externalName

例如,这foo-service将公开带有 label 的 pod app: foo。发送到 port 上的节点的任何请求30007都将转发到 port 上的 pod 80

apiVersion: v1
kind: Service
metadata:
  name: foo-service
spec:
  type: NodePort
  selector:
    app: foo
  ports:
    - port: 80
      targetPort: 80
      nodePort: 30007
Run Code Online (Sandbox Code Playgroud)

Istio 虚拟服务

Istiovirtualservice比 Kuberenetes 高一级service。它可用于将流量路由、故障注入、重试和许多其他配置应用于services.

例如,这foo-retry-virtualservice将重试 3 次,每次失败的请求超时 2 秒foo

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: foo-retry-virtualservice
spec:
  hosts:
  - foo
  http:
  - route:
    - destination:
        host: foo
    retries:
      attempts: 3
      perTryTimeout: 2s
Run Code Online (Sandbox Code Playgroud)

另一个例子是foo-delay-virtualservice对 0.1% 的请求应用 0.5 秒的延迟foo

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: foo-delay-virtualservice
spec:
  hosts:
  - foo
  http:
  - fault:
      delay:
        percentage:
          value: 0.1
        fixedDelay: 5s
    route:
    - destination:
        host: foo
Run Code Online (Sandbox Code Playgroud)

参考

https://kubernetes.io/docs/concepts/services-networking/service/ https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/ https://istio.io/latest/ docs/reference/config/networking/virtual-service/ https://istio.io/latest/docs/concepts/traffic-management/#virtual-services

  • VirtualService'“spec.http.route.destination.host”不应该是“foo-service”而不是“foo”吗?https://istio.io/latest/docs/reference/config/networking/virtual-service/#Destination 说:“destination.host 应明确引用服务注册表中的服务。” (3认同)

Sub*_*kam 5

虚拟服务:

它定义了一组流量路由规则,根据匹配标准应用于 kubernetes 服务或服务子集。这类似于 kubernetes Ingress 对象。它对 Istio 灵活而强大的流量管理起到了关键作用。

Kubernetes 服务:

它可以是一组逻辑 pod,并定义为 pod 之上的抽象,它提供单个 DNS 名称或 IP。