Files
website/content/zh/docs/tasks/inject-data-application/distribute-credentials-secure.md
Zach Corleissen abcee2dccd Update localization guidelines (#10485)
* Update localization guidelines for language labels

Continuing work

Continuing work

Continuing work

More work in progress

Add local OWNERS folders

Add an OWNERS file to Chinese

Remove shortcode for repos

Add Japanese

Alphabetize languages, change weights accordingly

More updates

Add Korean in Korean

Add English to languageName

Feedback from gochist

Move Chinese content from cn/ to zh/

Move OWNERS from cn/ to zh/

Resolve merge conflicts by updating from master

Add files back in to prep for resolution

After rebase on upstream/master, remove files

Review and update localization guidelines

Feedback from gochist, tnir, cstoku

Add a trailing newline to content/ja/OWNERS

Add a trailing newline to content/zh/OWNERS

Drop requirement for GH repo project

Clarify language about forks/branches

Edits and typos

Remove a shortcode specific to a multi-repo language setup

Update aliases and owners

Add explicit OWNERS for content/en

Migrate content from Chinese repo, update regex in config.toml

Remove untranslated strings

Add trailing newline to content/en/OWNERS

Add trailing newlines to OWNERS files

add Jaguar project description (#10433)

* add Jaguar project description

[Jaguar](https://gitlab.com/sdnlab/jaguar) is an open source solution for Kubernetes's network based on OpenDaylight.
Jaguar provides overlay network using vxlan and Jaguar CNIPlugin provides one IP address per pod.

* Minor newline tweak

blog post for azure vmss (#10538)

Add microk8s to pick-right-solution.md (#10542)

* Add microk8s to pick-right-solution.md

Microk8s is a single-command installation of upstream Kubernetes on any Linux and should be included in the list of local-machine solutions.

* capitalized Istio

Add microk8s to foundational.md (#10543)

* Add microk8s to foundational.md

Adding microk8s as credible and stable alternative to get started with Kubernetes on a local machine. This is especially attractive for those not wanting to incur the overhead of running a VM for a local cluster.

* Update foundational.md

Thank you for your suggestions! LMK if this works now?

* Rewrote first paragraph

And included a bullet list of features of microk8s

* Copyedit

fix typo (#10545)

Fix the kubectl subcommands links. (#10550)

Signed-off-by: William Zhang <warmchang@outlook.com>

Fix command issue (#10515)

Signed-off-by: mooncake <xcoder@tenxcloud.com>

remove imported community files per issue 10184 (#10501)

networking.md: Markdown fix (#10498)

Fix front matter, federation command-line tools (#10500)

Clean up glossary entry (#10399)

update slack link (#10536)

typo in StatefulSet docs (#10558)

fix discription about horizontal pod autoscale (#10557)

Remove redundant symbols (#10556)

Fix issue #10520 (#10554)

Signed-off-by: William Zhang <warmchang@outlook.com>

Update api-concepts.md (#10534)

Revert "Fix command issue (#10515)"

This reverts commit c02a7fb9f9.

Update memory-constraint-namespace.md (#10530)

update memory request to 100MiB corresponding the yaml content

Blog: Introducing Volume Snapshot Alpha for Kubernetes (#10562)

* blog post for azure vmss

* snapshot blog post

Resolve merge conflicts in OWNERS*

Minor typo fix (#10567)

Not sure what's supposed to be here, proposing removing it.

* Feedback from gochist

Tweaks to feedback

* Feedback from ClaudiaJKang
2018-10-12 14:25:01 -07:00

4.1 KiB
Raw Permalink Blame History

title, content_template
title content_template
使用 Secret 安全地分发凭证 templates/task

{{% capture overview %}} 本文展示如何安全地将敏感数据(如密码和加密密钥)注入到 Pods 中。 {{% /capture %}}

{{% capture prerequisites %}}

{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}

{{% /capture %}}

{{% capture steps %}}

将 secret 数据转换为 base-64 形式

假设用户想要有两条 secret 数据:用户名 my-app 和密码 39528$vdg7Jb。 首先使用 Base64 编码 将用户名和密码转化为 base-64 形式。 这里是一个 Linux 示例:

echo -n 'my-app' | base64
echo -n '39528$vdg7Jb' | base64

结果显示 base-64 形式的用户名为 bXktYXBw base-64 形式的密码为 Mzk1MjgkdmRnN0pi

创建 Secret

这里是一个配置文件,可以用来创建存有用户名和密码的 Secret:

{{< code file="secret.yaml" >}}

  1. 创建 Secret

    kubectl create -f secret.yaml
    

    {{< note >}} 注意: 如果想要跳过 Base64 编码的步骤,可以使用 kubectl create secret 命令来创建 Secret {{< /note >}}

    kubectl create secret generic test-secret --from-literal=username='my-app' --from-literal=password='39528$vdg7Jb'
    
  2. 查看 Secret 相关信息:

    kubectl get secret test-secret
    

    输出:

     NAME          TYPE      DATA      AGE
     test-secret   Opaque    2         1m
    
  3. 查看 Secret 相关的更多详细信息:

    kubectl describe secret test-secret
    

    输出:

     Name:       test-secret
     Namespace:  default
     Labels:     <none>
     Annotations:    <none>
    
     Type:   Opaque
    
     Data
     ====
     password:   13 bytes
     username:   7 bytes
    

创建可以通过卷访问 secret 数据的 Pod

这里是一个可以用来创建 pod 的配置文件:

{{< code file="secret-pod.yaml" >}}

  1. 创建 Pod

    kubectl create -f secret-pod.yaml
    
  2. 确认 Pod 正在运行:

    kubectl get pod secret-test-pod
    

    输出:

     NAME              READY     STATUS    RESTARTS   AGE
     secret-test-pod   1/1       Running   0          42m
    
  3. 在 Pod 中运行的容器中获取一个 shell:

    kubectl exec -it secret-test-pod -- /bin/bash
    
  4. secret 数据通过挂载在 /etc/secret-volume 目录下的卷暴露在容器中。 在 shell 中,进入 secret 数据被暴露的目录:

    root@secret-test-pod:/# cd /etc/secret-volume
    
  5. 在 shell 中,列出 /etc/secret-volume 目录的文件:

    root@secret-test-pod:/etc/secret-volume# ls
    

    输出显示了两个文件,每个对应一条 secret 数据:

     password username
    
  6. 在 shell 中,显示 usernamepassword 文件的内容:

    root@secret-test-pod:/etc/secret-volume# cat username; echo; cat password; echo
    

    输出为用户名和密码:

     my-app
     39528$vdg7Jb
    

创建通过环境变量访问 secret 数据的 Pod

这里是一个可以用来创建 pod 的配置文件:

{{< code file="secret-envars-pod.yaml" >}}

  1. 创建 Pod

    kubectl create -f secret-envars-pod.yaml
    
  2. 确认 Pod 正在运行:

    kubectl get pod secret-envars-test-pod
    

    输出:

     NAME                     READY     STATUS    RESTARTS   AGE
     secret-envars-test-pod   1/1       Running   0          4m
    
  3. 在 Pod 中运行的容器中获取一个 shell:

    kubectl exec -it secret-envars-test-pod -- /bin/bash
    
  4. 在 shell 中,显示环境变量:

     root@secret-envars-test-pod:/# printenv
    

    输出包括用户名和密码:

     ...
     SECRET_USERNAME=my-app
     ...
     SECRET_PASSWORD=39528$vdg7Jb
    

{{% /capture %}}

{{% capture whatsnext %}}

参考

  • [Secret](/docs/api-reference/{{< param "version" >}}/#secret-v1-core)
  • [Volume](/docs/api-reference/{{< param "version" >}}/#volume-v1-core)
  • [Pod](/docs/api-reference/{{< param "version" >}}/#pod-v1-core)

{{% /capture %}}