Brennan Tolman
07/26/2023, 8:57 PMMarvin
07/26/2023, 8:58 PMkubectl create secret generic my-secret --from-literal=key1=value1 --from-literal=key2=value2
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:
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
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.Nate
07/26/2023, 8:59 PMNate
07/26/2023, 8:59 PMBrennan Tolman
07/26/2023, 10:43 PMecho $HADOOP_HOME
returns $HADOOP_HOME
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.Nate
07/26/2023, 10:48 PMNate
07/26/2023, 10:48 PMbash -c
in your scriptNate
07/26/2023, 10:48 PMBrennan Tolman
07/26/2023, 11:29 PMNate
07/26/2023, 11:30 PM