Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
How can sslcert and sslkey be passed as environment variables in Kubernetes?

I'm trying to make my app connect to my PostgreSQL instance through an encrypted and secure connection.

I've configured my server certificate and generated the client cert and key files.

The following command connects without problems:

psql "sslmode=verify-ca sslrootcert=server-ca.pem \
  sslcert=client-cert.pem sslkey=client-key.pem \
  hostaddr=<instance_ip> \
  port=5432 \
  user=db dbname=dbname"

Unfortunately, I couldn't find a way to pass the client key as value, I can only pass the file path. Even using the default environment variables from psql, this is not possible: https://www.postgresql.org/docs/current/libpq-envars.html

Golang follows the same specifications as lib-pq and there is no way to pass the cert and key values: https://pkg.go.dev/github.com/lib/pq?tab=doc#hdr-Connection_String_Parameters.

I want to store the client cert and key in environment variables for security reasons, I don't want to store sensitive files in github/gitlab.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Just set the values in your environment and you can get them in a init function.

func init() {
   var := os.Getenv("SOME_KEY")
}

When you want to set these with K8s you would just do this in a yaml file.

apiVersion: v1
kind: Secret
metadata:
  name: my-secret
data:
  SOME_KEY: the-value-of-the-key

Then to inject into the environment do.

envFrom:
  - secretRef:
    name: my-secret

Now when your init function runs it will we able to see SOME_KEY.

If you want to pass a secret as a file you do something like this.

kubectl create secret generic my-secret-files --from-file=my-secret-file-1.stuff --from-file=my-secret-file-2.stuff

Then in your deployment.

volumes:
  - name: my-secret-files
    secret:
      secretName: my-secret-files

Also in your deployment under you container.

volumeMounts:
  - name: my-secret-files
    mountPath: /config/

Now your init would be able to see.

/config/my-secret-file-1.stuff
/config/my-secret-file-2.stuff
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!