istio.io/archive/v1.1/zh/help/ops/setup/injection/index.html

88 lines
28 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="Sidecar 注入 Webhook"><meta name=description content="描述了 Istio 如何使用 Kubernetes webhooks 进行自动 sidecar 注入。"><meta name=keywords content=microservices,services,mesh><meta property=og:title content="Sidecar 注入 Webhook"><meta property=og:type content=website><meta property=og:description content="描述了 Istio 如何使用 Kubernetes webhooks 进行自动 sidecar 注入。"><meta property=og:url content=/v1.1/zh/help/ops/setup/injection/><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 / Sidecar 注入 Webhook</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="Sidecar 注入 Webhook";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\/setup\/injection\/');return false;">当前版本</a>
<a tabindex=-1 role=menuitem onclick="navigateToUrlOrRoot('https://preliminary.istio.io/help\/ops\/setup\/injection\/');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 aria-hidden=true></button><a title=帮助管理服务网格中的网络。 href=/v1.1/zh/help/ops/traffic-management/>流量管理</a><ul role=group aria-expanded=false 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><a role=treeitem title=提供特定的部署和配置指南。 href=/v1.1/zh/help/ops/traffic-management/deploy-guidelines/>部署和配置指南</a></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 class=show aria-hidden=true></button><a title="帮助诊断和修复 Isto 安装问题。" href=/v1.1/zh/help/ops/setup/>安装和设置</a><ul role=group aria-expanded=true 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><span role=treeitem class=current title="描述了 Istio 如何使用 Kubernetes webhooks 进行自动 sidecar 注入。">Sidecar 注入 Webhook</span></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/setup/ title="帮助诊断和修复 Isto 安装问题。">安装和设置</a></li><li>Sidecar 注入 Webhook</li></ol></nav><article aria-labelledby=title><div class=title-area><div><h1 id=title>Sidecar 注入 Webhook</h1><p class=byline><span title="536 字"><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=注入的结果和预期不一致><a href=#%e6%b3%a8%e5%85%a5%e7%9a%84%e7%bb%93%e6%9e%9c%e5%92%8c%e9%a2%84%e6%9c%9f%e4%b8%8d%e4%b8%80%e8%87%b4>注入的结果和预期不一致</a><li role=none aria-label="Pod 完全不能创建"><a href=#pod-%e5%ae%8c%e5%85%a8%e4%b8%8d%e8%83%bd%e5%88%9b%e5%bb%ba>Pod 完全不能创建</a><ol><li role=none aria-label="x509 证书相关的错误"><a href=#x509-%e8%af%81%e4%b9%a6%e7%9b%b8%e5%85%b3%e7%9a%84%e9%94%99%e8%af%af>x509 证书相关的错误</a><li role=none aria-label="部署状态中出现 no such hosts 或 no endpoints available 错误"><a href=#%e9%83%a8%e7%bd%b2%e7%8a%b6%e6%80%81%e4%b8%ad%e5%87%ba%e7%8e%b0-no-such-hosts-%e6%88%96-no-endpoints-available-%e9%94%99%e8%af%af>部署状态中出现 <code>no such hosts</code><code>no endpoints available</code> 错误</a></ol></li></ol><hr></div></nav><p>自动 Sidecar 注入可将 Sidecar 代理添加到用户创建的 Pod 之中。在创建 Pod 时,它使用 <code>MutatingWebhook</code> 将 Sidecar 容器和卷附加到每个 Pod 的中。可以使用 Webhook 的<code>namespaceSelector</code> 机制将注入范围限定为特定的命名空间,也可以使用注解为每个 Pod 启用和禁用注入。</p><p>是否进行 Sidecar 注入取决于以下三个条件:</p><ul><li><p>Webhook 的 <code>namespaceSelector</code></p></li><li><p>默认 <code>Policy</code></p></li><li><p>每个 Pod 的注解</p></li></ul><p>下面的表格展示了基于三个条件变量的最终的注入状态。</p><table><thead><tr><th><code>namespaceSelector</code> 匹配</th><th>默认 <code>Policy</code></th><th>Pod 注解 <code>sidecar.istio.io/inject</code></th><th>Sidecar 是否注入?</th></tr></thead><tbody><tr><td>yes</td><td>enabled</td><td>true</td><td>yes</td></tr><tr><td>yes</td><td>enabled</td><td>false</td><td>no</td></tr><tr><td>yes</td><td>enabled</td><td></td><td>yes</td></tr><tr><td>yes</td><td>disabled</td><td>true</td><td>yes</td></tr><tr><td>yes</td><td>disabled</td><td>false</td><td>no</td></tr><tr><td>yes</td><td>disabled</td><td></td><td>no</td></tr><tr><td>no</td><td>enabled</td><td>true</td><td>no</td></tr><tr><td>no</td><td>enabled</td><td>false</td><td>no</td></tr><tr><td>no</td><td>enabled</td><td></td><td>no</td></tr><tr><td>no</td><td>disabled</td><td>true</td><td>no</td></tr><tr><td>no</td><td>disabled</td><td>false</td><td>no</td></tr><tr><td>no</td><td>disabled</td><td></td><td>no</td></tr></tbody></table><h2 id=注入的结果和预期不一致>注入的结果和预期不一致</h2><p>不一致包括 Sidecar 的非预期注入和非预期未注入。</p><ol><li><p>通过检查 Webhook 的 <code>namespaceSelector</code> 以确定目标命名空间是否包含或者排除在 <code>Webhook</code> 范围内。</p><p>用包含方式定义的 <code>namespaceSelector</code> 如下所示:</p><pre><code class=language-bash data-expandlinks=true data-outputis=yaml>$ kubectl get mutatingwebhookconfiguration istio-sidecar-injector -o yaml | grep &#34;namespaceSelector:&#34; -A5
namespaceSelector:
matchLabels:
istio-injection: enabled
rules:
- apiGroups:
- &#34;&#34;
</code></pre><p>在标记 <code>istio-injection=enabled</code> 标签的命名空间中创建的 Pod就会调用 Webhook。</p><pre><code class=language-bash data-expandlinks=true>$ kubectl get namespace -L istio-injection
NAME STATUS AGE ISTIO-INJECTION
default Active 18d enabled
istio-system Active 3d
kube-public Active 18d
kube-system Active 18d
</code></pre><p>用排除方式定义的 <code>namespaceSelector</code> 如下所示:</p><pre><code class=language-bash data-expandlinks=true>$ kubectl get mutatingwebhookconfiguration istio-sidecar-injector -o yaml | grep &#34;namespaceSelector:&#34; -A5
namespaceSelector:
matchExpressions:
- key: istio-injection
operator: NotIn
values:
- disabled
rules:
- apiGroups:
- &#34;&#34;
</code></pre><p>在没有标记 <code>istio-injection=disabled</code> 标签的命名空间中创建的 Pod会调用 Webhook 进行注入。</p><pre><code class=language-bash data-expandlinks=true>$ kubectl get namespace -L istio-injection
NAME STATUS AGE ISTIO-INJECTION
default Active 18d
istio-system Active 3d disabled
kube-public Active 18d disabled
kube-system Active 18d disabled
</code></pre><p>验证应用程序 Pod 的命名空间是否已相应地被正确(重新)标记,例如:</p><pre><code class=language-bash data-expandlinks=true>$ kubectl label namespace istio-system istio-injection=disabled --overwrite
</code></pre><p>(在所有应该执行 Webhook 注入的命名空间中执行这一命令)</p><pre><code class=language-bash data-expandlinks=true>$ kubectl label namespace default istio-injection=enabled --overwrite
</code></pre></li><li><p>检查默认 <code>policy</code></p><p>检查 <code>istio-sidecar-injector</code> <code>configmap</code> 中的默认注入策略。</p><pre><code class=language-bash data-expandlinks=true data-outputis=yaml>$ kubectl -n istio-system get configmap istio-sidecar-injector -o jsonpath=&#39;{.data.config}&#39; | grep policy:
policy: enabled
</code></pre><p>策略允许的取值范围是 <code>disabled</code><code>enabled</code>。仅当 webhook 的 <code>namespaceSelector</code> 与目标命名空间匹配时,默认策略才会被应用。无法识别的策略值默认为 <code>disabled</code></p></li><li><p>检查每个 Pod 的注解。</p><p>可以使用 Pod 注解 <code>sidecar.istio.io/inject</code> 来覆盖默认策略。<code>Deployment</code><code>metadata</code> 在这里是无效的。注解值为 <code>true</code> 会被强制注入 Sidecar<code>false</code> 不会注入 Sidecar。</p><p>以下注解会覆盖默认策略并强制注入 Sidecar</p><pre><code class=language-bash data-expandlinks=true data-outputis=yaml>$ kubectl get deployment sleep -o yaml | grep &#34;sidecar.istio.io/inject:&#34; -C3
template:
metadata:
annotations:
sidecar.istio.io/inject: &#34;true&#34;
labels:
app: sleep
</code></pre></li></ol><h2 id=pod-完全不能创建>Pod 完全不能创建</h2><p>在失败的 Pod 的部署上运行 <code>kubectl describe -n namespace deployment name</code>。通常能在事件日志中获取到调用注入 Webhook 失败的原因。</p><h3 id=x509-证书相关的错误>x509 证书相关的错误</h3><pre><code class=language-plain data-expandlinks=true>Warning FailedCreate 3m (x17 over 8m) replicaset-controller Error creating: Internal error occurred: \
failed calling admission webhook &#34;sidecar-injector.istio.io&#34;: Post https://istio-sidecar-injector.istio-system.svc:443/inject: \
x509: certificate signed by unknown authority (possibly because of &#34;crypto/rsa: verification error&#34; while trying \
to verify candidate authority certificate &#34;Kubernetes.cluster.local&#34;)
</code></pre><p><code>x509: certificate signed by unknown authority</code> 错误通常是因为 Webhook 中配置了空的 <code>caBundle</code></p><p>验证 <code>mutatingwebhookconfiguration</code> 配置中的 <code>caBundle</code> 是否与 <code>istio-sidecar-injector</code> 中 Pod 安装的根证书匹配。</p><pre><code class=language-bash data-expandlinks=true>$ kubectl get mutatingwebhookconfiguration istio-sidecar-injector -o yaml -o jsonpath=&#39;{.webhooks[0].clientConfig.caBundle}&#39; | md5sum
4b95d2ba22ce8971c7c92084da31faf0 -
$ kubectl -n istio-system get secret istio.istio-sidecar-injector-service-account -o jsonpath=&#39;{.data.root-cert\.pem}&#39; | md5sum
4b95d2ba22ce8971c7c92084da31faf0 -
</code></pre><p>CA 证书必须匹配。如不匹配,则可重新启动 <code>sidecar-injector</code> Pod。</p><pre><code class=language-bash data-expandlinks=true>$ kubectl -n istio-system patch deployment istio-sidecar-injector \
-p &#34;{\&#34;spec\&#34;:{\&#34;template\&#34;:{\&#34;metadata\&#34;:{\&#34;labels\&#34;:{\&#34;date\&#34;:\&#34;`date +&#39;%s&#39;`\&#34;}}}}}&#34;
deployment.extensions &#34;istio-sidecar-injector&#34; patched
</code></pre><h3 id=部署状态中出现-no-such-hosts-或-no-endpoints-available-错误>部署状态中出现 <code>no such hosts</code><code>no endpoints available</code> 错误</h3><p>注入过程是<code>故障则关闭</code>fail-close。如果 <code>istio-sidecar-injector</code> Pod 尚未准备就绪,则无法创建 Pod。在这种情况下则会出现以下错误 <code>no such host</code> Kubernetes 1.9)或 <code>no endpoints available</code>&gt;=1.10)。</p><pre><code class=language-plain data-expandlinks=true>Internal error occurred: failed calling admission webhook &#34;istio-sidecar-injector.istio.io&#34;: \
Post https://istio-sidecar-injector.istio-system.svc:443/admitPilot?timeout=30s: \
no endpoints available for service &#34;istio-sidecar-injector&#34;
</code></pre><pre><code class=language-bash data-expandlinks=true>$ kubectl -n istio-system get pod -listio=sidecar-injector
NAME READY STATUS RESTARTS AGE
istio-sidecar-injector-5dbbbdb746-d676g 1/1 Running 0 2d
</code></pre><pre><code class=language-bash data-expandlinks=true>$ kubectl -n istio-system get endpoints istio-sidecar-injector
NAME ENDPOINTS AGE
istio-sidecar-injector 10.48.6.108:10514,10.48.6.108:443 3d
</code></pre><p>如果 Pod 或 Endpoint 尚未就绪,可以通过检查 Pod 日志和状态查找有关 Webhook pod 无法启动并提供服务的原因。</p><pre><code class=language-bash data-expandlinks=true>$ for pod in $(kubectl -n istio-system get pod -listio=sidecar-injector -o jsonpath=&#39;{.items[*].metadata.name}&#39;); do \
kubectl -n istio-system logs ${pod} \
done
$ for pod in $(kubectl -n istio-system get pod -listio=sidecar-injector -o name); do \
kubectl -n istio-system describe ${pod} \
done
</code></pre></article><nav class=pagenav><div class=left><a title="Istio 使用 Kubernetes webhook 进行服务器端配置验证的方式。" href=/v1.1/zh/help/ops/setup/validation/><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#left-arrow"/></svg>配置验证 Webhook</a></div><div class=right><a title="如何检查 Pod 中被许可的功能。" href=/v1.1/zh/help/ops/setup/required-pod-capabilities/>Pod 的必要功能<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=注入的结果和预期不一致><a href=#%e6%b3%a8%e5%85%a5%e7%9a%84%e7%bb%93%e6%9e%9c%e5%92%8c%e9%a2%84%e6%9c%9f%e4%b8%8d%e4%b8%80%e8%87%b4>注入的结果和预期不一致</a><li role=none aria-label="Pod 完全不能创建"><a href=#pod-%e5%ae%8c%e5%85%a8%e4%b8%8d%e8%83%bd%e5%88%9b%e5%bb%ba>Pod 完全不能创建</a><ol><li role=none aria-label="x509 证书相关的错误"><a href=#x509-%e8%af%81%e4%b9%a6%e7%9b%b8%e5%85%b3%e7%9a%84%e9%94%99%e8%af%af>x509 证书相关的错误</a><li role=none aria-label="部署状态中出现 no such hosts 或 no endpoints available 错误"><a href=#%e9%83%a8%e7%bd%b2%e7%8a%b6%e6%80%81%e4%b8%ad%e5%87%ba%e7%8e%b0-no-such-hosts-%e6%88%96-no-endpoints-available-%e9%94%99%e8%af%af>部署状态中出现 <code>no such hosts</code><code>no endpoints available</code> 错误</a></ol></li></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>