Skip to content

Secret

一句话解释

Secret 是 Kubernetes resource 那个存储 sensitive 数据例如密码, 令牌, and 键, encoded in base64.

用大白话说

A Secret is like a ConfigMap but for sensitive data — passwords, API keys, TLS certificates, database credentials. The values are stored base64-encoded, which is not encryption but prevents casual viewing.

Secrets can be mounted as files or injected as environment variables into your Pods. For real security, you should combine Secrets with encryption at rest (enabled in the cluster) and use tools like HashiCorp Vault or cloud KMS for production-grade secret management.

There are several types of Secrets: Opaque (generic key-value), kubernetes.io/tls (TLS certificate + key), and kubernetes.io/dockerconfigjson (registry credentials).

示例

yaml
apiVersion: v1
kind: Secret
metadata:
  name: db-credentials
type: Opaque
data:
  username: YWRtaW4=   # base64 of 'admin'
  password: c2VjcmV0   # base64 of 'secret'

这个 Secret 存储数据库用户名 and 密码, base64-encoded. Pod 能 use 它们 as 环境变量.

工作原理

  1. You create a Secret with base64-encoded sensitive data.
  2. You reference it in your Pod spec as env vars or a mounted volume.
  3. The container decodes and uses the values at runtime.
  4. Enable encryption at rest in the cluster for real protection.

常见混淆

  • 容易混淆的对象: ConfigMap

    关键区别: Secrets 存储 sensitive 数据 base64-encoded and 有 access controls; ConfigMaps 存储非-sensitive 数据 in plain 文本.

相关术语

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表