Skip to content

Commit d337b38

Browse files
longmuirFilipB
andauthored
Use bookinfo for injection examples (openshift-service-mesh#169)
* Use bookinfo for injection examples * Update docs/ossm/injection/README.md Co-authored-by: Filip Brychta <[email protected]> * Feedback from PR, and add exclusion example * Update docs/ossm/injection/README.md Co-authored-by: Filip Brychta <[email protected]> * Further updates from review, remove extra restarts not needed --------- Co-authored-by: Filip Brychta <[email protected]>
1 parent fe27337 commit d337b38

File tree

1 file changed

+159
-60
lines changed

1 file changed

+159
-60
lines changed

docs/ossm/injection/README.md

Lines changed: 159 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -49,81 +49,180 @@ The injector is configured with the following logic:
4949
1. If either label (`istio-injection` or `sidecar.istio.io/inject`) is disabled, the pod is not injected.
5050
2. If either label (`istio-injection` or `sidecar.istio.io/inject` or `istio.io/rev`) is enabled, the pod is injected.
5151

52-
### Example: Enabling sidecar injection
52+
### Sidecar injection examples
53+
54+
The following examples use the [Bookinfo application](https://docs.openshift.com/service-mesh/3.0.0tp1/install/ossm-installing-openshift-service-mesh.html#deploying-book-info_ossm-about-bookinfo-application) to demonstrate different approaches for configuring side car injection.
55+
56+
> Note: If you have followed the procedure to deploy the Bookinfo application, step 5 added a sidecar injection label to the `bookinfo` namespace, and these steps are not necessary to repeat.
57+
5358
Prerequisites:
54-
- The OpenShift Service Mesh operator has been installed
55-
- An Istio CNI resource has been created
59+
- You have installed the Red Hat OpenShift Service Mesh Operator, created an `Istio` resource, and the Operator has deployed Istio.
60+
- You have created the `IstioCNI` resource, and the Operator has deployed the necessary IstioCNI pods.
61+
- You have created the namespaces that are to be part of the mesh, and they are [discoverable by the Istio control plane](https://docs.openshift.com/service-mesh/3.0.0tp1/install/ossm-installing-openshift-service-mesh.html#ossm-scoping-service-mesh-with-discoveryselectors_ossm-creating-istiocni-resource).
62+
- (Optional) You have deployed the workloads to be included in the mesh. In the following examples, the [Bookinfo has been deployed](https://docs.redhat.com/en/documentation/red_hat_openshift_service_mesh/3.0.0tp1/html-single/installing/index#ossm-about-bookinfo-application_ossm-discoveryselectors-scope-service-mesh) to the `bookinfo` namespace, but sidecar injection (step 5) has not been configured.
63+
64+
#### Example 1: Enabling sidecar injection with namespace labels
65+
66+
In this example, all workloads within a namespace will be injected with a sidecar proxy. This is the best approach if most of the workloads within a namespace are to be included in the mesh.
67+
68+
Procedure:
69+
70+
1. Verify the revision name of the Istio control plane:
5671

57-
1. Create the `istio-system` namespace:
5872
```bash
59-
oc create ns istio-system
73+
$ oc get istiorevision
74+
NAME TYPE READY STATUS IN USE VERSION AGE
75+
default Local True Healthy False v1.23.0 4m57s
6076
```
61-
1. Prepare `default` `istio.yaml`:
62-
```yaml
63-
kind: Istio
64-
apiVersion: sailoperator.io/v1alpha1
65-
metadata:
66-
name: default
67-
spec:
68-
namespace: istio-system
69-
updateStrategy:
70-
type: InPlace
71-
version: v1.23.0
72-
```
73-
1. Create the `default` Istio CR in `istio-system` namespace:
77+
Since the revision name is `default`, we can used the default injection labels and do not need to reference the specific revision name.
78+
79+
1. For workloads already running in the desired namespace, verify that they show "1/1" containers as "READY", indicating that the pods are currently running without sidecars:
80+
7481
```bash
75-
oc apply -f istio.yaml
82+
$ oc get pods -n bookinfo
83+
NAME READY STATUS RESTARTS AGE
84+
details-v1-65cfcf56f9-gm6v7 1/1 Running 0 4m55s
85+
productpage-v1-d5789fdfb-8x6bk 1/1 Running 0 4m53s
86+
ratings-v1-7c9bd4b87f-6v7hg 1/1 Running 0 4m55s
87+
reviews-v1-6584ddcf65-6wqtw 1/1 Running 0 4m54s
88+
reviews-v2-6f85cb9b7c-w9l8s 1/1 Running 0 4m54s
89+
reviews-v3-6f5b775685-mg5n6 1/1 Running 0 4m54s
7690
```
77-
1. Wait for `Istio` to become ready.
91+
92+
1. Apply the injection label to the bookinfo namespace by entering the following command at the CLI:
7893
```bash
79-
oc wait --for=condition=Ready istios/default -n istio-system
94+
$ oc label namespace bookinfo istio-injection=enabled
95+
namespace/bookinfo labeled
8096
```
81-
1. Deploy the `sleep` app:
97+
98+
1. Workloads that were already running when the injection label was added will need to be redeployed for sidecar injection to occur. The following command can be used to perform a rolling update of all workloads in the `bookinfo` namespace:
8299
```bash
83-
oc apply -f https://raw.githubusercontent.com/istio/istio/release-1.23/samples/sleep/sleep.yaml
100+
oc -n bookinfo rollout restart deployment
84101
```
85-
1. Verify both the deployment and pod have a single container:
102+
103+
1. Verify that once rolled out, the new pods show "2/2" containers "READY", indicating that the sidecars have been successfully injected:
104+
86105
```bash
87-
oc get deployment -o wide
88-
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
89-
sleep 1/1 1 1 16s sleep curlimages/curl app=sleep
90-
oc get pod -l app=sleep
91-
NAME READY STATUS RESTARTS AGE
92-
sleep-5577c64d7c-ntn9d 1/1 Running 0 16s
106+
$ oc get pods -n bookinfo
107+
NAME READY STATUS RESTARTS AGE
108+
details-v1-7745f84ff-bpf8f 2/2 Running 0 55s
109+
productpage-v1-54f48db985-gd5q9 2/2 Running 0 55s
110+
ratings-v1-5d645c985f-xsw7p 2/2 Running 0 55s
111+
reviews-v1-bd5f54b8c-zns4v 2/2 Running 0 55s
112+
reviews-v2-5d7b9dbf97-wbpjr 2/2 Running 0 55s
113+
reviews-v3-5fccc48c8c-bjktn 2/2 Running 0 55s
93114
```
94-
1. Label the `default` namespace with `istio-injection=enabled`:
95-
```bash
96-
oc label namespace default istio-injection=enabled
115+
#### Example 2: Exclude a workload from the mesh
116+
117+
There may be times when you want to exclude individual workloads from a namespace where all workloads are otherwise injected with sidecars. This continues the previous example to exclude the `details` service from the mesh.
118+
119+
> Note: This example is for demonstration purposes only, and the bookinfo application requires all workloads to be part of the mesh for it to work.
120+
121+
Procedure:
122+
123+
1. Open the application’s `Deployment` resource in an editor. In this case, we will exclude the `ratings-v1` service.
124+
125+
1. Modify the `spec.template.metadata.labels` section of your `Deployment` resource to include the appropriate pod injection or revision label to set injection to "false". In this case, `sidecar.istio.io/inject: false`:
126+
127+
```yaml
128+
kind: Deployment
129+
apiVersion: apps/v1
130+
metadata:
131+
name: ratings-v1
132+
namespace: bookinfo
133+
labels:
134+
app: ratings
135+
version: v1
136+
spec:
137+
template:
138+
metadata:
139+
labels:
140+
sidecar.istio.io/inject: 'false'
97141
```
98-
1. Injection occurs at pod creation time. Remove the running pod to be injected with a proxy sidecar.
142+
> Note: Adding the label to the `Deployment`'s top level `labels` section will not impact sidecar injection.
143+
144+
Updating the deployment will result in a rollout, where a new `ReplicaSet` is created with updated pod(s).
145+
146+
1. Verify that the updated pod(s) do not contain a sidecar container, and shows "1/1" containers "Running":
99147
```bash
100-
oc delete pod -l app=sleep
148+
oc get pods -n bookinfo
149+
NAME READY STATUS RESTARTS AGE
150+
details-v1-6bc7b69776-7f6wz 1/1 Running 0 7s
151+
productpage-v1-54f48db985-gd5q9 2/2 Running 0 29m
152+
ratings-v1-5d645c985f-xsw7p 2/2 Running 0 29m
153+
reviews-v1-bd5f54b8c-zns4v 2/2 Running 0 29m
154+
reviews-v2-5d7b9dbf97-wbpjr 2/2 Running 0 29m
155+
reviews-v3-5fccc48c8c-bjktn 2/2 Running 0 29m
101156
```
102-
1. Verify a new pod is created with the injected sidecar. The original pod has `1/1 READY` containers, and the pod with injected sidecar has `2/2 READY` containers.
103-
```bash
104-
oc get pod -l app=sleep
105-
NAME READY STATUS RESTARTS AGE
106-
sleep-5577c64d7c-w9vpk 2/2 Running 0 12s
157+
158+
### Example 3: Enabling sidecar injection with pod labels
159+
160+
Rather than including all workloads within a namespace, you can include individual workloads for sidecar injection. This approach is ideal when only a few workloads within a namespace will be part of a service mesh.
161+
162+
This example also demonstrates the use of a revision label for sidecar injection. In this case, the `Istio` resource has been created with the name "my-mesh". A unique resource `Istio` name is needed when there are multiple Istio control planes present in the same cluster, or a revision based control plane upgrade is in progress.
163+
164+
Procedure:
165+
166+
1. Verify the revision name of the Istio control plane:
167+
168+
```console
169+
$ oc get istiorevision
170+
NAME TYPE READY STATUS IN USE VERSION AGE
171+
my-mesh Local True Healthy False v1.23.0 47s
107172
```
108-
1. View the detailed state of the injected pod. You should see the injected `istio-proxy` container.
173+
Since the revision name is `my-mesh`, we must use the a revision label to enable sidecar injection. In this case, `istio.io/rev=my-mesh`.
174+
175+
1. For workloads already running, verify that they show "1/1" containers as "READY", indicating that the pods are currently running without sidecars:
176+
109177
```bash
110-
oc describe pod -l app=sleep
111-
...
112-
Events:
113-
Type Reason Age From Message
114-
---- ------ ---- ---- -------
115-
Normal Scheduled 50s default-scheduler Successfully assigned default/sleep-5577c64d7c-w9vpk to user-rhos-d-1-v8rnx-worker-0-rwjrr
116-
Normal AddedInterface 50s multus Add eth0 [10.128.2.179/23] from ovn-kubernetes
117-
Normal Pulled 50s kubelet Container image "registry.redhat.io/openshift-service-mesh-tech-preview/istio-proxyv2-rhel9@sha256:c0170ef9a34869828a5f2fea285a7cda543d99e268f7771e6433c54d6b2cbaf4" already present on machine
118-
Normal Created 50s kubelet Created container istio-validation
119-
Normal Started 50s kubelet Started container istio-validation
120-
Normal Pulled 50s kubelet Container image "curlimages/curl" already present on machine
121-
Normal Created 50s kubelet Created container sleep
122-
Normal Started 50s kubelet Started container sleep
123-
Normal Pulled 50s kubelet Container image "registry.redhat.io/openshift-service-mesh-tech-preview/istio-proxyv2-rhel9@sha256:c0170ef9a34869828a5f2fea285a7cda543d99e268f7771e6433c54d6b2cbaf4" already present on machine
124-
Normal Created 50s kubelet Created container istio-proxy
125-
Normal Started 50s kubelet Started container istio-proxy
126-
...
178+
$ oc get pods -n bookinfo
179+
NAME READY STATUS RESTARTS AGE
180+
details-v1-65cfcf56f9-gm6v7 1/1 Running 0 4m55s
181+
productpage-v1-d5789fdfb-8x6bk 1/1 Running 0 4m53s
182+
ratings-v1-7c9bd4b87f-6v7hg 1/1 Running 0 4m55s
183+
reviews-v1-6584ddcf65-6wqtw 1/1 Running 0 4m54s
184+
reviews-v2-6f85cb9b7c-w9l8s 1/1 Running 0 4m54s
185+
reviews-v3-6f5b775685-mg5n6 1/1 Running 0 4m54s
186+
```
187+
188+
1. Open the application’s `Deployment` resource in an editor. In this case, we will update the `ratings-v1` service.
189+
190+
1. Update the `spec.template.metadata.labels` section of your `Deployment` to include the appropriate pod injection or revision label. In this case, `istio.io/rev: my-mesh`:
191+
192+
```yaml
193+
kind: Deployment
194+
apiVersion: apps/v1
195+
metadata:
196+
name: ratings-v1
197+
namespace: bookinfo
198+
labels:
199+
app: ratings
200+
version: v1
201+
spec:
202+
template:
203+
metadata:
204+
labels:
205+
istio.io/rev: my-mesh
127206
```
128-
> [!CAUTION]
129-
> Injection using the `istioctl kube-inject` which is not supported by Red Hat OpenShift Service Mesh.
207+
208+
> Note: Adding the label to the `Deployment`'s top level `labels` section will not impact sidecar injection.
209+
210+
Updating the deployment will result in a rollout, where a new `ReplicaSet` is created with updated pod(s).
211+
212+
1. Verify that only the `ratings-v1` pod now shows "2/2" containers "READY", indicating that the sidecar has been successfully injected:
213+
```
214+
oc get pods -n bookinfo
215+
NAME READY STATUS RESTARTS AGE
216+
details-v1-559cd49f6c-b89hw 1/1 Running 0 42m
217+
productpage-v1-5f48cdcb85-8ppz5 1/1 Running 0 42m
218+
ratings-v1-848bf79888-krdch 2/2 Running 0 9s
219+
reviews-v1-6b7444ffbd-7m5wp 1/1 Running 0 42m
220+
reviews-v2-67876d7b7-9nmw5 1/1 Running 0 42m
221+
reviews-v3-84b55b667c-x5t8s 1/1 Running 0 42m
222+
```
223+
224+
1. Repeat for other workloads that you wish to include in the mesh.
225+
226+
227+
Additional Resources
228+
- [Istio Sidecar injection problems](https://istio.io/latest/docs/ops/common-problems/injection/)

0 commit comments

Comments
 (0)