PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 5, 2022

[FIXED] How to override Go environment variables with Helm

 November 05, 2022     environment-variables, go, kubernetes-helm     No comments   

Issue

How do I override environment variables in a .env file for Go with Helm?

With C# I do the following:

In appsettings.json:

{
    "Animals":{
        "Pig": "Squeek"
    },
}

In values.yaml:

animals:
  pig: "Oink"

In configmap.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: animal-configmap
pig: {{ .Values.animals.pig }}

And finally in deployment.yaml:

spec:
  ...
  template:
    ...
    spec:
      ...
      containers:
          ...
          env:
            - name: Animals__Pig
              valueFrom:
                configMapKeyRef:
                  name: animal-configmap  
                  key: pig

Not the double __. How would one go about updating an environment value for Go?

Here is the Go .env file example:

PIG=SQUEEK

Solution

If your Go code is retrieving an ordinary environment variable

pig := os.Getenv("PIG")

then the Kubernetes manifest should use that name as the environment variable name:

env:
  - name: PIG
    valueFrom: {...}

The double-underscore doesn't have any special meaning in Unix environment variables or the Kubernetes manifest, in your initial example it looks like the way the C# framework separates components when it maps environment variables to application properties. If you're using environment variables directly you don't need to do anything special.



Answered By - David Maze
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing