The following procedures utilize the Bookinfo application to illustrate various methods for configuring sidecar injection.
Istio
resource has been created, and the Operator has successfully deployed Istio.IstioCNI
resource has been created, and the Operator has deployed the required IstioCNI
pods.bookinfo
namespace, but sidecar injection (as described in step 2) is not yet configured. See "Deploying the Bookinfo application" for more details.This method injects a sidecar proxy into all workloads within a given namespace. It is the ideal approach when most workloads in that namespace need to be part of the mesh.
Check the revision name of the Istio control plane with the following command:
You should see output similar to the following example:
Example output
Because the revision name is default
, you can use the standard injection labels without specifying the exact revision.
Confirm that existing workloads in the target namespace show 1/1
ready containers by running the command below. This verifies the pods are currently running without sidecars.
You should see output similar to the following example:
Example output
Apply the injection label to the bookinfo
namespace by executing the following command:
Example output
To apply the sidecar injection, redeploy the workloads in the bookinfo
namespace. Initiate a rolling update for all deployments with this command:
To verify the rollout, check that the new pods show 2/2
containers in the READY
state, which confirms a successful sidecar injection. Use the following command:
You should see output similar to the following example:
Example output
It is possible to prevent sidecar injection for a specific workload even when injection is enabled for its entire namespace.
This example serves only as a demonstration. For the Bookinfo application to function correctly, all of its workloads must be part of the mesh.
Edit the Deployment
resource for the application. In this example, we will exclude the ratings-v1
service.
In the spec.template.metadata.labels
section of the Deployment
, add the label sidecar.istio.io/inject: "false"
to disable sidecar injection.
The sidecar injection process is not affected if this label is added to the top-level labels
section of the Deployment
.
When the deployment is updated, a rollout is triggered, which creates a new ReplicaSet containing the modified pod(s).
Confirm that the updated pod(s) lack a sidecar container and display 1/1
running containers by executing this command:
You should see output similar to the following example:
Example output
With this method, you can select individual workloads for sidecar injection rather than enabling it for an entire namespace. This is best suited for cases where only a small number of workloads require inclusion in the service mesh. The example also shows how to use a revision label for sidecar injection, where the Istio
resource is named my-mesh
. Using a distinct Istio
resource name is necessary when multiple Istio control planes exist in one cluster or during a control plane upgrade that is based on revisions.
Check the Istio control plane's revision name by running this command:
You should see output similar to the following example:
Example output
Because the revision name is my-mesh
, the revision label istio.io/rev=my-mesh
must be used to activate sidecar injection.
Confirm that existing pods are running without sidecars by checking that they show 1/1
containers in the READY
state. Use this command:
You should see output similar to the following example:
Example output
Edit the Deployment
resource of the application. For this example, modify the ratings-v1
service.
Modify the spec.template.metadata.labels
section of the Deployment
to add the required pod injection or revision label. Here, it is istio.io/rev: my-mesh
:
Placing the label in the top-level labels
section of the Deployment
resource will not affect sidecar injection.
This update to the deployment initiates a rollout, which results in a new ReplicaSet with the changed pod(s).
Confirm that the sidecar was injected successfully by verifying that only the ratings-v1
pod displays 2/2
ready containers. Run the following command:
You should see output similar to the following example:
Example output
Follow the same process for any other workloads you want to add to the mesh.