Home > database >  Value of Kubernetes secret in environment variable seems incorrect
Value of Kubernetes secret in environment variable seems incorrect

Time:12-14

I'm deploying a test application onto kubernetes on my local computer (minikube) and trying to pass database connection details into a deployment via environment variables.

I'm passing in these details using two methods - a ConfigMap and a Secret. The username (DB_USERNAME) and connection url (DB_URL) are passed via a ConfigMap, while the DB password is passed in as a secret (DB_PASSWORD).

My issue is that while the values passed via ConfigMap are fine, the DB_PASSWORD from the secret appears jumbled - like there's some encoding issue (see image below). DB_PASSWORD not showing up properly

My deployment yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        envFrom:
        - configMapRef:
            name: gweb-cm
        - secretRef:
            name: password

My ConfigMap and Secret yaml

apiVersion: v1
data:
  DB_URL: jdbc:mysql://mysql/test?serverTimezone=UTC
  DB_USERNAME: webuser
  SPRING_PROFILES_ACTIVE: prod
  SPRING_DDL_AUTO: create
kind: ConfigMap
metadata:
  name: gweb-cm
---
apiVersion: v1
kind: Secret
metadata:
  name: password
type: Generic
data:
  DB_PASSWORD: test

Not sure if I'm missing something in my Secret definition?

CodePudding user response:

The secret value should be base64 encoded. Instead of test, use the output of

echo -n 'test' | base64

P.S. the Secret's type should be Opaque, not Generic

  • Related