To display some environment variables in a pod on Kubernetes, I tried it in two ways.
(1) Connecting inside a pod
I connected to shell in a pod and I executed 'echo' command like below..
kubectl exec -it <pod-name> /bin/bash
then...
echo $KUBERNETES_SERVICE_HOST
I saw correct result as I expected.
(2) Send a command to a pod
kubectl exec <pod-name> -- echo $KUBERNETES_SERVICE_HOST
In this case, there is no output.
you can see the screenshot what I did.
What is the problem here? What is difference between two situations?
Thanks you :)
In the second case, '
#x27; DOllar in the command references to your local host envrionment variables. And there is no such variable KUBERNETES_SERVICE_HOST on local host, the command that goes looks like belowkubectl exec <pod-name> -- echo <blank>
use below instead
kubectl exec c-hub-admin-app-systest-6dc46bb776-tvb99 -- printenv | grep KUBERNETES_SERVICE_HOST