1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 12:46:18 +01:00
Files
openshift-docs/modules/builds-using-secrets.adoc
2019-05-13 13:57:48 +10:00

117 lines
2.3 KiB
Plaintext

// Module included in the following assemblies:
// * assembly/builds
[id="builds-using-secrets_{context}"]
= Using secrets
After creating secrets, you can create a pod to reference your secret, get logs,
and delete the pod.
.Procedure
. Create the pod to reference your secret:
+
----
$ oc create -f <your_yaml_file>.yaml
----
. Get the logs:
+
----
$ oc logs secret-example-pod
----
. Delete the pod:
+
----
$ oc delete pod secret-example-pod
----
.Additional resources
* Example YAML files with secret data:
+
.YAML Secret That Will Create Four Files
[source,yaml]
----
apiVersion: v1
kind: Secret
metadata:
name: test-secret
data:
username: dmFsdWUtMQ0K <1>
password: dmFsdWUtMQ0KDQo= <2>
stringData:
hostname: myapp.mydomain.com <3>
secret.properties: |- <4>
property1=valueA
property2=valueB
----
<1> File contains decoded values.
<2> File contains decoded values.
<3> File contains the provided string.
<4> File contains the provided data.
+
.YAML of a Pod Populating Files in a Volume with Secret Data
[source,yaml]
----
apiVersion: v1
kind: Pod
metadata:
name: secret-example-pod
spec:
containers:
- name: secret-test-container
image: busybox
command: [ "/bin/sh", "-c", "cat /etc/secret-volume/*" ]
volumeMounts:
# name must match the volume name below
- name: secret-volume
mountPath: /etc/secret-volume
readOnly: true
volumes:
- name: secret-volume
secret:
secretName: test-secret
restartPolicy: Never
----
+
.YAML of a Pod Populating Environment Variables with Secret Data
[source,yaml]
----
apiVersion: v1
kind: Pod
metadata:
name: secret-example-pod
spec:
containers:
- name: secret-test-container
image: busybox
command: [ "/bin/sh", "-c", "export" ]
env:
- name: TEST_SECRET_USERNAME_ENV_VAR
valueFrom:
secretKeyRef:
name: test-secret
key: username
restartPolicy: Never
----
+
.YAML of a Build Config Populating Environment Variables with Secret Data
[source,yaml]
----
apiVersion: v1
kind: BuildConfig
metadata:
name: secret-example-bc
spec:
strategy:
sourceStrategy:
env:
- name: TEST_SECRET_USERNAME_ENV_VAR
valueFrom:
secretKeyRef:
name: test-secret
key: username
----