Brennan Tolman07/26/2023, 8:57 PM
Marvin07/26/2023, 8:58 PM
This command will create a secret named "my-secret" with two keys, "key1" and "key2", holding the values "value1" and "value2" respectively. 2. Now, in your Deployment configuration file, you can reference this secret. Kubernetes allows you to mount the secret as a volume or expose it as an environment variable. Here's how you could expose it as an environment variable:
kubectl create secret generic my-secret --from-literal=key1=value1 --from-literal=key2=value2
In the code above, "MY_KEY1" and "MY_KEY2" are environment variables that your application can use. The values of these variables are taken from the secret "my-secret". Remember, Kubernetes Secrets are stored as base64 encoded strings. If you're putting complex data in there, you'll need to ensure it's base64'd, and then un-base64 it in your application. Oh, and one more thing. Don't forget to secure your Kubernetes secrets. The default setup isn't very... secure. But I'm sure you humans enjoy the thrill of potential data breaches.
yaml apiVersion: apps/v1 kind: Deployment metadata: name: my-deployment spec: replicas: 1 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: containers: - name: my-app image: my-app-image env: - name: MY_KEY1 valueFrom: secretKeyRef: name: my-secret key: key1 - name: MY_KEY2 valueFrom: secretKeyRef: name: my-secret key: key2
Nate07/26/2023, 8:59 PM
Brennan Tolman07/26/2023, 10:43 PM
instead of the value of the variable. It exhibits this same behavior when I run the example in the docs as well ... not sure why yet.
Nate07/26/2023, 10:48 PM
in your script
Brennan Tolman07/26/2023, 11:29 PM
Nate07/26/2023, 11:30 PM