|
7 | 7 | [id="ossm-automatic-sidecar-injection_{context}"] |
8 | 8 | = Enabling automatic sidecar injection |
9 | 9 |
|
10 | | -When deploying an application, you must opt-in to injection by setting the `sidecar.istio.io/inject` annotation to `"true"`. Opting in ensures that the sidecar injection does not interfere with other {product-title} features such as builder pods used by numerous frameworks within the {product-title} ecosystem. |
| 10 | +When deploying an application, you must opt-in to injection by configuring the annotation `sidecar.istio.io/inject` in `spec.template.metadata.annotations` to `true` in the `deployment` object. Opting in ensures that the sidecar injection does not interfere with other {product-title} features such as builder pods used by numerous frameworks within the {product-title} ecosystem. |
11 | 11 |
|
12 | 12 | .Prerequisites |
13 | 13 |
|
14 | | -* Identify the deployments for which you want to enable automatic sidecar injection. |
| 14 | +* Identify the namespaces that are part of your service mesh and the deployments that need automatic sidecar injection. |
15 | 15 |
|
16 | 16 | .Procedure |
17 | 17 |
|
18 | | -. Open the application's deployment configuration YAML file in an editor. To find a deployment use the `oc get` command. For example, for an app called `sleep` in the `sleep` namespace, use the following command to see the resource in YAML format. |
| 18 | +. To find your deployments use the `oc get` command. |
19 | 19 | + |
20 | 20 | [source,terminal] |
21 | 21 | ---- |
22 | | -$ oc get deployment sleep -o yaml |
| 22 | +$ oc get deployment -n <namespace> |
23 | 23 | ---- |
| 24 | ++ |
| 25 | +For example, to view the deployment file for the 'ratings-v1' microservice in the `bookinfo` namespace, use the following command to see the resource in YAML format. |
| 26 | ++ |
| 27 | +[source,terminal] |
| 28 | +---- |
| 29 | +oc get deployment -n bookinfo ratings-v1 -o yaml |
| 30 | +---- |
| 31 | ++ |
| 32 | +. Open the application's deployment configuration YAML file in an editor. |
24 | 33 |
|
25 | | -. Add `sidecar.istio.io/inject` to the configuration YAML with a value of `"true"` in the `spec.template.metadata.annotations.sidecar.istio/inject` field. See the following example for an app called `sleep`. |
| 34 | +. Add `spec.template.metadata.annotations.sidecar.istio/inject` to your Deployment YAML and set `sidecar.istio.io/inject` to `true` as shown in the following example. |
26 | 35 | + |
27 | | -.Sleep test application example sleep.yaml |
| 36 | +.Example snippet from bookinfo deployment-ratings-v1.yaml |
28 | 37 | [source,yaml] |
29 | 38 | ---- |
30 | 39 | apiVersion: apps/v1 |
31 | 40 | kind: Deployment |
32 | 41 | metadata: |
| 42 | + name: ratings-v1 |
| 43 | + namespace: bookinfo |
33 | 44 | labels: |
34 | | - app: sleep |
35 | | - name: sleep |
| 45 | + app: ratings |
| 46 | + version: v1 |
36 | 47 | spec: |
37 | | - replicas: 1 |
38 | | - selector: |
39 | | - matchLabels: |
40 | | - app: sleep |
41 | 48 | template: |
42 | 49 | metadata: |
43 | 50 | annotations: |
44 | | - sidecar.istio.io/inject: "true" |
45 | | - labels: |
46 | | - app: sleep |
47 | | - spec: |
48 | | - containers: |
49 | | - - name: sleep |
50 | | - image: curlimages/curl |
51 | | - command: ["/bin/sleep","3650d"] |
52 | | - imagePullPolicy: IfNotPresent |
| 51 | + sidecar.istio.io/inject: 'true' |
53 | 52 | ---- |
| 53 | ++ |
| 54 | +. Save the Deployment configuration file. |
54 | 55 |
|
55 | | -. Save the configuration file. |
56 | | - |
57 | | -. Add the file back to the project that contains your app. In this example, `sleep` is the name of the project that contains the `sleep` app and `sleep.yaml` is the file you edited. |
| 56 | +. Add the file back to the project that contains your app. |
58 | 57 | + |
59 | 58 | [source,terminal] |
60 | 59 | ---- |
61 | | -$ oc apply -n sleep -f sleep.yaml |
| 60 | +$ oc apply -n <namespace> -f deployment.yaml |
62 | 61 | ---- |
63 | | - |
| 62 | ++ |
| 63 | +In this example, `bookinfo` is the name of the project that contains the `ratings-v1` app and `deployment-ratings-v1.yaml` is the file you edited. |
| 64 | ++ |
| 65 | +[source,terminal] |
| 66 | +---- |
| 67 | +$ oc apply -n bookinfo -f deployment-ratings-v1.yaml |
| 68 | +---- |
| 69 | ++ |
64 | 70 | . To verify that the resource uploaded successfully, run the following command. |
65 | 71 | + |
66 | 72 | [source,terminal] |
67 | 73 | ---- |
68 | | -$ oc get deployment sleep -o yaml |
| 74 | +$ oc get deployment -n <namespace> <deploymentName> -o yaml |
| 75 | +---- |
| 76 | ++ |
| 77 | +For example, |
| 78 | ++ |
| 79 | +[source,terminal] |
| 80 | +---- |
| 81 | +$ oc get deployment -n bookinfo ratings-v1 -o yaml |
69 | 82 | ---- |
0 commit comments