This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 17. Secrets
17.1. Overview 링크 복사링크가 클립보드에 복사되었습니다!
The Secret
object type provides a mechanism to hold sensitive information such as passwords, OpenShift Enterprise client config files, dockercfg
files, private source repository credentials, etc. Secrets decouple sensitive content from the pods that use it and can be mounted into containers using a volume plug-in or used by the system to perform actions on behalf of a pod. This topic discusses important properties of secrets and provides an overview on how developers can use them.
Example 17.1. YAML Secret Object Definition
- 1
- The allowable format for the keys in the
data
field must meet the guidelines in the DNS_SUBDOMAIN value in the Kubernetes identifiers glossary.
17.2. Properties of Secrets 링크 복사링크가 클립보드에 복사되었습니다!
Key properties include:
- Secret data can be referenced independently from its definition.
- Secret data never comes to rest on the node. Volumes are backed by temporary file-storage facilities (tmpfs).
- Secret data can be shared within a namespace.
17.2.1. Secrets and the Pod Lifecycle 링크 복사링크가 클립보드에 복사되었습니다!
A secret must be created before the pods that depend on it.
Containers read the secret from the files. If a secret is expected to be stored in an environment variable, then you must modify the image to populate the environment variable from the file before running the main program.
Once a pod is created, its secret volumes do not change, even if the secret resource is modified. To change the secret used, the original pod must be deleted, and a new pod (perhaps with an identical PodSpec) must be created. An exception to this is when a node is rebooted and the secret data must be re-read from the API server. Updating a secret follows the same workflow as deploying a new container image. The kubectl rollingupdate
command can be used.
The resourceVersion
value in a secret is not specified when it is referenced. Therefore, if a secret is updated at the same time as pods are starting, then the version of the secret will be used for the pod will not be defined.
Currently, it is not possible to check the resource version of a secret object that was used when a pod was created. It is planned that pods will report this information, so that a controller could restart ones using a old resourceVersion
. In the interim, do not update the data of existing secrets, but create new ones with distinct names.
17.3. Creating and Using Secrets 링크 복사링크가 클립보드에 복사되었습니다!
When creating secrets:
- Create a secret object with secret data
-
Create a pod with a volume of type
secret
and a container to mount the volume - Update the pod’s service account to allow the reference to the secret.
17.3.1. Creating Secrets 링크 복사링크가 클립보드에 복사되었습니다!
To create a secret object, use the following command, where the JSON file is a predefined secret:
oc create -f secret.json
$ oc create -f secret.json
17.3.2. Secrets in Volumes and Environment Variables 링크 복사링크가 클립보드에 복사되었습니다!
See examples of YAML files with secret data.
After you create a secret, you can:
Create the pod to reference your secret:
oc create -f <your_yaml_file>.yaml
$ oc create -f <your_yaml_file>.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get the logs:
oc logs secret-example-pod
$ oc logs secret-example-pod
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the pod:
oc delete pod secret-example-pod
$ oc delete pod secret-example-pod
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
17.3.3. Image Pull Secrets 링크 복사링크가 클립보드에 복사되었습니다!
See Using Image Pull Secrets for more information.
17.3.4. Source Clone Secrets 링크 복사링크가 클립보드에 복사되었습니다!
See Using Private Repositories for Builds for more information.
17.4. Restrictions 링크 복사링크가 클립보드에 복사되었습니다!
To use a secret, a pod needs to reference the secret. A secret can be used with a pod in two ways: either as files in a volume mounted on one or more of its containers, or used by kubelet when pulling images for the pod.
Volume type secrets write data into the container as a file using the volume mechanism. imagePullSecrets use service accounts for the automatic injection of the secret into all pods in a namespaces.
When a template contains a secret definition, the only way for the template to use the provided secret is to ensure that the secret volume sources are validated and that the specified object reference actually points to an object of type Secret
. Therefore, a secret needs to be created before any pods that depend on it. The most effective way to ensure this is to have it get injected automatically through the use of a service account.
Secret API objects reside in a namespace. They can only be referenced by pods in that same namespace.
Individual secrets are limited to 1MB in size. This is to discourage the creation of large secrets that would exhaust apiserver and kubelet memory. However, creation of a number of smaller secrets could also exhaust memory.
17.4.1. Secret Data Keys 링크 복사링크가 클립보드에 복사되었습니다!
Secret keys must be in a DNS subdomain.
17.5. Examples 링크 복사링크가 클립보드에 복사되었습니다!
Example 17.2. YAML Secret That Will Create Four Files
Example 17.3. YAML of a Pod Populating Files in a Volume with Secret Data
Example 17.4. YAML of a Pod Populating Environment Variables with Secret Data
17.6. Troubleshooting 링크 복사링크가 클립보드에 복사되었습니다!
Issue | Resolution |
---|---|
A service certificate generation fails with (service’s secret/ssl-key references serviceUID 62ad25ca-d703-11e6-9d6f-0e9c0057b608, which does not match 77b6dd80-d716-11e6-9d6f-0e9c0057b60
|
The service that generated the ceritiface no longer exists (has different oc delete secret <secret_name> oc annotate service <service_name> service.alpha.openshift.io/serving-cert-generation-error- oc annotate service <service_name> service.alpha.openshift.io/serving-cert-generation-error-num-
Note
The command removing annotation has a |