istio.io/archive/v1.2/zh/blog/2018/v1alpha3-routing/index.html

173 lines
40 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html><html lang=zh itemscope itemtype=https://schema.org/WebPage><head><meta charset=utf-8><meta http-equiv=x-ua-compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name=theme-color content=#466BB0><meta name=title content="Istio v1aplha3 路由 API 介绍"><meta name=description content="Istio v1alpha3 路由 API 介绍,动机及其设计原则。"><meta name=author content="Frank Budinsky (IBM) and Shriram Rajagopalan (VMware)"><meta name=keywords content=microservices,services,mesh,traffic-management><meta property=og:title content="Istio v1aplha3 路由 API 介绍"><meta property=og:type content=website><meta property=og:description content="Istio v1alpha3 路由 API 介绍,动机及其设计原则。"><meta property=og:url content=/v1.2/zh/blog/2018/v1alpha3-routing/><meta property=og:image content=/v1.2/img/istio-whitelogo-bluebackground-framed.svg><meta property=og:image:alt content="Istio Logo"><meta property=og:image:width content=112><meta property=og:image:height content=150><meta property=og:site_name content=Istio><meta name=twitter:card content=summary><meta name=twitter:site content=@IstioMesh><title>Istioldie 1.2 / Istio v1aplha3 路由 API 介绍</title><script async src="https://www.googletagmanager.com/gtag/js?id=UA-98480406-2"></script><script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}
gtag('js',new Date());gtag('config','UA-98480406-2');</script><link rel=alternate type=application/rss+xml title="Istio Blog" href=/v1.2/feed.xml><link rel="shortcut icon" href=/v1.2/favicons/favicon.ico><link rel=apple-touch-icon href=/v1.2/favicons/apple-touch-icon-180x180.png sizes=180x180><link rel=icon type=image/png href=/v1.2/favicons/favicon-16x16.png sizes=16x16><link rel=icon type=image/png href=/v1.2/favicons/favicon-32x32.png sizes=32x32><link rel=icon type=image/png href=/v1.2/favicons/android-36x36.png sizes=36x36><link rel=icon type=image/png href=/v1.2/favicons/android-48x48.png sizes=48x48><link rel=icon type=image/png href=/v1.2/favicons/android-72x72.png sizes=72x72><link rel=icon type=image/png href=/v1.2/favicons/android-96x96.png sizes=96xW96><link rel=icon type=image/png href=/v1.2/favicons/android-144x144.png sizes=144x144><link rel=icon type=image/png href=/v1.2/favicons/android-192x192.png sizes=192x192><link rel=manifest href=/v1.2/manifest.json><meta name=apple-mobile-web-app-title content=Istio><meta name=application-name content=Istio><link rel=stylesheet href="https://fonts.googleapis.com/css?family=Work+Sans:400|Chivo:400|Work+Sans:500,300,600,300italic,400italic,500italic,600italic|Chivo:500,300,600,300italic,400italic,500italic,600italic"><link rel=stylesheet href=/v1.2/css/all.css><script src=/v1.2/js/themes_init.min.js></script></head><body class="language-unknown archive-site"><script>const branchName="release-1.2";const docTitle="Istio v1aplha3 路由 API 介绍";const iconFile="\/v1.2/img/icons.svg";const buttonCopy='复制到剪切板';const buttonPrint='打印';const buttonDownload='下载';</script><script src="https://www.google.com/cse/brand?form=search-form" defer></script><script src=/v1.2/js/all.min.js data-manual defer></script><header><nav><a id=brand href=/v1.2/zh/><span class=logo><svg viewBox="0 0 300 300"><circle cx="150" cy="150" r="146" stroke-width="2" /><path d="M65 240H225L125 270z"/><path d="M65 230l60-10V110z"/><path d="M135 220l90 10L135 30z"/></svg></span><span class=name>Istioldie 1.2</span></a><div id=hamburger><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#hamburger"/></svg></div><div id=header-links><a title="了解如何部署、使用和运维 Istio。" href=/v1.2/zh/docs/>文档</a>
<span title="关于使用 Istio 的博客文章。">博客</span>
<a title=关于Istio的常见问题。 href=/v1.2/zh/faq/>FAQ</a>
<a title=关于Istio的说明。 href=/v1.2/zh/about/>关于</a><div class=menu><button id=gearDropdownButton class=menu-trigger title=选项和设置 aria-label="Options and Settings" aria-controls=gearDropdownContent><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#gear"/></svg></button><div id=gearDropdownContent class=menu-content aria-labelledby=gearDropdownButton role=menu><a tabindex=-1 role=menuitem lang=en id=switch-lang-en>English</a>
<a tabindex=-1 role=menuitem lang=zh id=switch-lang-zh class=active>中文</a><div role=separator></div><a tabindex=-1 role=menuitem class=active id=light-theme-item>亮主题</a>
<a tabindex=-1 role=menuitem id=dark-theme-item>暗主题</a><div role=separator></div><a tabindex=-1 role=menuitem id=syntax-coloring-item>代码高亮</a><div role=separator></div><h6>本站的其它版本</h6><a tabindex=-1 role=menuitem onclick="navigateToUrlOrRoot('https://istio.io/blog\/2018\/v1alpha3-routing\/');return false;">当前版本</a>
<a tabindex=-1 role=menuitem onclick="navigateToUrlOrRoot('https://preliminary.istio.io/blog\/2018\/v1alpha3-routing\/');return false;">下个版本</a>
<a tabindex=-1 role=menuitem href=https://archive.istio.io>旧版本</a></div></div><button id=search-show title=搜索istio.io aria-label=Search><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#magnifier"/></svg></button></div><form id=search-form name=cse role=search><input type=hidden name=cx value=013699703217164175118:iwwf17ikgf4>
<input type=hidden name=ie value=utf-8>
<input type=hidden name=hl value=en>
<input type=hidden id=search-page-url value=/v1.2/search.html>
<input id=search-textbox class=form-control name=q type=search aria-label=搜索istio.io>
<button id=search-close title="Cancel search" type=reset aria-label="Cancel search"><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#cancel-x"/></svg></button></form></nav></header><main class=primary><div id=sidebar-container class="sidebar-container sidebar-offcanvas"><nav id=sidebar aria-label="Section Navigation"><div class=directory><div class=card><button class="header dynamic" id=card0 title="2019 年的博客文章。" aria-controls=card0-body><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#blog"/></svg>2019 年的博客文章</button><div class=body aria-labelledby=card0 role=region id=card0-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card0><li role=none><a role=treeitem title="Istio 1.1.3。" href=/v1.2/zh/blog/2019/announcing-1.1.3/>安全更新:发布 Istio 1.1.3</a></li><li role=none><a role=treeitem title="Istio 1.0.7 的补丁版本。" href=/v1.2/zh/blog/2019/announcing-1.0.7/>安全更新:发布 Istio 1.0.7</a></li><li role=none><a role=treeitem title="Istio 1.1.2 的补丁版本。" href=/v1.2/zh/blog/2019/announcing-1.1.2/>安全更新:发布 Istio 1.1.2</a></li><li role=none><a role=treeitem title="Istio 1.1 发布声明。" href=/v1.2/zh/blog/2019/announcing-1.1/>宣布 Istio 1.1 发布</a></li><li role=none><a role=treeitem title="Istio 1.1 性能概览." href=/v1.2/zh/blog/2019/istio1.1_perf/>面向性能而架构的 Istio 1.1</a></li><li role=none><a role=treeitem title="Istio 1.0.6 补丁版本。" href=/v1.2/zh/blog/2019/announcing-1.0.6/>Istio 1.0.6 发布</a></li><li role=none><a role=treeitem title="在多集群服务网格环境中配置 Istio 的路由规则。" href=/v1.2/zh/blog/2019/multicluster-version-routing/>多集群服务网格中的分版本路由</a></li><li role=none><a role=treeitem title=宣布新的博客策略。 href=/v1.2/zh/blog/2019/sail-the-blog/>博客策略更新</a></li><li role=none><a role=treeitem title="评估加入 Egress gateway 对性能造成的影响。" href=/v1.2/zh/blog/2019/egress-performance/>Egress gateway 性能测试</a></li><li role=none><a role=treeitem title="Istio 将数据面组件注入到现存部署之中的过程。" href=/v1.2/zh/blog/2019/data-plane-setup/>Istio Sidecar 注入过程解密</a></li><li role=none><a role=treeitem title="使用 AppSwitch 解决应用程序启动顺序和启动延迟。" href=/v1.2/zh/blog/2019/appswitch/>使用 AppSwitch 进行 Sidestepping 依赖性排序</a></li><li role=none><a role=treeitem title="如何使用 cert-manager 手工部署一个自定义 Ingress 网关。" href=/v1.2/zh/blog/2019/custom-ingress-gateway/>使用 Cert-Manager 部署一个自定义 Ingress 网关</a></li><li role=none><a role=treeitem title="Istio 推出新的讨论板。" href=/v1.2/zh/blog/2019/announcing-discuss.istio.io/>宣布 discuss.istio.io</a></li></ul></div></div><div class=card><button class="header dynamic" id=card1 title="2017 年的博客文章。" aria-controls=card1-body><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#blog"/></svg>2017 年的博客文章</button><div class=body aria-labelledby=card1 role=region id=card1-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card1><li role=none><a role=treeitem title=提高可用,降低延迟。 href=/v1.2/zh/blog/2017/mixer-spof-myth/>Mixer 和 SPOF 神话</a></li><li role=none><a role=treeitem title="概要说明 Mixer 的插件架构。" href=/v1.2/zh/blog/2017/adapter-model/>Mixer 适配器模型</a></li><li role=none><a role=treeitem title="Istio 0.2 公告。" href=/v1.2/zh/blog/2017/0.2-announcement/>宣布 Istio 0.2</a></li><li role=none><a role=treeitem title="Istio 的策略如何关联 Kubernetes 的网络策略 。" href=/v1.2/zh/blog/2017/0.1-using-network-policy/>Istio 使用网络策略</a></li><li role=none><a role=treeitem title="使用 Istio 创建自动缩放的金丝雀部署。" href=/v1.2/zh/blog/2017/0.1-canary/>使用 Istio 进行金丝雀部署</a></li><li role=none><a role=treeitem title="Istio Auth 0.1 公告。" href=/v1.2/zh/blog/2017/0.1-auth/>使用 Istio 增强端到端安全</a></li><li role=none><a role=treeitem title="Istio 0.1 宣布。" href=/v1.2/zh/blog/2017/0.1-announcement/>初次了解 Istio</a></li></ul></div></div><div class=card><button class="header dynamic" id=card2 title="2018 年的博客文章。" aria-controls=card2-body><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#blog"/></svg>2018 年的博客文章</button><div class="body default" aria-labelledby=card2 role=region id=card2-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card2><li role=none><a role=treeitem title="Istio 1.0.5 补丁版本发布。" href=/v1.2/zh/blog/2018/announcing-1.0.5/>Istio 1.0.5 发布</a></li><li role=none><a role=treeitem title="Istio 1.0.4 补丁版本发布。" href=/v1.2/zh/blog/2018/announcing-1.0.4/>Istio 1.0.4 发布</a></li><li role=none><a role=treeitem title="如何在不部署 Sidecar 代理的情况下使用 Istio 进行流量管理。" href=/v1.2/zh/blog/2018/incremental-traffic-management/>增量式应用 Istio 第一部分,流量管理</a></li><li role=none><a role=treeitem title="描述了一个基于 Istio 的 Bookinfo 示例的简单场景。" href=/v1.2/zh/blog/2018/egress-mongo/>使用外部 MongoDB 服务</a></li><li role=none><a role=treeitem title="Istio 1.0.3 修补版本。" href=/v1.2/zh/blog/2018/announcing-1.0.3/>宣布 Istio 1.0.3</a></li><li role=none><a role=treeitem title="Istio 1.0.2 补丁版本." href=/v1.2/zh/blog/2018/announcing-1.0.2/>Istio 1.0.2 发布</a></li><li role=none><a role=treeitem title="Istio 1.0.1 补丁版本。" href=/v1.2/zh/blog/2018/announcing-1.0.1/>Istio 1.0.1 发布</a></li><li role=none><a role=treeitem title="Istio 在 Twitch 举办了为期一天的直播庆祝 1.0 的发布。" href=/v1.2/zh/blog/2018/istio-twitch-stream/>Istio 在 Twitch 上全天直播</a></li><li role=none><a role=treeitem title="惠普如何在 Istio 上构建其下一代鞋类个性化平台。" href=/v1.2/zh/blog/2018/hp/>Istio 是惠普 FitStation 平台的改变者</a></li><li role=none><a role=treeitem title="Istio 1.0 已生产就绪。" href=/v1.2/zh/blog/2018/announcing-1.0/>宣布 Istio 1.0</a></li><li role=none><a role=treeitem title="使用 AppSwitch 自动接入应用并降低延迟。" href=/v1.2/zh/blog/2018/delayering-istio/>使用 AppSwitch 精简 Istio 层次</a></li><li role=none><a role=treeitem title="描述 Istio 的授权功能以及如何在各种用例中使用它。" href=/v1.2/zh/blog/2018/istio-authorization/>基于 Istio 的 Micro-Segmentation 授权</a></li><li role=none><a role=treeitem title="如何通过 Stackdriver 将 Istio 访问日志导出到 BigQuery、GCS、Pub/Sub 等不同的接收器。" href=/v1.2/zh/blog/2018/export-logs-through-stackdriver/>通过 Stackdriver 将日志导出到 BigQuery、GCS、Pub/Sub</a></li><li role=none><a role=treeitem title="描述如何配置 Istio 进行 HTTP Egress 流量监控和访问策略。" href=/v1.2/zh/blog/2018/egress-monitoring-access-control/>HTTP Egress 流量监控和访问策略</a></li><li role=none><span role=treeitem class=current title="Istio v1alpha3 路由 API 介绍,动机及其设计原则。">Istio v1aplha3 路由 API 介绍</span></li><li role=none><a role=treeitem title="描述如何在AWS上使用网络负载均衡器配置 Istio Ingress。" href=/v1.2/zh/blog/2018/aws-nlb/>使用AWS NLB 配置 Istio Ingress</a></li><li role=none><a role=treeitem title="使用 Kubernetes 命名空间和 RBAC 为 Istio 构建软性多租户环境。" href=/v1.2/zh/blog/2018/soft-multitenancy/>Istio 的软性多租户支持</a></li><li role=none><a role=treeitem title=介绍更安全,低风险的部署和发布到生产。 href=/v1.2/zh/blog/2018/traffic-mirroring/>用于在生产环境进行测试的 Istio 流量镜像功能</a></li><li role=none><a role=treeitem title="描述基于 Istio 的 Bookinfo 示例的简单场景。" href=/v1.2/zh/blog/2018/egress-tcp/>使用外部 TCP 服务</a></li><li role=none><a role=treeitem title="描述基于 Istio Bookinfo 示例的简单场景。" href=/v1.2/zh/blog/2018/egress-https/>使用外部 Web 服务</a></li></ul></div></div></div></nav></div><div class=article-container><button tabindex=-1 id=sidebar-toggler title=折叠导航栏><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#pull"/></svg></button><nav aria-label=Breadcrumb><ol><li><a href=/v1.2/zh/>Istio</a></li><li><a href=/v1.2/zh/blog/ title="关于使用 Istio 的博客文章。">博客</a></li><li><a href=/v1.2/zh/blog/2018/ title="2018 年的博客文章。">2018 年的博客文章</a></li><li>Istio v1aplha3 路由 API 介绍</li></ol></nav><article aria-labelledby=title><div class=title-area><div><h1 id=title>Istio v1aplha3 路由 API 介绍</h1><p class=byline><span>作者</span>
<span class=attribution>Frank Budinsky (IBM) and Shriram Rajagopalan (VMware)</span><span> | </span><span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#calendar"/></svg><span>&nbsp;</span>2018年4月25日</span><span> | </span><span title="696 字"><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#clock"/></svg><span>&nbsp;</span>阅读大约需要 4 分钟</span></p></div></div><nav class=toc-inlined aria-label="Table of Contents"><div><hr><ol><li role=none aria-label=设计原则><a href=#%e8%ae%be%e8%ae%a1%e5%8e%9f%e5%88%99>设计原则</a><li role=none aria-label="v1alpha3 中的配置资源"><a href=#v1alpha3-%e4%b8%ad%e7%9a%84%e9%85%8d%e7%bd%ae%e8%b5%84%e6%ba%90>v1alpha3 中的配置资源</a><ol><li role=none aria-label=Gateway><a href=#gateway><code>Gateway</code></a><li role=none aria-label=VirtualService><a href=#virtualservice><code>VirtualService</code></a><li role=none aria-label=DestinationRule><a href=#destinationrule><code>DestinationRule</code></a><li role=none aria-label=ServiceEntry><a href=#serviceentry><code>ServiceEntry</code></a></ol></li><li role=none aria-label="创建和删除 v1alpha3 路由规则"><a href=#%e5%88%9b%e5%bb%ba%e5%92%8c%e5%88%a0%e9%99%a4-v1alpha3-%e8%b7%af%e7%94%b1%e8%a7%84%e5%88%99>创建和删除 v1alpha3 路由规则</a><li role=none aria-label=总结><a href=#%e6%80%bb%e7%bb%93>总结</a><li role=none aria-label=致谢><a href=#%e8%87%b4%e8%b0%a2>致谢</a><li role=none aria-label=相关内容><a href=#see-also>相关内容</a></li></ol><hr></div></nav><p>到目前为止Istio 提供了一个简单的API来进行流量管理该API包括了四种资源<code>RouteRule</code><code>DestinationPolicy</code><code>EgressRule</code>Kubernetes 的)<code>Ingress</code>。借助此 API用户可以轻松管理 Istio 服务网格中的流量。该 API 允许用户将请求路由到特定版本的服务,为弹性测试注入延迟和失败,添加超时和断路器等,所有这些功能都不必更改应用程序本身的代码。</p><p>虽然目前 API 的功能已被证明是 Istio 非常引人注目的一部分,但用户的反馈也表明,这个 API 确实有一些缺点,尤其是在使用它来管理包含数千个服务的非常大的应用程序,以及使用 HTTP 以外的协议时。 此外,使用 Kubernetes Ingress 资源来配置外部流量的方式已被证明不能满足需求。</p><p>为了解决上述缺陷和其他的一些问题Istio 引入了新的流量管理 API v1alpha3新版本的 API 将完全取代之前的 API。 尽管 v1alpha3 和之前的模型在本质上是基本相同的但它并不向后兼容的基于旧API的模型需要进行手动转换。</p><p>为了证明该非兼容升级的必要性v1alpha3 API 经历了漫长而艰苦的社区评估过程以希望新的API能够大幅改进并经得起时间考验。 在本文中,我们将介绍新的配置模型,并试图解释影响这次变化的一些动机和设计原则。</p><h2 id=设计原则>设计原则</h2><p>路由模型的重构过程中遵循了一些关键的设计原则:</p><ul><li>除支持声明式(意图)配置外,也支持显式指定模型依赖的基础设施。例如,除了配置入口网关(的功能特性)之外,负责实现 入口网关功能的组件Controller也可以在模型指定。</li><li>编写模型时应该&rdquo;生产者导向”和&rdquo;以 Host 为中心”,而不是通过组合多个规则来编写模型。 例如,所有与特定 Host 关联的规则被配置在一起,而不是单独配置。</li><li>将路由与路由后行为清晰分开。</li></ul><h2 id=v1alpha3-中的配置资源>v1alpha3 中的配置资源</h2><p>在一个典型的网格中,通常有一个或多个用于终结外部 TLS 链接,将流量引入网格的负载均衡器(我们称之为 gateway。 然后流量通过边车网关sidecar gateway流经内部服务。 应用程序使用外部服务的情况也很常见(例如访问 Google Maps API一些情况下这些外部服务可能被直接调用但在某些部署中网格中所有访问外部服务的流量可能被要求强制通过专用的出口网关Egress gateway。 下图描绘了网关在网格中的使用情况。</p><figure style=width:80%><div class=wrapper-with-intrinsic-ratio style=padding-bottom:35.204472660409245%><a data-skipendnotes=true href=/v1.2/blog/2018/v1alpha3-routing/gateways.svg title=Istio服务网格中的网关><img class=element-to-stretch src=/v1.2/blog/2018/v1alpha3-routing/gateways.svg alt="Role of gateways in the mesh"></a></div><figcaption>Istio服务网格中的网关</figcaption></figure><p>考虑到上述因素,<code>v1alpha3</code>引入了以下这些新的配置资源来控制进入网格,网格内部和离开网格的流量路由。</p><ol><li><code>Gateway</code></li><li><code>VirtualService</code></li><li><code>DestinationRule</code></li><li><code>ServiceEntry</code></li></ol><p><code>VirtualService</code><code>DestinationRule</code><code>ServiceEntry</code> 分别替换了原 API 中的 <code>RouteRule</code><code>DestinationPolicy</code><code>EgressRule</code><code>Gateway</code> 是一个独立于平台的抽象,用于对流入专用中间设备的流量进行建模。</p><p>下图描述了跨多个配置资源的控制流程。</p><figure style=width:80%><div class=wrapper-with-intrinsic-ratio style=padding-bottom:41.164966727369595%><a data-skipendnotes=true href=/v1.2/blog/2018/v1alpha3-routing/virtualservices-destrules.svg title=不同v1alpha3元素之间的关系><img class=element-to-stretch src=/v1.2/blog/2018/v1alpha3-routing/virtualservices-destrules.svg alt=不同v1alpha3元素之间的关系></a></div><figcaption>不同v1alpha3元素之间的关系</figcaption></figure><h3 id=gateway><code>Gateway</code></h3><p><a href=/v1.2/zh/docs/reference/config/istio.networking.v1alpha3/#Gateway><code>Gateway</code></a> 用于为 HTTP / TCP 流量配置负载均衡器,并不管该负载均衡器将在哪里运行。 网格中可以存在任意数量的 Gateway并且多个不同的 Gateway 实现可以共存。 实际上通过在配置中指定一组工作负载Pod标签可以将 Gateway 配置绑定到特定的工作负载,从而允许用户通过编写简单的 Gateway Controller 来重用现成的网络设备。</p><p>对于入口流量管理,您可能会问: <em>为什么不直接使用 Kubernetes Ingress API</em> 原因是 Ingress API 无法表达 Istio 的路由需求。 Ingress 试图在不同的 HTTP 代理之间取一个公共的交集,因此只能支持最基本的 HTTP 路由最终导致需要将代理的其他高级功能放入到注解annotation而注解的方式在多个代理之间是不兼容的无法移植。</p><p>Istio <code>Gateway</code> 通过将 L4-L6 配置与L7配置分离的方式克服了 <code>Ingress</code> 的这些缺点。 <code>Gateway</code> 只用于配置 L4-L6 功能例如对外公开的端口TLS 配置所有主流的L7代理均以统一的方式实现了这些功能。 然后,通过在 <code>Gateway</code> 上绑定 <code>VirtualService</code> 的方式,可以使用标准的 Istio 规则来控制进入 <code>Gateway</code> 的 HTTP 和 TCP 流量。</p><p>例如,下面这个简单的 <code>Gateway</code> 配置了一个 Load Balancer以允许访问 host <code>bookinfo.com</code> 的 https 外部流量进入网格中:</p><pre><code class=language-yaml data-expandlinks=true>apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
servers:
- port:
number: 443
name: https
protocol: HTTPS
hosts:
- bookinfo.com
tls:
mode: SIMPLE
serverCertificate: /tmp/tls.crt
privateKey: /tmp/tls.key
</code></pre><p>要为进入上面的 Gateway 的流量配置相应的路由,必须为同一个 host 定义一个 <code>VirtualService</code>(在下一节中描述),并使用配置中的 <code>gateways</code> 字段绑定到前面定义的 <code>Gateway</code> 上:</p><pre><code class=language-yaml data-expandlinks=true>apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo
spec:
hosts:
- bookinfo.com
gateways:
- bookinfo-gateway # &lt;---- bind to gateway
http:
- match:
- uri:
prefix: /reviews
route:
...
</code></pre><p><code>Gateway</code> 可以用于建模边缘代理或纯粹的内部代理,如第一张图所示。 无论在哪个位置,所有网关都可以用相同的方式进行配置和控制。</p><h3 id=virtualservice><code>VirtualService</code></h3><p>用一种叫做 &ldquo;Virtual services” 的东西代替路由规则可能看起来有点奇怪,但对于它配置的内容而言,这事实上是一个更好的名称,特别是在重新设计 API 以解决先前模型的可扩展性问题之后。</p><p>实际上,发生的变化是:在之前的模型中,需要用一组相互独立的配置规则来为特定的目的服务设置路由规则,并通过 precedence 字段来控制这些规则的顺序;在新的 API 中,则直接对(虚拟)服务进行配置,该虚拟服务的所有规则以一个有序列表的方式配置在对应的 <a href=/v1.2/zh/docs/reference/config/istio.networking.v1alpha3/#virtualservice><code>VirtualService</code></a> 资源中。</p><p>例如,之前在 <a href=/v1.2/zh/docs/examples/bookinfo/>Bookinfo</a> 应用程序的 <code>reviews</code> 服务中有两个 <code>RouteRule</code> 资源,如下所示:</p><pre><code class=language-yaml data-expandlinks=true>apiVersion: config.istio.io/v1alpha2
kind: RouteRule
metadata:
name: reviews-default
spec:
destination:
name: reviews
precedence: 1
route:
- labels:
version: v1
---
apiVersion: config.istio.io/v1alpha2
kind: RouteRule
metadata:
name: reviews-test-v2
spec:
destination:
name: reviews
precedence: 2
match:
request:
headers:
cookie:
regex: &#34;^(.*?;)?(user=jason)(;.*)?$&#34;
route:
- labels:
version: v2
</code></pre><p><code>v1alpha3</code>,可以在单个 <code>VirtualService</code> 资源中提供相同的配置:</p><pre><code class=language-yaml data-expandlinks=true>apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews
http:
- match:
- headers:
cookie:
regex: &#34;^(.*?;)?(user=jason)(;.*)?$&#34;
route:
- destination:
host: reviews
subset: v2
- route:
- destination:
host: reviews
subset: v1
</code></pre><p>正如你所看到的, 和 <code>reviews</code> 服务相关的两个规则集中写在了一个地方。这个改变乍一看可能觉得并没有什么特别的优势, 然而,如果仔细观察这个新模型,会发现它和之前的 API 之间存在着根本的差异,这使得 <code>v1alpha3</code> 功能更加强大。</p><p>首先,请注意 <code>VirtualService</code> 的目标服务是使用 <code>hosts</code> 字段(实际上是重复字段)指定的,然后再在每个路由的 <code>destination</code> 字段中指定。 这是与以前模型的重要区别。</p><p><code>VirtualService</code> 描述了一个或多个用户可寻址目标到网格内实际工作负载之间的映射。在上面的示例中,这两个地址是相同的,但实际上用户可寻址目标可以是任何用于定位服务的,具有可选通配符前缀或 CIDR 前缀的 DNS 名称。
这对于应用从单体架构到微服务架构的迁移过程特别有用,单体应用被拆分为多个独立的微服务后,采用 <code>VirtualService</code> 可以继续把多个微服务对外暴露为同一个目标地址,而不需要服务消费者进行修改以适应该变化。</p><p>例如,以下规则允许服务消费者访问 Bookinfo 应用程序的 reviews 和 ratings 服务,就好像它们是 <code>http://bookinfo.com/</code>(虚拟)服务的一部分:</p><pre><code class=language-yaml data-expandlinks=true>apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo
spec:
hosts:
- bookinfo.com
http:
- match:
- uri:
prefix: /reviews
route:
- destination:
host: reviews
- match:
- uri:
prefix: /ratings
route:
- destination:
host: ratings
...
</code></pre><p>实际上在 <code>VirtualService</code> 中 hosts 部分设置只是虚拟的目的地,因此不一定是已在网格中注册的服务。这允许用户为在网格内没有可路由条目的虚拟主机的流量进行建模。 通过将 <code>VirtualService</code> 绑定到同一 Host 的 <code>Gateway</code> 配置(如前一节所述 ),可向网格外部暴露这些 Host。</p><p>除了这个重大的重构之外, <code>VirtualService</code> 还包括其他一些重要的改变:</p><ol><li><p>可以在 <code>VirtualService</code> 配置中表示多个匹配条件,从而减少对冗余的规则设置。</p></li><li><p>每个服务版本都有一个名称(称为服务子集)。 属于某个子集的一组 Pod/VM 在 <code>DestinationRule</code> 定义,具体定义参见下节。</p></li><li><p>通过使用带通配符前缀的 DNS 来指定 <code>VirtualService</code> 的 host可以创建单个规则以作用于所有匹配的服务。 例如,在 Kubernetes 中,在 <code>VirtualService</code> 中使用 <code>*.foo.svc.cluster.local</code> 作为 host ,可以对 <code>foo</code> 命名空间中的所有服务应用相同的重写规则。</p></li></ol><h3 id=destinationrule><code>DestinationRule</code></h3><p><a href=/v1.2/zh/docs/reference/config/istio.networking.v1alpha3/#destinationrule><code>DestinationRule</code></a> 配置将流量转发到服务时应用的策略集。 这些策略应由服务提供者撰写用于描述断路器负载均衡设置TLS 设置等。
除了下述改变外,<code>DestinationRule</code> 与其前身 <code>DestinationPolicy</code> 大致相同。</p><ol><li><code>DestinationRule</code><code>host</code> 可以包含通配符前缀,以允许单个规则应用于多个服务。</li><li><code>DestinationRule</code> 定义了目的 host 的子集 <code>subsets</code> (例如:命名版本)。 这些 subset 用于 <code>VirtualService</code> 的路由规则设置中,可以将流量导向服务的某些特定版本。 通过这种方式为版本命名后,可以在不同的 virtual service 中明确地引用这些命名版本的 subset简化 Istio 代理发出的统计数据,并可以将 subset 编码到 SNI 头中。
为 reviews 服务配置策略和 subsets 的 <code>DestinationRule</code> 可能如下所示:</li></ol><pre><code class=language-yaml data-expandlinks=true>apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: reviews
spec:
host: reviews
trafficPolicy:
loadBalancer:
simple: RANDOM
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
trafficPolicy:
loadBalancer:
simple: ROUND_ROBIN
- name: v3
labels:
version: v3
</code></pre><p>注意,与 <code>DestinationPolicy</code> 不同的是,可在单个 <code>DestinationRule</code> 中指定多个策略(例如上面实例中的缺省策略和 v2 版本特定的策略)。</p><h3 id=serviceentry><code>ServiceEntry</code></h3><p><a href=/v1.2/zh/docs/reference/config/istio.networking.v1alpha3/#serviceentry><code>ServiceEntry</code></a> 用于将附加条目添加到 Istio 内部维护的服务注册表中。
它最常用于对访问网格外部依赖的流量进行建模,例如访问 Web 上的 API 或遗留基础设施中的服务。</p><p>所有以前使用 <code>EgressRule</code> 进行配置的内容都可以通过 <code>ServiceEntry</code> 轻松完成。 例如,可以使用类似这样的配置来允许从网格内部访问一个简单的外部服务:</p><pre><code class=language-yaml data-expandlinks=true>apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: foo-ext
spec:
hosts:
- foo.com
ports:
- number: 80
name: http
protocol: HTTP
</code></pre><p>也就是说,<code>ServiceEntry</code> 比它的前身具有更多的功能。首先,<code>ServiceEntry</code> 不限于外部服务配置,它可以有两种类型:网格内部或网格外部。网格内部条目只是用于向网格显式添加服务,添加的服务与其他内部服务一样。采用网格内部条目,可以把原本未被网格管理的基础设施也纳入到网格中(例如,把虚机中的服务添加到基于 Kubernetes 的服务网格中)。网格外部条目则代表了网格外部的服务。对于这些外部服务来说,双向 TLS 身份验证是禁用的,并且策略是在客户端执行的,而不是在像内部服务请求一样在服务器端执行策略。</p><p>由于 <code>ServiceEntry</code> 配置只是将服务添加到网格内部的服务注册表中,因此它可以像注册表中的任何其他服务一样,与 <code>VirtualService</code> 和/或 <code>DestinationRule</code> 一起使用。例如,以下 <code>DestinationRule</code> 可用于启动外部服务的 双向 TLS 连接:</p><pre><code class=language-yaml data-expandlinks=true>apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: foo-ext
spec:
name: foo.com
trafficPolicy:
tls:
mode: MUTUAL
clientCertificate: /etc/certs/myclientcert.pem
privateKey: /etc/certs/client_private_key.pem
caCertificates: /etc/certs/rootcacerts.pem
</code></pre><p>除了扩展通用性以外,<code>ServiceEntry</code> 还提供了其他一些有关 <code>EgressRule</code> 改进,其中包括:</p><ol><li>一个 <code>ServiceEntry</code> 可以配置多个服务端点,这在之前需要采用多个 <code>EgressRules</code> 来实现。</li><li>现在可以配置服务端点的解析模式(<code>NONE</code><code>STATIC</code><code>DNS</code>)。</li><li>此外,我们正在努力解决另一个难题:目前需要通过纯文本端口访问安全的外部服务(例如 <code>http://google.com:443</code>)。该问题将会在未来几周内得到解决,届时将允许从应用程序直接访问 <code>https://google.com</code>。请继续关注解决此限制的 Istio 补丁版本0.8.x</li></ol><h2 id=创建和删除-v1alpha3-路由规则>创建和删除 v1alpha3 路由规则</h2><p>由于一个特定目的地的所有路由规则现在都存储在单个 <code>VirtualService</code> 资源的一个有序列表中,因此为该目的地添加新的规则不需要再创建新的 <code>RouteRule</code>,而是通过更新该目的地的 <code>VirtualService</code> 资源来实现。</p><p>旧的路由规则:</p><pre><code class=language-bash data-expandlinks=true>$ kubectl apply -f my-second-rule-for-destination-abc.yaml
</code></pre><p><code>v1alpha3</code> 路由规则:</p><pre><code class=language-bash data-expandlinks=true>$ kubectl apply -f my-updated-rules-for-destination-abc.yaml
</code></pre><p>通过使用<code>kubectl apply</code>更新现有资源,也可以删除特定目的地的最后一个路径规则。</p><p>在添加或删除引用服务版本的路由时,需要在该服务相应的 <code>DestinationRule</code> 更新 <code>subsets</code> 。 正如你可能猜到的,这也是使用 <code>kubectl apply</code> 完成的。</p><h2 id=总结>总结</h2><p>Istio <code>v1alpha3</code> 路由 API 具有比其前身更多的功能,但不幸的是新的 API 并不向后兼容,旧的模型升级需要一次手动转换。 Istio 0.9以后将不再支持 <code>RouteRule</code><code>DesintationPolicy</code><code>EgressRule</code> 这些以前的配置资源 。Kubernetes 用户可以继续使用 <code>Ingress</code> 配置边缘负载均衡器来实现基本的路由。 但是,高级路由功能(例如,跨两个版本的流量分割)则需要使 <code>用Gateway</code> 这是一种功能更强大Istio 推荐的 <code>Ingress</code> 替代品。</p><h2 id=致谢>致谢</h2><p>感谢以下人员为新版本的路由模型重构和实现工作做出的贡献(按字母顺序)</p><ul><li>Frank Budinsky (IBM)</li><li>Zack Butcher (Google)</li><li>Greg Hanson (IBM)</li><li>Costin Manolache (Google)</li><li>Martin Ostrowski (Google)</li><li>Shriram Rajagopalan (VMware)</li><li>Louis Ryan (Google)</li><li>Isaiah Snell-Feikema (IBM)</li><li>Kuat Yessenov (Google)</li></ul><nav id=see-also><h2>相关内容</h2><div class=see-also><div class=entry><p class=link><a data-skipendnotes=true href=/v1.2/zh/blog/2019/multicluster-version-routing/>多集群服务网格中的分版本路由</a></p><p class=desc>在多集群服务网格环境中配置 Istio 的路由规则。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.2/zh/blog/2019/egress-performance/>Egress gateway 性能测试</a></p><p class=desc>评估加入 Egress gateway 对性能造成的影响。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.2/zh/blog/2019/data-plane-setup/>Istio Sidecar 注入过程解密</a></p><p class=desc>Istio 将数据面组件注入到现存部署之中的过程。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.2/zh/blog/2019/custom-ingress-gateway/>使用 Cert-Manager 部署一个自定义 Ingress 网关</a></p><p class=desc>如何使用 cert-manager 手工部署一个自定义 Ingress 网关。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.2/zh/blog/2018/incremental-traffic-management/>增量式应用 Istio 第一部分,流量管理</a></p><p class=desc>如何在不部署 Sidecar 代理的情况下使用 Istio 进行流量管理。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.2/zh/blog/2018/egress-mongo/>使用外部 MongoDB 服务</a></p><p class=desc>描述了一个基于 Istio 的 Bookinfo 示例的简单场景。</p></div></div></nav></article><nav class=pagenav><div class=left><a title="描述如何配置 Istio 进行 HTTP Egress 流量监控和访问策略。" href=/v1.2/zh/blog/2018/egress-monitoring-access-control/><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#left-arrow"/></svg>HTTP Egress 流量监控和访问策略</a></div><div class=right><a title="描述如何在AWS上使用网络负载均衡器配置 Istio Ingress。" href=/v1.2/zh/blog/2018/aws-nlb/>使用AWS NLB 配置 Istio Ingress<svg class="icon"><use xlink:href="/v1.2/img/icons.svg#right-arrow"/></svg></a></div></nav><div id=endnotes-container aria-hidden=true><h2>链接</h2><ol id=endnotes></ol></div></div><div class=toc-container><nav class=toc aria-label="Table of Contents"><div id=toc><ol><li role=none aria-label=设计原则><a href=#%e8%ae%be%e8%ae%a1%e5%8e%9f%e5%88%99>设计原则</a><li role=none aria-label="v1alpha3 中的配置资源"><a href=#v1alpha3-%e4%b8%ad%e7%9a%84%e9%85%8d%e7%bd%ae%e8%b5%84%e6%ba%90>v1alpha3 中的配置资源</a><ol><li role=none aria-label=Gateway><a href=#gateway><code>Gateway</code></a><li role=none aria-label=VirtualService><a href=#virtualservice><code>VirtualService</code></a><li role=none aria-label=DestinationRule><a href=#destinationrule><code>DestinationRule</code></a><li role=none aria-label=ServiceEntry><a href=#serviceentry><code>ServiceEntry</code></a></ol></li><li role=none aria-label="创建和删除 v1alpha3 路由规则"><a href=#%e5%88%9b%e5%bb%ba%e5%92%8c%e5%88%a0%e9%99%a4-v1alpha3-%e8%b7%af%e7%94%b1%e8%a7%84%e5%88%99>创建和删除 v1alpha3 路由规则</a><li role=none aria-label=总结><a href=#%e6%80%bb%e7%bb%93>总结</a><li role=none aria-label=致谢><a href=#%e8%87%b4%e8%b0%a2>致谢</a><li role=none aria-label=相关内容><a href=#see-also>相关内容</a></li></ol></div></nav></div></main><footer><div class=user-links><a class=channel title="Go download Istio 1.2.5 now" href=https://github.com/istio/istio/releases/tag/1.2.5 aria-label="Download Istio"><span>download</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#download"/></svg>
</a><a class=channel title="加入 Istio discussion board 参与讨论获取帮助" href=https://discuss.istio.io aria-label="Istio discussion board"><span>discuss</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#discourse"/></svg></a>
<a class=channel title="Stack Overflow 中列举了针对实际问题以及部署、配置和使用 Istio 的各项回答" href=https://stackoverflow.com/questions/tagged/istio aria-label="Stack Overflow"><span>stack overflow</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#stackoverflow"/></svg></a>
<a class=channel title="在 Slack 上与 Istio 社区交互讨论开发问题(仅限邀请)" href=https://istio.slack.com aria-label=slack><span>slack</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#slack"/></svg></a>
<a class=channel title="关注我们的 Twitter 来获取最新信息" href=https://twitter.com/IstioMesh aria-label=Twitter><span>twitter</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#twitter"/></svg></a><div class=tag>对于用户</div></div><div class=info><p class=copyright>中文内容由 ServiceMesher 社区维护,部分文档可能稍微滞后于英文版本,同步工作持续进行中<br>Istio 归档
1.2.5<br>&copy; 2019 Istio Authors, <a href=https://policies.google.com/privacy>隐私政策</a><br>归档于 2019年9月12日</p></div><div class=dev-links><a class=channel title="Istio 的代码在 GitHub 上开发" href=https://github.com/istio/community aria-label=GitHub><span>github</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#github"/></svg></a>
<a class=channel title="如果您想深入了解 Istio 的技术细节,请查看我们日益完善的设计文档" href=https://groups.google.com/forum/#!forum/istio-team-drive-access aria-label="team drive"><span>drive</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#drive"/></svg></a>
<a class=channel title="如果您想为 Istio 项目做出贡献,请考虑加入我们的工作组" href=https://github.com/istio/community/blob/master/WORKING-GROUPS.md aria-label="working groups"><span>working groups</span><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#working-groups"/></svg></a><div class=tag>对于开发者</div></div></footer><div id=scroll-to-top-container aria-hidden=true><button id=scroll-to-top title=回到顶部><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#top"/></svg></button></div></body></html>