# Environment variables in Plugin Configuration

**URL:** <https://discuss.konghq.com/t/environment-variables-in-plugin-configuration/6335>\
**Category:** Questions\
**Tags:** service-mesh, kubernetes\
**Created:** [May 19, 2020, 5:18pm UTC](https://discuss.konghq.com/t/environment-variables-in-plugin-configuration/6335 "2020-05-19T17:18:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kvwork](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@kvwork](https://discuss.konghq.com/u/kvwork)\
**Post date:** [May 19, 2020, 5:18pm UTC](https://discuss.konghq.com/t/environment-variables-in-plugin-configuration/6335/1 "2020-05-19T17:18:12Z")

</div>

I am using Kong Ingress Controller 0.8.1 and trying to configure few plugins including custom ones. I am able to get them working however I would like to configure some of the plugin parameters using environment variables. E.g. provide a plugin parameter with value of the Kubernetes Node IP on which Kong Pod is running. Is this possible and if so how would I do it via declarative configuration?

```
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: ingress-kong
  name: ingress-kong
  namespace: kong
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ingress-kong
  template:
    metadata:
      annotations:
        kuma.io/gateway: enabled
        prometheus.io/port: "9542"
        prometheus.io/scrape: "true"
        traffic.sidecar.istio.io/includeInboundPorts: ""
      labels:
        app: ingress-kong
    spec:
      containers:
      - env:
        - name: POD_HOST_IP
          valueFrom:
            fieldRef:
              fieldPath: status.hostIP
...
---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: my-plugin
  namespace: myns
config:
  kongNodeIP: <POD_HOST_IP> # how to specify POD env variable here?
plugin: my-plugin
---

```

---

<div class="post-metadata">

**Author:** ![traines](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/traines/32/158_2.png) [@traines](https://discuss.konghq.com/u/traines)\
**Post date:** [May 19, 2020, 7:56pm UTC](https://discuss.konghq.com/t/environment-variables-in-plugin-configuration/6335/2 "2020-05-19T19:56:25Z")

</div>

To clarify, are you looking to specify the environment variable name or the environment variable value? The latter isn’t possible because the KongPlugin exists outside the Pod and isn’t sent to it directly, it’s translated into its Kong-native format and then applied through the admin API.

Specifying the name should work, but with caveats:

- The plugin has to [load the variable](https://www.lua.org/manual/5.1/manual.html#pdf-os.getenv) in its code. There’s no generic support for automatically translating environment variables in configuration to their local value.
- NGINX has to [expose the environment variable](https://github.com/openresty/lua-nginx-module#system-environment-variable-support) to Kong. This should be possible by using [main directive injection](https://github.com/Kong/kong/blob/master/kong.conf.default#L577-L578) to add [an env directive](http://nginx.org/en/docs/ngx_core_module.html#env).

---

<div class="post-metadata">

**Author:** ![kvwork](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@kvwork](https://discuss.konghq.com/u/kvwork)\
**Post date:** [May 19, 2020, 8:42pm UTC](https://discuss.konghq.com/t/environment-variables-in-plugin-configuration/6335/3 "2020-05-19T20:42:06Z")

</div>

Thanks for the response. I was hoping for using the environment variable value which looks like is not possible. I will try alternative options for my configuration.
