Secret
创建 Secret#
sudo kubectl create secret -h
Create a secret with specified type.
A docker-registry type secret is for accessing a container registry. – docker 仓库加密(常用)
A generic type secret indicate an Opaque secret type. – 普通文本加密
A tls type secret holds TLS certificate and its associated key.
Available Commands:
docker-registry Create a secret for use with a Docker registry
generic Create a secret from a local file, directory, or literal
value
tls Create a TLS secretUsage:
kubectl create secret (docker-registry | generic | tls) [options]Use “kubectl create secret
–help” for more information about a given
command.
普通文本加密#
1 | hhhyc@hhhyc:~$ sudo kubectl create secret generic test-secret --from- literal=username=admin --from-literal=password=ds@!3- |
- 密码被和谐了
ds@!3-
变成了ds@cd
- 展示密码的是否数据只是显示为字节数,因此
describe
没啥意义
加密形式
1
2
3
4
5
6
7
8hhhyc@hhhyc:~$ echo 'admin' | base64
YWRtaW4K
hhhyc@hhhyc:~$ echo 'YWRtaW4K' | base64 --decode
admin
hhhyc@hhhyc:~$ echo 'ds@cd' | base64
ZHNAY2QK
hhhyc@hhhyc:~$ echo 'ZHNAY2QK' | base64 --decode
ds@cd只是用 Base64编码方式去创建,安全性不高
Docker Registy 加密#
1 | sudo kubectl create secret docker-registry -h |
创建 Secret :
1 | sudo kubectl create secret docker-registry docker-secret --docker- |
拿到我加密后的数据 并 解密
- 拿到我加密后的数据
1 | kubectl edit secret docker-secret |
加密后的数据为: eyJhdXRocyI6eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsidXNl
- 解密一下
1 | hhhyc@hhhyc:~$ echo 'eyJhdXRocyI6eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsidXNl' | base64 --decode |
yaml文件加密#
好像还可以用yaml文件加密,GPT字节说的:
- 创建 YAML 文件:
- 将您的数据定义为一个 YAML 文件。您可以使用
data
字段以 Base64 编码格式存储数据,或者使用stringData
字段直接存储字符串数据。
- 将您的数据定义为一个 YAML 文件。您可以使用
- Base64 编码(如果使用
data
字段):- 将您的敏感信息进行 Base64 编码。可以使用
base64
命令行工具进行编码。
- 将您的敏感信息进行 Base64 编码。可以使用
- 编写 Secret YAML:
- 使用以下格式编写 YAML 文件:
1 | apiVersion: v1 |
- 假设您有一个用户名
myuser
和密码mypassword
,您可以这样创建 Secret:
1 | apiVersion: v1 |
创建 Secret
- 使用
kubectl
命令行工具应用 YAML 文件来创建 Secret:
1 | kubectl apply -f my-secret.yaml |
验证 Secret 是否创建成功
- 使用以下命令检查 Secret 是否已正确创建:
1 | kubectl get secret my-secret |
这个我就不验证了,反正都是gpt的东西,不大会错