1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-07 00:48:01 +01:00
Files
openshift-docs/modules/ossm-automatic-sidecar-injection.adoc
2023-10-30 10:13:25 -04:00

83 lines
2.4 KiB
Plaintext

// Module included in the following assemblies:
//
// * service_mesh/v1x/prepare-to-deploy-applications-ossm.adoc
// * service_mesh/v2x/prepare-to-deploy-applications-ossm.adoc
:_mod-docs-content-type: PROCEDURE
[id="ossm-automatic-sidecar-injection_{context}"]
= Enabling automatic sidecar injection
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.
.Prerequisites
* Identify the namespaces that are part of your service mesh and the deployments that need automatic sidecar injection.
.Procedure
. To find your deployments use the `oc get` command.
+
[source,terminal]
----
$ oc get deployment -n <namespace>
----
+
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.
+
[source,terminal]
----
oc get deployment -n bookinfo ratings-v1 -o yaml
----
+
. Open the application's deployment configuration YAML file in an editor.
. 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.
+
.Example snippet from bookinfo deployment-ratings-v1.yaml
[source,yaml]
----
apiVersion: apps/v1
kind: Deployment
metadata:
name: ratings-v1
namespace: bookinfo
labels:
app: ratings
version: v1
spec:
template:
metadata:
annotations:
sidecar.istio.io/inject: 'true'
----
+
. Save the Deployment configuration file.
. Add the file back to the project that contains your app.
+
[source,terminal]
----
$ oc apply -n <namespace> -f deployment.yaml
----
+
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.
+
[source,terminal]
----
$ oc apply -n bookinfo -f deployment-ratings-v1.yaml
----
+
. To verify that the resource uploaded successfully, run the following command.
+
[source,terminal]
----
$ oc get deployment -n <namespace> <deploymentName> -o yaml
----
+
For example,
+
[source,terminal]
----
$ oc get deployment -n bookinfo ratings-v1 -o yaml
----