Right now, if we describe any of the pods running in the prod namespace, we’ll notice that they are running with just one container, the same one we initially deployed it with:
kubectl get pods -nprod
yields:
and to take a closer look:
kubectl describe pods/dj-5b445fbdf4-qf8sv -nprod
yields:
The injector controller we installed earlier watches for new pods to be created, and ensures any new pods that are created in the prod namespace are injected with the App Mesh sidecar. Since our dj pods were already running before the injector was created, we’ll force them to be recreated, this time with the sidecars auto-injected into them.
In production, there are more graceful ways to do this, but for the purpose of this tutorial, an easy way to have the deployment recreate the pods in an innocuous fashion is to patch into the deployment a simple date annotation.
To do that with our current deployment, first we get all the prod namespace pod names:
kubectl get pods -nprod
The output will be the pod names:
Note that under the READY column, we see 1⁄1, which indicates one container is running for each pod.
Next, run the following commands to add a date label to each dj, jazz-v1, and metal-1 deployment, forcing the pods to be recreated:
kubectl patch deployment dj -nprod -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
kubectl patch deployment metal-v1 -nprod -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
kubectl patch deployment jazz-v1 -nprod -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
Once again, get the pods:
kubectl get pods -nprod
Now note how we see 2⁄2 under READY, which indicates two container for each pod are running:
If you don’t see the above exact output, and instead see “Terminating” or “Initializing” pods, wait about 10 seconds — (your redeployment is underway), and re-run the command. Run kubectl get pods -nprod --watch
to see the entire process of initializaing and terminating pods.
kubectl get pods -nprod --watch
If we now describe the new dj pod to get more detail:
kubectl describe pods/$(kubectl get pods -nprod | grep 'dj-' | awk '{print $1}') -nprod`
We’ll see that both the original container, and the auto-injected sidecar will both be running for any new pods created in the prod namespace.