<p>Hi I am playing around with Kubernetes secrets.
My deployment file is :</p>

<pre><code>---
apiVersion: v1
kind: Secret
metadata:
  name: my-secrets
  labels:
    app: my-app
data:
  username: dXNlcm5hbWU=
  password: cGFzc3dvcmQ=
</code></pre>

<p>I am able to create secrets and I am mounting them in my deployments as below:</p>

<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-service
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  type: NodePort

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: spring-service
  labels:
    app: spring-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: spring-service
  template:
    metadata:
      labels:
        app: spring-service
    spec:
      containers:
      - name: spring-service
        image: my-image:tag
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: my-secret-vol
          mountPath: "/app/secrets/my-secret"
          readOnly: true            
      volumes:
      - name: my-secret-vol
        secret:
          secretName: my-secrets
</code></pre>

<p>My question is how can I access <code>username</code> and <code>password</code> I created in secret in spring-boot app?</p>

<p>I have tried loading in with <code>${my-secrets.username}</code> and <code>${username}</code>, but it fails to find values.</p>

<p>I also tried adding secrets as enviroment variables as below in deployment.yml:</p>

<pre><code>env:
- name: username
  valueFrom:
    secretKeyRef:
      name: my-secrets
      key: username
- name: password
  valueFrom:
    secretKeyRef:
      name: my-secrets
      key: password
</code></pre>

<p>In this case, values are loaded from secrets and when I change values of secrets in minikube dashboard, it does not reflect the changes.</p>

<p>Please help me to understand how this works.</p>

<p>I am using <code>minikube</code> and <code>docker</code> as containers</p>

Nirav
<p>For the first approach you'll find the values on:   </p>

<pre><code>- /app/secrets/my-secret/username
- /app/secrets/my-secret/password 
</code></pre>

<p>and for the second approach you can't change the value of env vars during runtime, you need to restart or redeploy the pod</p>
