Add Deployments and Services with the Istio Sidecar

Add Deployments and Services with the Istio Sidecar - 图1Prerequisite:

To enable Istio for a workload, the cluster and namespace must have the Istio app installed.

Enabling Istio in a namespace only enables automatic sidecar injection for new workloads. To enable the Envoy sidecar for existing workloads, you need to enable it manually for each workload.

To inject the Istio sidecar on an existing workload in the namespace,

  1. In the upper left corner, click ☰ > Cluster Management.
  2. On the Clusters page, go to the cluster where you want to see the visualizations and click Explore.
  3. Click Workload.
  4. Go to the workload where you want to inject the Istio sidecar and click ⋮ > Redeploy. When the workload is redeployed, it will have the Envoy sidecar automatically injected.

Wait a few minutes for the workload to upgrade to have the istio sidecar. Click it and go to the Containers section. You should be able to see istio-proxy alongside your original workload. This means the Istio sidecar is enabled for the workload. Istio is doing all the wiring for the sidecar envoy. Now Istio can do all the features automatically if you enable them in the yaml.

Add Deployments and Services

There are a few ways to add new Deployments in your namespace:

  1. Click ☰ > Cluster Management.
  2. Go to the cluster that you created and click Explore.
  3. Click Workload.
  4. Click Create.
  5. Click Deployment.
  6. Fill out the form, or Edit as Yaml.
  7. Click Create.

To add a Service to your namespace:

  1. Click ☰ > Cluster Management.
  2. Go to the cluster that you created and click Explore.
  3. Click Service Discovery > Services.
  4. Click Create.
  5. Select the type of service that you want.
  6. Fill out the form, or Edit as Yaml.
  7. Click Create

You can also create deployments and services using the kubectl shell

  1. Run kubectl create -f <name of service/deployment file>.yaml if your file is stored locally in the cluster
  2. Or run cat<< EOF | kubectl apply -f -, paste the file contents into the terminal, then run EOF to complete the command.

Example Deployments and Services

Next we add the Kubernetes resources for the sample deployments and services for the BookInfo app in Istio’s documentation.

  1. Click ☰ > Cluster Management.
  2. Go to the cluster that you created and click Explore.
  3. In the top navigation bar, open the kubectl shell.
  4. Run cat<< EOF | kubectl apply -f -
  5. Copy the below resources into the the shell.
  6. Run EOF

This will set up the following sample resources from Istio’s example BookInfo app:

Details service and deployment:

  • A details Service
  • A ServiceAccount for bookinfo-details
  • A details-v1 Deployment

Ratings service and deployment:

  • A ratings Service
  • A ServiceAccount for bookinfo-ratings
  • A ratings-v1 Deployment

Reviews service and deployments (three versions):

  • A reviews Service
  • A ServiceAccount for bookinfo-reviews
  • A reviews-v1 Deployment
  • A reviews-v2 Deployment
  • A reviews-v3 Deployment

Productpage service and deployment:

This is the main page of the app, which will be visible from a web browser. The other services will be called from this page.

  • A productpage service
  • A ServiceAccount for bookinfo-productpage
  • A productpage-v1 Deployment

Resource 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. ---

Next: Set up the Istio Gateway