<p>I created a deployment in Kubernetes 1.9 running on GKE that makes use of secrets put into environment variables. I uploaded the secrets into GKE using a yaml file with the secrets base64 encoded. </p>

<p>What I'm seeing in my container is that the environment variable is there, but the value includes trailing whitespace. Here's what it would look like if I set up an environment variable FOO with the value "bar", where the base64 I put in the secrets yaml would be "YmFyCg==":</p>

<pre><code>$ echo $FOO
bar 
$ echo \"$FOO\"
"bar "
$ echo $FOO | base64
YmFyCg==
$ echo "$FOO" | base64
YmFyIAo=
</code></pre>

<p>This is causing no end of difficulties for applications that read from environment variables expecting the value to be encoded without the additional whitespace, e.g., <code>POSTGRES_PASSWORD</code> and <code>POSTGRES_USER</code> in the <code>postgres:9.6</code> image. Other variables in the environment (including those set from my deployment yaml without secrets) do not include the trailing whitespace; it's only secrets that have the problem. </p>

<p>Your echo is adding the newline. Add -n to omit a trailing newline </p>
