概述

在命名空间中启用 Istio 后仅对新的工作负载启用自动 Sidecar 注入。要为现有工作负载启用 Envoy Sidecar,您需要为每个工作负载手动启用它。

要将 Istio sidecar 注入命名空间中的现有工作负载,请转到工作负载页面,单击省略号 (…),然后单击重新部署。重新部署工作负载时,Envoy sidecar 会自动注入。

等待几分钟,以使工作负载升级到带有 Istio sidecar。单击该工作负载,然后转到容器部分。您应该能够在工作负载中看到 istio-init 和 istio-proxy 容器。这意味着已为工作负载启用了 Istio sidecar。Istio 正在为 Envoy sidecar 进行所有接线。现在,如果您通过 Yaml 中使用了 Istio 的功能,则 Istio 可以自动执行。

先决条件: 要为工作负载启用 Istio,集群和命名空间必须启用 Istio。

添加部署和服务

接下来,我们再添加 Istio 文档中的 BookInfo 示例应用程序相关的 Kubernetes 资源。

  1. 进入要部署工作负载的项目中。
  2. 在工作负载页面,单击导入 YAML
  3. 将以下资源复制到表单中。
  4. 单击导入

这将从 Istio 的 BookInfo 示例应用中设置以下资源:

Details 部署和服务:

  • 一个名为details的 Service
  • 一个名为bookinfo-details的 ServiceAccount
  • 一个名为details-v1的 Deployment

Ratings 部署和服务:

  • 一个名为ratings的 Service
  • 一个名为bookinfo-ratings的 ServiceAccount
  • 一个名为ratings-v1的 Deployment

Reviews 部署和服务(三个版本):

  • 一个名为reviews的 Service
  • 一个名为bookinfo-reviews的 ServiceAccount
  • 一个名为reviews-v1的 Deployment
  • 一个名为reviews-v2的 Deployment
  • 一个名为reviews-v3的 Deployment

Productpage 部署和服务:

这是应用程序的主页,可从网页浏览器中看到。其他服务将从此页面调用。

  • 一个名为productpage的 Service
  • 一个名为bookinfo-productpage的 ServiceAccount
  • 一个名为productpage-v1的 Deployment

资源 YAML

  1. # Copyright 2017 Istio Authors
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. ##################################################################################################
  15. # Details service
  16. ##################################################################################################
  17. apiVersion: v1
  18. kind: Service
  19. metadata:
  20. name: details
  21. labels:
  22. app: details
  23. service: details
  24. spec:
  25. ports:
  26. - port: 9080
  27. name: http
  28. selector:
  29. app: details
  30. ---
  31. apiVersion: v1
  32. kind: ServiceAccount
  33. metadata:
  34. name: bookinfo-details
  35. ---
  36. apiVersion: apps/v1
  37. kind: Deployment
  38. metadata:
  39. name: details-v1
  40. labels:
  41. app: details
  42. version: v1
  43. spec:
  44. replicas: 1
  45. selector:
  46. matchLabels:
  47. app: details
  48. version: v1
  49. template:
  50. metadata:
  51. labels:
  52. app: details
  53. version: v1
  54. spec:
  55. serviceAccountName: bookinfo-details
  56. containers:
  57. - name: details
  58. image: docker.io/istio/examples-bookinfo-details-v1:1.15.0
  59. imagePullPolicy: IfNotPresent
  60. ports:
  61. - containerPort: 9080
  62. ---
  63. ##################################################################################################
  64. # Ratings service
  65. ##################################################################################################
  66. apiVersion: v1
  67. kind: Service
  68. metadata:
  69. name: ratings
  70. labels:
  71. app: ratings
  72. service: ratings
  73. spec:
  74. ports:
  75. - port: 9080
  76. name: http
  77. selector:
  78. app: ratings
  79. ---
  80. apiVersion: v1
  81. kind: ServiceAccount
  82. metadata:
  83. name: bookinfo-ratings
  84. ---
  85. apiVersion: apps/v1
  86. kind: Deployment
  87. metadata:
  88. name: ratings-v1
  89. labels:
  90. app: ratings
  91. version: v1
  92. spec:
  93. replicas: 1
  94. selector:
  95. matchLabels:
  96. app: ratings
  97. version: v1
  98. template:
  99. metadata:
  100. labels:
  101. app: ratings
  102. version: v1
  103. spec:
  104. serviceAccountName: bookinfo-ratings
  105. containers:
  106. - name: ratings
  107. image: docker.io/istio/examples-bookinfo-ratings-v1:1.15.0
  108. imagePullPolicy: IfNotPresent
  109. ports:
  110. - containerPort: 9080
  111. ---
  112. ##################################################################################################
  113. # Reviews service
  114. ##################################################################################################
  115. apiVersion: v1
  116. kind: Service
  117. metadata:
  118. name: reviews
  119. labels:
  120. app: reviews
  121. service: reviews
  122. spec:
  123. ports:
  124. - port: 9080
  125. name: http
  126. selector:
  127. app: reviews
  128. ---
  129. apiVersion: v1
  130. kind: ServiceAccount
  131. metadata:
  132. name: bookinfo-reviews
  133. ---
  134. apiVersion: apps/v1
  135. kind: Deployment
  136. metadata:
  137. name: reviews-v1
  138. labels:
  139. app: reviews
  140. version: v1
  141. spec:
  142. replicas: 1
  143. selector:
  144. matchLabels:
  145. app: reviews
  146. version: v1
  147. template:
  148. metadata:
  149. labels:
  150. app: reviews
  151. version: v1
  152. spec:
  153. serviceAccountName: bookinfo-reviews
  154. containers:
  155. - name: reviews
  156. image: docker.io/istio/examples-bookinfo-reviews-v1:1.15.0
  157. imagePullPolicy: IfNotPresent
  158. ports:
  159. - containerPort: 9080
  160. ---
  161. apiVersion: apps/v1
  162. kind: Deployment
  163. metadata:
  164. name: reviews-v2
  165. labels:
  166. app: reviews
  167. version: v2
  168. spec:
  169. replicas: 1
  170. selector:
  171. matchLabels:
  172. app: reviews
  173. version: v2
  174. template:
  175. metadata:
  176. labels:
  177. app: reviews
  178. version: v2
  179. spec:
  180. serviceAccountName: bookinfo-reviews
  181. containers:
  182. - name: reviews
  183. image: docker.io/istio/examples-bookinfo-reviews-v2:1.15.0
  184. imagePullPolicy: IfNotPresent
  185. ports:
  186. - containerPort: 9080
  187. ---
  188. apiVersion: apps/v1
  189. kind: Deployment
  190. metadata:
  191. name: reviews-v3
  192. labels:
  193. app: reviews
  194. version: v3
  195. spec:
  196. replicas: 1
  197. selector:
  198. matchLabels:
  199. app: reviews
  200. version: v3
  201. template:
  202. metadata:
  203. labels:
  204. app: reviews
  205. version: v3
  206. spec:
  207. serviceAccountName: bookinfo-reviews
  208. containers:
  209. - name: reviews
  210. image: docker.io/istio/examples-bookinfo-reviews-v3:1.15.0
  211. imagePullPolicy: IfNotPresent
  212. ports:
  213. - containerPort: 9080
  214. ---
  215. ##################################################################################################
  216. # Productpage services
  217. ##################################################################################################
  218. apiVersion: v1
  219. kind: Service
  220. metadata:
  221. name: productpage
  222. labels:
  223. app: productpage
  224. service: productpage
  225. spec:
  226. ports:
  227. - port: 9080
  228. name: http
  229. selector:
  230. app: productpage
  231. ---
  232. apiVersion: v1
  233. kind: ServiceAccount
  234. metadata:
  235. name: bookinfo-productpage
  236. ---
  237. apiVersion: apps/v1
  238. kind: Deployment
  239. metadata:
  240. name: productpage-v1
  241. labels:
  242. app: productpage
  243. version: v1
  244. spec:
  245. replicas: 1
  246. selector:
  247. matchLabels:
  248. app: productpage
  249. version: v1
  250. template:
  251. metadata:
  252. labels:
  253. app: productpage
  254. version: v1
  255. spec:
  256. serviceAccountName: bookinfo-productpage
  257. containers:
  258. - name: productpage
  259. image: docker.io/istio/examples-bookinfo-productpage-v1:1.15.0
  260. imagePullPolicy: IfNotPresent
  261. ports:
  262. - containerPort: 9080
  263. ---

后续操作

设置 Istio 网关