kubernetes秘密在环境变量中具有尾随空格 [英] kubernetes secrets have trailing whitespace in environment variables

查看:75
本文介绍了kubernetes秘密在环境变量中具有尾随空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行在GKE上的Kubernetes 1.9中创建了一个部署,该部署利用了放入环境变量中的机密.我使用一个带有base64编码秘密的yaml文件将这些秘密上传到GKE.

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.

我在容器中看到的是环境变量在其中,但该值包括尾随空格.如果设置环境变量FOO的值为"bar",这就是它的样子,我在秘密yaml中输入的base64将是"YmFyCg ==:

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==":

$ echo $FOO
bar 
$ echo \"$FOO\"
"bar "
$ echo $FOO | base64
YmFyCg==
$ echo "$FOO" | base64
YmFyIAo=

这对于从环境变量读取的应用程序没有任何困难,这些应用程序希望在没有附加空格的情况下对值进行编码,例如,<<>中的 POSTGRES_PASSWORD POSTGRES_USER code> postgres:9.6 图片.环境中的其他变量(包括从我的部署yaml中设置的变量,没有任何秘密)不包括结尾的空格;只有秘密才有问题.

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., POSTGRES_PASSWORD and POSTGRES_USER in the postgres:9.6 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.

推荐答案

您的回显正在添加换行符.添加-n可以省略尾随的换行符

Your echo is adding the newline. Add -n to omit a trailing newline

这篇关于kubernetes秘密在环境变量中具有尾随空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆