Recall that to join the mesh, each pod will need an Envoy proxy sidecar container. To stream configuration, those proxies will need some minimal permissions in IAM. We can use IRSA here again, granting only the required permissions to our application namespace.
Note you can scope the policy actions to only specific resources within your namespace, if you wish. For the purposes of our demo, we’ll use the default policy and apply to all resources in the namespace.
# Download the IAM policy document for the Envoy proxies
curl -o envoy-iam-policy.json https://raw.githubusercontent.com/aws/aws-app-mesh-controller-for-k8s/master/config/iam/envoy-iam-policy.json
# Create an IAM policy for the proxies from the policy document
aws iam create-policy \
--policy-name AWSAppMeshEnvoySidecarIAMPolicy \
--policy-document file://envoy-iam-policy.json
# Create an IAM role and service account for the application namespace
eksctl create iamserviceaccount \
--cluster eksworkshop-eksctl \
--namespace prod \
--name prod-proxies \
--attach-policy-arn arn:aws:iam::$ACCOUNT_ID:policy/AWSAppMeshEnvoySidecarIAMPolicy \
--override-existing-serviceaccounts \
--approve
Now that’s sorted, you can start the proxies. We have enabled automatic sidecar injection on the prod
namespace, but this was done after initial pod creation. Currently, your pods each have one container running.
kubectl get pods -n prod
To inject sidecar proxies for these pods, simply restart the deployments. The controller will handle the rest, and will inject sidecar proxies in any new pods as well.
kubectl -n prod rollout restart deployment dj jazz-v1 metal-v1
You should now see 2 containers in each pod. It might take a few seconds for the new configuration to settle.
kubectl -n prod get pods
Now you can see that 2 containers are running in each pod, verify that they are the application service and the Envoy proxy. Examine the pod and confirm these are the containers running within it.
export DJ_POD_NAME=$(kubectl get pods -n prod -l app=dj -o jsonpath='{.items[].metadata.name}')
kubectl -n prod get pods $DJ_POD_NAME -o jsonpath='{.spec.containers[*].name}'
Here you see both the application service as well as the sidecar proxy container. Any new pods created in this namespace will have the proxy injected automatically.