如何通过Yaml将机密文件设置为kubernetes机密? [英] How to set secret files to kubernetes secrets by yaml?

查看:84
本文介绍了如何通过Yaml将机密文件设置为kubernetes机密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文件存储在Kubernetes Secrets中,但是我还没有找到如何使用yaml文件来实现该功能.

I want to store files in Kubernetes Secrets but I haven't found how to do it using a yaml file.

我已经能够使用cli和kubectl来实现它:

I've been able to make it using the cli with kubectl:

kubectl create secret generic some-secret --from-file=secret1.txt=secrets/secret1.txt

但是当我在yaml中尝试类似的操作时:

But when I try something similar in a yaml:

apiVersion: v1
kind: Secret
metadata:
  name: some-secret
type: Opaque
data:
  secret1.txt: secrets/secret1.txt

我遇到了这个错误:

[pos 73]: json: error decoding base64 binary 'assets/elasticsearch.yml': illegal base64 data at input byte 20

我正在遵循本指南 http://kubernetes.io/docs/user-guide /secrets/.它说明了如何使用yaml创建机密,但没有说明如何使用yaml文件创建机密.

I'm following this guide http://kubernetes.io/docs/user-guide/secrets/. It explains how to create a secret using a yaml but not how to create a secret from a file using yaml.

有可能吗?如果是这样,我该怎么办?

Is it possible? If so, how can I do it?

推荐答案

使用CLI格式时,基本上是在将Yaml生成器发布到服务器端之前使用它的生成器.

When using the CLI format basically you're using a generator of the yaml before posting it to the server-side.

由于Kubernetes是介于两者之间的REST API的客户端-服务器应用程序,并且操作必须是原子的,因此发布的YAML需要包含文件的内容,而实现此目的的最佳方法是将其嵌入为base64格式排队.如果可以通过其他方式嵌入文件(缩进可以用于创建文件的边界),那将是很好的选择,但是到目前为止,我还没有看到这样的示例.

Since Kubernetes is client-server app with REST API in between, and the actions need to be atomic, the posted YAML needs to contain the content of the file, and best way to do that is by embedding it as a base64 format in-line. It would be nice if the file could be otherwise embedded (indentation maybe could be used to create the boundaries of the file), but I haven't seen any example of such until now.

话虽如此,不可能在yaml上放置文件引用,也没有对yaml进行飞行前渲染以包含内容.

That being said, putting a file reference on the yaml is not possible, there is no pre-flight rendering of the yaml to include the content.

这篇关于如何通过Yaml将机密文件设置为kubernetes机密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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