Passing Connection String As Environment Variable in yaml file

10/14/2019

I have password of my SQL connection as secret key. I assigned this to a key. I need to pass the SQL connection string as an environment variable which assigns value in my appsettings.json file. It was working when I passed a team city variable as password. But when I changed password to secret key, I'm not able to retrieve data from API (Moved to Kubernities). It shows an error login failed for user. How can I pass a connection string in YAML file with password as secret key?

I tried to access the key in several ways but the result was the same.

env:
   - name: SECRET_USERNAME
     valueFrom:
          secretKeyRef:
            name: mysecret
            key: username
    - name: SECRET_PASSWORD
      valueFrom:
          secretKeyRef:
            name: mysecret
            key: password

  -name:ConnectionString
   Value: "server:172.168.0.1; username: ${SECRET_USERNAME};password:${SECRET_PASSWORD};....." 

Please don't mind the indentation here. I have it correctly in the file. How can I access SECRET_PASSWORD here?

The API wants to return success message. But am getting error login failed for user.

-- VAISAKH K C
kubernetes
kubernetes-helm
yaml

2 Answers

10/14/2019

I think you have to decode the secrete first

kubectl get secret mysecret -o yaml
apiVersion: v1
kind: Secret 
metadata:
  creationTimestamp: 2016-01-22T18:41:56Z
  name: mysecret
  namespace: default
  resourceVersion: "164619"
  uid: cfee02d6-c137-11e5-8d73-42010af00002
type: Opaque
data:
  username: YWRtaW4=
  password: MWYyZDFlMmU2N2Rm

Decode the password field:

echo 'MWYyZDFlMmU2N2Rm' | base64 --decode

https://kubernetes.io/docs/concepts/configuration/secret/

kindly correct me if I'm wrong I'm new here

-- Muhammad Ibtihaj Naeem
Source: StackOverflow

10/14/2019

Please refer to the kubernetes documentation which talks about the usage of password in secret and mount as a file the path you set.

-- Bimal
Source: StackOverflow