erdarun
erdarun

Reputation: 551

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.

Upvotes: 10

Views: 8080

Answers (2)

P Ekambaram
P Ekambaram

Reputation: 17621

You should be using PodPreset object 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/

Upvotes: 6

Rajesh Deshpande
Rajesh Deshpande

Reputation: 853

If i understood it correctly, you want to set env variable to container. If this is correct understanding, You can use below configuration for container to set env variables

env:
- name: HTTPS_PROXY
  value: "Value"
- name: HTTP_PROXY
  value: "Value"

You can check more details at :https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/#define-an-environment-variable-for-a-container

Upvotes: -5

Related Questions