Sidecar Proxy
Istio requires to run a sidecar proxy next to every instance of your containers that needs to participate in the service mesh. There are 2 ways of adding the sidecar proxy:
  1. 1.
    Automatic sidecar injection
  2. 2.
    Manual sidecar injection

Automatic Sidecar Injection

You can inject the Istio sidecar automatically for every pod that's deployed into a specific namespace. You can enable automatic injection by annotating the namespace you want to use the service mesh.
1
kubectl label namespace default istio-injection=enabled
Copied!
Deploy a workload, such as the Helloworld application from the Kubernetes Deployment section.
1
kubectl apply -f k8s/deployment.yaml
Copied!
Verify that the Helloworld pod has 2 containers rather than only 1:
1
kubectl get pods
Copied!
Each container within a pod is named. Now that the pod has multiple containers, you can specify a container within the pod using -c containername parameter:
1
POD_NAME=$(kubectl get pods -lapp=helloworld -o jsonpath='{.items[0].metadata.name}')
2
3
kubectl logs ${POD_NAME} -c helloworld
4
kubectl logs ${POD_NAME} -c istio-proxy
Copied!
If, for some reason, a workload do not want to participate in the mesh, then you can explicitly turn off automatic sidecar injection using annotation:
1
apiVersion: apps/v1
2
kind: Deployment
3
metadata:
4
name: helloworld
5
...
6
spec:
7
template:
8
metadata:
9
labels:
10
...
11
annotations:
12
# Explicitly turn off automatic sidecar injection
13
sidecar.istio.io/inject: "false"
14
spec:
15
...
16
Copied!

Manual Sidecar Injection

You can use istioctl to filter your existing Kubernetes deployment file and it'll produce the enhanced deployment manifest.
1
istioctl kube-inject -f k8s/deployment.yaml
Copied!
In addition to your original manifest, the enhanced manifest now has an additional istio-proxycontainer.
You can save the enhanced manifest into a file for future deployments. Or, you can filter and apply in one command:
1
istioctl kube-inject -f k8s/deployment.yaml| kubectl apply -f
Copied!
In most cases, Automatic Sidecar Injection is what you need.