istio.io/archive/v1.1/zh/help/ops/traffic-management/deploy-guidelines/index.html

145 lines
32 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=部署和配置指南><meta name=description content=提供特定的部署和配置指南。><meta name=keywords content=microservices,services,mesh><meta property=og:title content=部署和配置指南><meta property=og:type content=website><meta property=og:description content=提供特定的部署和配置指南。><meta property=og:url content=/v1.1/zh/help/ops/traffic-management/deploy-guidelines/><meta property=og:image content=/v1.1/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.1 / 部署和配置指南</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.1/feed.xml><link rel="shortcut icon" href=/v1.1/favicons/favicon.ico><link rel=apple-touch-icon href=/v1.1/favicons/apple-touch-icon-180x180.png sizes=180x180><link rel=icon type=image/png href=/v1.1/favicons/favicon-16x16.png sizes=16x16><link rel=icon type=image/png href=/v1.1/favicons/favicon-32x32.png sizes=32x32><link rel=icon type=image/png href=/v1.1/favicons/android-36x36.png sizes=36x36><link rel=icon type=image/png href=/v1.1/favicons/android-48x48.png sizes=48x48><link rel=icon type=image/png href=/v1.1/favicons/android-72x72.png sizes=72x72><link rel=icon type=image/png href=/v1.1/favicons/android-96x96.png sizes=96xW96><link rel=icon type=image/png href=/v1.1/favicons/android-144x144.png sizes=144x144><link rel=icon type=image/png href=/v1.1/favicons/android-192x192.png sizes=192x192><link rel=manifest href=/v1.1/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.1/css/all.css></head><body class="language-unknown archive-site"><script src=/v1.1/js/themes_init.min.js></script><script>const branchName="release-1.1";const docTitle="部署和配置指南";const iconFile="\/v1.1/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.1/js/all.min.js data-manual defer></script><header><nav><a id=brand href=/v1.1/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.1</span></a><div id=hamburger><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#hamburger"/></svg></div><div id=header-links><a title="了解如何部署、使用和运维 Istio。" href=/v1.1/zh/docs/>文档</a>
<a title="关于使用 Istio 的博客文章。" href=/v1.1/zh/blog/2019/root-transition/>博客</a>
<span title="一堆帮助您部署、配置和使用 Istio 的资源。">帮助</span>
<a title=关于Istio的说明。 href=/v1.1/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.1/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/help\/ops\/traffic-management\/deploy-guidelines\/');return false;">当前版本</a>
<a tabindex=-1 role=menuitem onclick="navigateToUrlOrRoot('https://preliminary.istio.io/help\/ops\/traffic-management\/deploy-guidelines\/');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.1/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.1/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.1/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><div id=header0 class=header title="一堆帮助您部署、配置和使用 Istio 的资源。"><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#help"/></svg>需要帮助吗?</div><div class="body default" aria-labelledby=header0><ul role=tree aria-expanded=true aria-labelledby=header0><li role=treeitem aria-label=运维指南><button class=show aria-hidden=true></button><a title="关于运行 Istio 网格的提示、技巧和窍门。" href=/v1.1/zh/help/ops/>运维指南</a><ul role=group aria-expanded=true><li role=none><a role=treeitem title=描述如何使用组件日志来深入了解运行组件的行为。 href=/v1.1/zh/help/ops/component-logging/>组件日志</a></li><li role=none><a role=treeitem title="描述如何使用 ControlZ 检测查看单个组件的运行状态。" href=/v1.1/zh/help/ops/controlz/>组件内检</a></li><li role=none><a role=treeitem title="如何从底层调试 Istio 组件。" href=/v1.1/zh/help/ops/component-debugging/>组件调试</a></li><li role=treeitem aria-label=流量管理><button class=show aria-hidden=true></button><a title=帮助管理服务网格中的网络。 href=/v1.1/zh/help/ops/traffic-management/>流量管理</a><ul role=group aria-expanded=true class=leaf-section><li role=none><a role=treeitem title="介绍 Istio 网络操作方面知识。" href=/v1.1/zh/help/ops/traffic-management/introduction/>网络运维介绍</a></li><li role=none><span role=treeitem class=current title=提供特定的部署和配置指南。>部署和配置指南</span></li><li role=none><a role=treeitem title=常见网络相关问题的识别和处理。 href=/v1.1/zh/help/ops/traffic-management/troubleshooting/>网络问题排查</a></li><li role=none><a role=treeitem title=有关如何启用和理解本地负载均衡的信息。 href=/v1.1/zh/help/ops/traffic-management/locality-load-balancing/>本地负载均衡</a></li><li role=none><a role=treeitem title="用于对流量管理方面的 Envoy 配置问题进行检测的工具和技术。" href=/v1.1/zh/help/ops/traffic-management/proxy-cmd/>调试 Envoy 和 Pilot</a></li><li role=none><a role=treeitem title=介绍一些工具和技术,用来针对流量管理方面的配置问题进行诊断。 href=/v1.1/zh/help/ops/traffic-management/observing/>配置问题诊断</a></li></ul></li><li role=treeitem aria-label=安全><button aria-hidden=true></button><a title=帮助你管理运行中的网格的安全性方面问题。 href=/v1.1/zh/help/ops/security/>安全</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title=展示授权功能的调试过程。 href=/v1.1/zh/help/ops/security/debugging-authorization/>调试授权</a></li><li role=none><a role=treeitem title="如果 Citadel 表现不正常该怎么办。" href=/v1.1/zh/help/ops/security/repairing-citadel/>修复 Citadel</a></li><li role=none><a role=treeitem title="如果您怀疑 Istio 密钥和证书有问题该怎么办。" href=/v1.1/zh/help/ops/security/keys-and-certs/>密钥和证书</a></li><li role=none><a role=treeitem title="如何处理 TLS 认证的失效问题。" href=/v1.1/zh/help/ops/security/mutual-tls/>双向 TLS</a></li><li role=none><a role=treeitem title="如何在启用双向 TLS 的情况下运行健康检查。" href=/v1.1/zh/help/ops/security/health-checks-and-mtls/>健康检查和双向 TLS</a></li><li role=none><a role=treeitem title=已经启用了授权,但是无论如何请求还是会通过。 href=/v1.1/zh/help/ops/security/authorization-permissive/>授权太过宽松</a></li><li role=none><a role=treeitem title=启用了授权然后任何请求都无法到达服务。 href=/v1.1/zh/help/ops/security/authorization-restrictive/>授权过于严格</a></li><li role=none><a role=treeitem title=如果终端用户身份验证不起作用,该怎么办。 href=/v1.1/zh/help/ops/security/end-user-auth/>终端用户身份验证</a></li><li role=none><a role=treeitem title="学习如何延长 Istio 自签发根证书的有效期。" href=/v1.1/zh/help/ops/security/root-transition/>延长自签发证书的有效期</a></li></ul></li><li role=treeitem aria-label=遥测><button aria-hidden=true></button><a title=帮助您在一个运行的服务网格中管理遥测数据的采集和可视化。 href=/v1.1/zh/help/ops/telemetry/>遥测</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem href=/v1.1/zh/help/ops/telemetry/missing-metrics/>查看不到指标</a></li><li role=none><a role=treeitem title="处理 Grafana 相关问题。" href=/v1.1/zh/help/ops/telemetry/grafana/>Grafana</a></li><li role=none><a role=treeitem title="Envoy 统计数据的细粒度控制。" href=/v1.1/zh/help/ops/telemetry/envoy-stats/>Envoy 统计数据</a></li></ul></li><li role=treeitem aria-label=安装和设置><button aria-hidden=true></button><a title="帮助诊断和修复 Isto 安装问题。" href=/v1.1/zh/help/ops/setup/>安装和设置</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="概述了 Istio 使用 Kubernetes Webhook 及可能出现的相关问题。" href=/v1.1/zh/help/ops/setup/webhook/>动态准入 Webhook 概述</a></li><li role=none><a role=treeitem title="Istio 使用 Kubernetes webhook 进行服务器端配置验证的方式。" href=/v1.1/zh/help/ops/setup/validation/>配置验证 Webhook</a></li><li role=none><a role=treeitem title="描述了 Istio 如何使用 Kubernetes webhooks 进行自动 sidecar 注入。" href=/v1.1/zh/help/ops/setup/injection/>Sidecar 注入 Webhook</a></li><li role=none><a role=treeitem title="如何检查 Pod 中被许可的功能。" href=/v1.1/zh/help/ops/setup/required-pod-capabilities/>Pod 的必要功能</a></li><li role=none><a role=treeitem title="展示如何对 Istio service 进行健康检查。" href=/v1.1/zh/help/ops/setup/app-health-check/>Istio Service 健康检查</a></li></ul></li><li role=none><a role=treeitem title="关于解决 Istio 常见问题的建议。" href=/v1.1/zh/help/ops/misc/>杂项</a></li></ul></li><li role=treeitem aria-label=FAQ><button aria-hidden=true></button><a title=关于Istio的常见问题。 href=/v1.1/zh/help/faq/>FAQ</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title=常见问题。 href=/v1.1/zh/help/faq/general/>常见问题</a></li><li role=none><a role=treeitem title="安装 Q &amp; A。" href=/v1.1/zh/help/faq/setup/>安装</a></li><li role=none><a role=treeitem title=安全方面的常见问题。 href=/v1.1/zh/help/faq/security/>安全</a></li><li role=none><a role=treeitem title="Mixer Q &amp; A。" href=/v1.1/zh/help/faq/mixer/>Mixer</a></li><li role=none><a role=treeitem title=度量和日志的常见问题。 href=/v1.1/zh/help/faq/metrics-and-logs/>度量和日志</a></li><li role=none><a role=treeitem title="遥测 Q &amp; A." href=/v1.1/zh/help/faq/telemetry/>遥测</a></li><li role=none><a role=treeitem title=分布式追踪问答。 href=/v1.1/zh/help/faq/distributed-tracing/>分布式追踪</a></li><li role=none><a role=treeitem title="流量管理 Q &amp; A。" href=/v1.1/zh/help/faq/traffic-management/>流量管理</a></li></ul></li><li role=none><a role=treeitem title="Istio 常见的术语表。" href=/v1.1/zh/help/glossary/>术语表</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.1/img/icons.svg#pull"/></svg></button><nav aria-label=Breadcrumb><ol><li><a href=/v1.1/zh/>Istio</a></li><li><a href=/v1.1/zh/help/ title="一堆帮助您部署、配置和使用 Istio 的资源。">帮助</a></li><li><a href=/v1.1/zh/help/ops/ title="关于运行 Istio 网格的提示、技巧和窍门。">运维指南</a></li><li><a href=/v1.1/zh/help/ops/traffic-management/ title=帮助管理服务网格中的网络。>流量管理</a></li><li>部署和配置指南</li></ol></nav><article aria-labelledby=title><div class=title-area><div><h1 id=title>部署和配置指南</h1><p class=byline><span title="499 字"><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#clock"/></svg><span>&nbsp;</span>阅读大约需要 3 分钟</span></p></div></div><nav class=toc-inlined aria-label="Table of Contents"><div><hr><ol><li role=none aria-label="在网关中配置多个 TLS 主机"><a href=#%e5%9c%a8%e7%bd%91%e5%85%b3%e4%b8%ad%e9%85%8d%e7%bd%ae%e5%a4%9a%e4%b8%aa-tls-%e4%b8%bb%e6%9c%ba>在网关中配置多个 TLS 主机</a><li role=none aria-label="为同一主机名配置多个 VirtualService 和 DestinationRule"><a href=#%e4%b8%ba%e5%90%8c%e4%b8%80%e4%b8%bb%e6%9c%ba%e5%90%8d%e9%85%8d%e7%bd%ae%e5%a4%9a%e4%b8%aa-virtualservice-%e5%92%8c-destinationrule>为同一主机名配置多个 <code>VirtualService</code><code>DestinationRule</code></a><li role=none aria-label="重新配置服务路由后,如何避免 503 错误"><a href=#%e9%87%8d%e6%96%b0%e9%85%8d%e7%bd%ae%e6%9c%8d%e5%8a%a1%e8%b7%af%e7%94%b1%e5%90%8e-%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d-503-%e9%94%99%e8%af%af>重新配置服务路由后,如何避免 503 错误</a><li role=none aria-label="多个网关共用同一个 TLS 证书时引起浏览器问题"><a href=#%e5%a4%9a%e4%b8%aa%e7%bd%91%e5%85%b3%e5%85%b1%e7%94%a8%e5%90%8c%e4%b8%80%e4%b8%aa-tls-%e8%af%81%e4%b9%a6%e6%97%b6%e5%bc%95%e8%b5%b7%e6%b5%8f%e8%a7%88%e5%99%a8%e9%97%ae%e9%a2%98>多个网关共用同一个 TLS 证书时引起浏览器问题</a></ol><hr></div></nav><p>本节提供了特定的部署或配置指南,以避免网络或流量管理出现问题。</p><h2 id=在网关中配置多个-tls-主机>在网关中配置多个 TLS 主机</h2><p>如果您要创建一个 <code>Gateway</code>,新的 <code>Gateway</code> 与另一个现有 <code>Gateway</code> 具备相同 <code>selector</code> 配置,并且它们还开放了相同的 HTTPS 端口,这种情况下必须确保它们具有唯一的端口名称。否则,提交时候虽然不会立即看到错误提示,但运行时网关配置中会忽略该配置(重名端口的配置将被忽略)。例如:</p><pre><code class=language-yaml data-expandlinks=true>apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: mygateway
spec:
selector:
istio: ingressgateway # 使用 istio 默认 ingress gateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
tls:
mode: SIMPLE
serverCertificate: /etc/istio/ingressgateway-certs/tls.crt
privateKey: /etc/istio/ingressgateway-certs/tls.key
hosts:
- &#34;myhost.com&#34;
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: mygateway2
spec:
selector:
istio: ingressgateway # 使用 istio 默认 ingress gateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
tls:
mode: SIMPLE
serverCertificate: /etc/istio/ingressgateway-certs/tls.crt
privateKey: /etc/istio/ingressgateway-certs/tls.key
hosts:
- &#34;myhost2.com&#34;
</code></pre><p>使用此配置,对第二个主机 <code>myhost2.com</code> 的请求将失败,因为两个网关端口都具有 <code>name: https</code>
例如,<code>curl</code> 请求将产生如下错误消息:</p><pre><code class=language-plain data-expandlinks=true>curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to myhost2.com:443
</code></pre><p>您可以通过检查 Pilot 的日志以查找类似于以下内容的消息来确认是否发生了这种情况:</p><pre><code class=language-bash data-expandlinks=true>$ kubectl logs -n istio-system $(kubectl get pod -l istio=pilot -n istio-system -o jsonpath={.items..metadata.name}) -c discovery | grep &#34;non unique port&#34;
2018-09-14T19:02:31.916960Z info model skipping server on gateway mygateway2 port https.443.HTTPS: non unique port name for HTTPS port
</code></pre><p>要避免此问题,请确保对同一 <code>protocol: HTTPS</code> 端口的每次使用都进行唯一命名。
例如,将第二个更改为 <code>https2</code></p><pre><code class=language-yaml data-expandlinks=true>apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: mygateway2
spec:
selector:
istio: ingressgateway # 使用 istio 默认 ingress gateway
servers:
- port:
number: 443
name: https2
protocol: HTTPS
tls:
mode: SIMPLE
serverCertificate: /etc/istio/ingressgateway-certs/tls.crt
privateKey: /etc/istio/ingressgateway-certs/tls.key
hosts:
- &#34;myhost2.com&#34;
</code></pre><h2 id=为同一主机名配置多个-virtualservice-和-destinationrule>为同一主机名配置多个 <code>VirtualService</code><code>DestinationRule</code></h2><p>有的情况下可能不方便在单一的 <code>VirtualService</code> 或者 <code>DestinationRule</code> 资源中定义完整的策略或路由规则。如果能够用渐进的方式,在多个资源中为一个主机名完成定义配置,可能会很有帮助。</p><p>从 Istio 1.0.1 开始,添加了一个实验性功能,在<strong>绑定到网关时</strong><code>VirtualService</code><code>DestinationRule</code> 进行合并。</p><p>例如一个绑定到 Ingress网关的 <code>VirtualService</code>,它用主机名对外提供服务,使用基于路径的路由来为多个应用来提供转发服务:</p><pre><code class=language-yaml data-expandlinks=true>apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myapp
spec:
hosts:
- myapp.com
gateways:
- myapp-gateway
http:
- match:
- uri:
prefix: /service1
route:
- destination:
host: service1.default.svc.cluster.local
- match:
- uri:
prefix: /service2
route:
- destination:
host: service2.default.svc.cluster.local
- match:
...
</code></pre><p>这种配置的缺点是,任何底层微服务的其他配置(例如路由规则)也需要包含在该配置文件中,
而不是包含在与之相关联并且可能由各个服务团队拥有的单独配置文件中。有关详细信息,
在运维指南中的<a href=/v1.1/zh/help/ops/traffic-management/troubleshooting/#路由规则在-ingress-gateway-请求中无效>“路由规则对 Ingress网关请求中无效”</a>一节中提供了介绍。</p><p>为了避免这个问题,可能最好将 <code>myapp.com</code> 的配置分解为几个 <code>VirtualService</code> 片段,每个后端服务一个。例如:</p><pre><code class=language-yaml data-expandlinks=true>apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myapp-service1
spec:
hosts:
- myapp.com
gateways:
- myapp-gateway
http:
- match:
- uri:
prefix: /service1
route:
- destination:
host: service1.default.svc.cluster.local
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myapp-service2
spec:
hosts:
- myapp.com
gateways:
- myapp-gateway
http:
- match:
- uri:
prefix: /service2
route:
- destination:
host: service2.default.svc.cluster.local
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myapp-...
</code></pre><p>当把第二个和后续的 <code>VirtualService</code> 应用到现有主机名上的时候,<code>istio-pilot</code> 会将其他路由规则合并到主机的现有配置中。但是,有一些注意事项,使用时必须仔细考虑。</p><ol><li><p>单一 <code>VirtualService</code> 中的规则评估顺序是固定的,然而跨资源的情况下就不可预料了。换句话说,在这种碎片化的配置之中,规则的评估顺序是没有保障的,因此应该对分片资源进行预测,防止其中出现冲突或者顺序依赖,这样才能保障工作正常进行。</p></li><li><p>多个配置片段中,应该只有一个“全部捕获”规则(即,匹配任何请求路径或 Header 的规则)。配置合并时,所有这些“全部捕获”规则会被移动到列表的末尾。(如果这类规则不止一个)由于它们会匹配所有请求,所以最先应用的规则会覆盖和禁用其它所有的同类规则</p></li><li><p>Sidecar 不支持主机合并,只有绑定到网关支持 <code>VirtualService</code> 分段方式。</p></li></ol><p><code>DestinationRule</code> 也可以使用类似的合并语义和限制进行分段。</p><ol><li><p>对于同一主机,跨多个目标规则应该只有一个给定子集的定义。如果存在多个具有相同名称的定义,则使用第一个定义,其他重复项将失效。不支持合并子集内容。</p></li><li><p>对于同一主机,应该只有一个顶级的 <code>trafficPolicy</code>。在多个目标规则中定义顶级流量策略时,将使用第一个。任何其它的顶级 <code>trafficPolicy</code> 配置都将失效。</p></li><li><p>不同于 <code>VirtualService</code> 的合并,目标规则合并在 Sidecar 和网关中都有效。</p></li></ol><h2 id=重新配置服务路由后-如何避免-503-错误>重新配置服务路由后,如何避免 503 错误</h2><p>为了将流量转发到服务的特定版本(子集),在配置对应的路由规则时,必须注意在路由投入使用之前,确保子集已经可用。否则对服务的调用就会返回 503 错误。</p><p>使用 <code>kubectl</code> 命令一次性的创建 <code>VirtualService</code><code>DestinationRule</code> 的方式(例如 <code>kubectl apply -f myVirtualServiceAndDestinationRule.yaml</code>)无法避免这类错误,这是因为资源对象的传播(从配置服务器,例如 Kubernetes API Server过程是最终一致的方式。如果引用子集的 <code>VirtualService</code>,先于 <code>DestinationRule</code> 完成传播,那么 Pilot 生成的 Envoy 配置中,就会出现上游服务不存在的故障。因此会出现 503 错误,直到所有配置对象都成功完成传播。</p><p>在配置引用子集的 <code>VirtualService</code> 时,如果想要避免发生服务中断,应遵循下列流程,保证中断之前完成配置即可:</p><ul><li><p>在加入新的子集时:</p><ol><li><p>在更新相关的 <code>VirtualService</code> 之前,首先更新 <code>DestinationRules</code>,在其中加入新的子集。用 <code>kubectl</code> 或其他平台的特定方式来应用规则。</p></li><li><p>等候几秒钟,让 <code>DestinationRule</code> 配置传播给 Envoy sidecar。</p></li><li><p>更新 <code>VirtualService</code>,允许其引用新加入的子集。</p></li></ol></li><li><p>删除子集时:</p><ol><li><p>在从 <code>DestinationRule</code> 中删除子集之前,首先要更新 <code>VirtualServices</code>,移除其中对待删除子集的引用。</p></li><li><p>等待几秒钟,以便 <code>VirtualService</code> 配置传播至 Envoy sidecar。</p></li><li><p><code>DestinationRule</code> 中删除无用的子集。</p></li></ol></li></ul><h2 id=多个网关共用同一个-tls-证书时引起浏览器问题>多个网关共用同一个 TLS 证书时引起浏览器问题</h2><p>使用同一个 TLS 证书配置多于一个网关时,如果使用支持 <a href=https://httpwg.org/specs/rfc7540.html#reuse>HTTP/2 连接复用</a>的浏览器(多数浏览器都支持这一能力)来进行访问,在和第一个主机名建立连接之后,如果继续访问另一个主机名,就会出现 404 错误。</p><p>举个例子,假设有两个主机用这种方式来共享同样的 TLS 证书:</p><ul><li><p>安装在 <code>istio-ingressgateway</code> 上的通配符证书:<code>*.test.com</code></p></li><li><p>一个命名为 <code>gw1</code><code>Gateway</code> 对象,其主机名是 <code>service1.test.com</code><code>selector</code> 定义为 <code>istio: ingressgateway</code>,使用网关加载的证书来进行 TLS 认证</p></li><li><p>一个命名为 <code>gw2</code><code>Gateway</code> 对象,其主机名是 <code>service2.test.com</code><code>selector</code> 定义为 <code>istio: ingressgateway</code>,使用网关加载的证书来进行 TLS 认证</p></li><li><p>名为 <code>vs1</code><code>VirtaulService</code> 对象,主机名为 <code>service1.test.com</code>,网关设置为 <code>gw1</code></p></li><li><p>名为 <code>vs2</code><code>VirtaulService</code> 对象,主机名为 <code>service2.test.com</code>,网关设置为 <code>gw2</code></p></li></ul><p>两个网关对象使用的是一组工作负载(<code>istio: ingressgateway</code>),用同样的 IP 为两个服务提供网关支持。如果首先访问了 <code>service1.test.com</code>,会返回通配符证书 <code>*.test.com</code>,这一证书是可以用于连接 <code>service2.test.com</code> 的。Chrome 或者 Firefox 这样的浏览器会复用这已经存在的连接,来发起对 <code>service2.test.com</code> 的访问,但是 <code>gw1</code> 没有到 <code>service2.test.com</code> 的路由,所以就会返回 404 错误。</p><p>要解决这一问题,可以配置一个通用的 <code>Gateway</code> 对象,而不是分别配置两个 <code>gw1</code><code>gw2</code>。例如下面的配置:</p><ul><li><p>创建一个名为 <code>gw</code><code>Gateway</code>,对应主机为 <code>*.test.com</code>selector 仍然是 <code>istio: ingressgateway</code>TLS 还是使用网关加载的证书。</p></li><li><p><code>VirtualService</code> 对象 <code>vs1</code> 配置主机名为 <code>service1.test.com</code>,网关设置为 <code>gw</code></p></li><li><p><code>VirtualService</code> 对象 <code>vs2</code> 配置主机名为 <code>service2.test.com</code>,网关设置为 <code>gw</code></p></li></ul></article><nav class=pagenav><div class=left><a title="介绍 Istio 网络操作方面知识。" href=/v1.1/zh/help/ops/traffic-management/introduction/><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#left-arrow"/></svg>网络运维介绍</a></div><div class=right><a title=常见网络相关问题的识别和处理。 href=/v1.1/zh/help/ops/traffic-management/troubleshooting/>网络问题排查<svg class="icon"><use xlink:href="/v1.1/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="在网关中配置多个 TLS 主机"><a href=#%e5%9c%a8%e7%bd%91%e5%85%b3%e4%b8%ad%e9%85%8d%e7%bd%ae%e5%a4%9a%e4%b8%aa-tls-%e4%b8%bb%e6%9c%ba>在网关中配置多个 TLS 主机</a><li role=none aria-label="为同一主机名配置多个 VirtualService 和 DestinationRule"><a href=#%e4%b8%ba%e5%90%8c%e4%b8%80%e4%b8%bb%e6%9c%ba%e5%90%8d%e9%85%8d%e7%bd%ae%e5%a4%9a%e4%b8%aa-virtualservice-%e5%92%8c-destinationrule>为同一主机名配置多个 <code>VirtualService</code><code>DestinationRule</code></a><li role=none aria-label="重新配置服务路由后,如何避免 503 错误"><a href=#%e9%87%8d%e6%96%b0%e9%85%8d%e7%bd%ae%e6%9c%8d%e5%8a%a1%e8%b7%af%e7%94%b1%e5%90%8e-%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d-503-%e9%94%99%e8%af%af>重新配置服务路由后,如何避免 503 错误</a><li role=none aria-label="多个网关共用同一个 TLS 证书时引起浏览器问题"><a href=#%e5%a4%9a%e4%b8%aa%e7%bd%91%e5%85%b3%e5%85%b1%e7%94%a8%e5%90%8c%e4%b8%80%e4%b8%aa-tls-%e8%af%81%e4%b9%a6%e6%97%b6%e5%bc%95%e8%b5%b7%e6%b5%8f%e8%a7%88%e5%99%a8%e9%97%ae%e9%a2%98>多个网关共用同一个 TLS 证书时引起浏览器问题</a></ol></div></nav></div></main><footer><div class=user-links><a class=channel title="Go download Istio 1.1.9 now" href=https://github.com/istio/istio/releases/tag/1.1.9 aria-label="Download Istio"><span>download</span><svg class="icon"><use xlink:href="/v1.1/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.1/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.1/img/icons.svg#stackoverflow"/></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.1/img/icons.svg#twitter"/></svg></a><div class=tag>对于用户</div></div><div class=info><p class=copyright>中文内容由 ServiceMesher 社区维护,部分文档可能稍微滞后于英文版本,同步工作持续进行中<br>Istio 归档
1.1.9<br>&copy; 2019 Istio Authors, <a href=https://policies.google.com/privacy>隐私政策</a><br>归档于 2019年6月18日</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.1/img/icons.svg#github"/></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.1/img/icons.svg#slack"/></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.1/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.1/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.1/img/icons.svg#top"/></svg></button></div></body></html>