zoukankan      html  css  js  c++  java
  • 用 k8s 管理机密信息【转】

    应用启动过程中可能需要一些敏感信息,比如访问数据库的用户名密码或者秘钥。将这些信息直接保存在容器镜像中显然不妥,Kubernetes 提供的解决方案是 Secret。

    Secret 会以密文的方式存储数据,避免了直接在配置文件中保存敏感信息。Secret 会以 Volume 的形式被 mount 到 Pod,容器可通过文件的方式使用 Secret 中的敏感数据;此外,容器也可以环境变量的方式使用这些数据。

    Secret 可通过命令行或 YAML 创建。比如希望 Secret 中包含如下信息:

    1. 用户名 admin

    2. 密码 123456

    创建 Secret

    有四种方法创建 Secret:

    1. 通过 --from-literal

    kubectl create secret generic mysecret --from-literal=username=admin --from-literal=password=123456

    每个 --from-literal 对应一个信息条目。

    2. 通过 --from-file

    echo -n admin > ./username
    echo -n 123456 > ./password
    kubectl create secret generic mysecret --from-file=./username --from-file=./password

    每个文件内容对应一个信息条目。

    3. 通过 --from-env-file

    cat << EOF > env.txt
    username=admin
    password=123456
    EOF
    kubectl create secret generic mysecret --from-env-file=env.txt

    文件 env.txt 中每行 Key=Value 对应一个信息条目。

    4. 通过 YAML 配置文件:

    文件中的敏感数据必须是通过 base64 编码后的结果。

    执行 kubectl apply 创建 Secret:

    下一节我们学习如何使用这些创建好的 Secret。

  • 相关阅读:
    axios express设置跨域允许传递cookie
    yarn常用命令指北
    Web代理工具NProxy
    DevOps的了解
    css图片hover放大
    autoprefixer
    谈谈浏览器http缓存
    欢迎使用 MWeb
    优化关键渲染路径CRP
    chrome 61 更新
  • 原文地址:https://www.cnblogs.com/twobrother/p/11120341.html
Copyright © 2011-2022 走看看