Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes - Shared environment variables for all Pods

We have to set https_proxy & http_proxy for internet access from our cluster instances.

https_proxy & http_proxy environment variables should be exported to all pods so that application can access external sites.

We are using helm charts so is there common place we can set these environment variables so all pods can access internet.

like image 630
erdarun Avatar asked Feb 06 '19 10:02

erdarun


People also ask

Do containers in a pod share environment variables?

Short answer is No, they can't.

How do you pass environment variables in pod?

When you create a Pod, you can set dependent environment variables for the containers that run in the Pod. To set dependent environment variables, you can use $(VAR_NAME) in the value of env in the configuration file.

How do I get environment variables in Kubernetes?

There are two ways to define environment variables with Kubernetes: by setting them directly in a configuration file, from an external configuration file, using variables, or a secrets file. This tutorial shows both options, and uses the Humanitec getting started application used in previous tutorials.


1 Answers

you should be using PodPreset obejct to pass common environment variables and other params to all the matching pods.

Add label setproxy:true to all pods

The below PodPreset object would inject HTTPS_PROXY and HTTP_PROXY environment variable to all pods that match label 'setproxy:true'

apiVersion: settings.k8s.io/v1alpha1
kind: PodPreset
metadata:
  name: inject-proxy-var
spec:
  selector:
    matchLabels:
      setproxy: true
  env:
    - name: HTTPS_PROXY
      value: "https_proxy"
    - name: HTTP_PROXY
      value: "http_proxy"

Follow the link for more help --> https://kubernetes.io/docs/tasks/inject-data-application/podpreset/

You should enable Pod Preset in your cluster. follow the below link

https://kubernetes.io/docs/concepts/workloads/pods/podpreset/

like image 53
P Ekambaram Avatar answered Oct 26 '22 00:10

P Ekambaram