<p>I am looking for something equivalent to SPRING_APPLICATION_JSON env variable of Docker Compose in Kubernetes Deployment yaml.</p>

<p>I am aware of that we can pass individual config as name-value pair. But there must be something through which all env variables can be passed in json or yaml format in Kubernetes.</p>

<p>You can do it through config maps, as shown above, or you can read in the environment variable value as a string and unmarshal it. To this, you'd have to make use of <code>|</code> -- a yaml operator which allows you to embed more &quot;complicated&quot; structures.</p>
<p>e.g in your K8s deployment.yaml:</p>
<pre class="lang-yaml prettyprint-override"><code> ...
 env:
 - name: FOO
   value: |
   {&quot;foo&quot;:&quot;bar&quot;}
</code></pre>
<p>then in your code</p>
<pre class="lang-golang prettyprint-override"><code>type v struct {
    Key string `json:&quot;foo&quot;`
}
    
func main() {
    foo := os.Getenv(&quot;FOO&quot;)
    var t v
    if err := json.Unmarshal([]bytes(foo), &amp;t); err != nil {
        // log error
    }
    
    fmt.Println(&quot;Foo %s&quot;, t.Foo) // should print out &quot;bar&quot;
}
</code></pre>
<p>I'm not sure how well it looks like if you try to do this with yaml, but json objects can definitely be passed this way through the environment variable API in k8s. I'll leave it up to you to decide on the pros and cons of it. :)</p>
