我正在使用 kubernetes 将 Rails 应用程序部署到谷歌容器引擎。
遵循 kubernetes secret 文档:http://kubernetes.io/v1.1/docs/user-guide/secrets.html
我创建了一个网络 Controller 文件:
# web-controller.yml
apiVersion: v1
kind: ReplicationController
metadata:
labels:
name: web
name: web-controller
spec:
replicas: 2
selector:
name: web
template:
metadata:
labels:
name: web
spec:
containers:
- name: web
image: gcr.io/my-project-id/myapp:v1
ports:
- containerPort: 3000
name: http-server
env:
secret:
- secretName: mysecret
并创建了一个 secret 文件:
# secret.yml
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
RAILS_ENV: production
当我运行时:
kubectl create -f web-controller.yml
它显示:
error: could not read an encoded object from web-controller.yml: unable to load "web-controller.yml": json: cannot unmarshal object into Go value of type []v1.EnvVar
error: no objects passed to create
可能web-controller.yml
文件中的yaml格式有误。那怎么写呢?
最佳答案
secret .yml
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
stringData:
RAILS_ENV: production
stringData 是您所追求的简易模式版本,不过是一回事。 你会看到用于在注释中创建 secret 的明文原始 yaml(如果你使用上述方法,这意味着你的注释中将有一个人类可读的 secret ,如果你使用以下方法,你将拥有 base64 'd secret in your annotation),除非你跟进像这样的删除注释命令:
kubectl apply -f secret.yml
kubectl annotate secret mysecret kubectl.kubernetes.io/last-applied-configuration-
(最后的 - 是说要删除它)
kubectl get secret mysecret -n=api -o yaml
(确认)
或者你会做
Bash# 回声制作 | base64
cHJvZHVjdGlvbgo=
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
RAILS_ENV: cHJvZHVjdGlvbgo=
关于ruby-on-rails - 如何通过yaml将 secret 数据设置为kubernetes secret ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33732571/