Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda