Environment variables in VCL

Vlad Rusu vlad.rusu at lola.tech
Tue Sep 10 20:54:57 UTC 2019


@Hugues

I am also a heavy user in kube/openshift environments and this issue is
addressed by means of templating.

Using tools like helm would easily solve this for you. Helm has the value
and it uses it when rendering the backends file - in the form of a
configmap perhaps.

If you can’t/don’t want to use helm, you can still “render” configuration
by consuming values from the ENV by using envsubst for example. This is how
we dis it before helm. Burn the backends.vcl file AT RUNTIME by passing the
backends.vcl file through envsubst.

Either way, my recommendation is to solve this through templating and not
by trying to access ENV directly from the the backends VCL. I’m saying this
having a proper SDLC in mind.

Of course, dynamic backends and all other options Guillaume and
Paul-Henning have mentioned are solid.

Vlad Rusu

On Tue, 10 Sep 2019 at 22:14, Hugues Alary <hugues at betabrand.com> wrote:

> Guillaume, Poul-Henning, thank you for your suggestions.
>
> Regarding,
> > - create a static backend point to you k8s proxy, and just set
> req.http.host to whatever value you want.
>
> I don't think this would work for me since I'm working with a backend
> definition, trying to change the IP address (/hostname) to which the
> backend points to and not simply trying to change the Host header of the
> request.
>
> Cheers,
> -Hugues
>
>
>
> On Mon, Sep 9, 2019 at 11:54 PM Guillaume Quintard <
> guillaume at varnish-software.com> wrote:
>
>> True, but that amounts to template processing :-)
>>
>> --
>> Guillaume Quintard
>>
>>
>> On Tue, Sep 10, 2019 at 8:44 AM Poul-Henning Kamp <phk at phk.freebsd.dk>
>> wrote:
>>
>>> --------
>>> In message <
>>> CAJ6ZYQy5RnBjfCs88re6-hMfsQvyuzbOkHoofQ_c+suQNRQjig at mail.gmail.com>
>>> , Guillaume Quintard writes:
>>>
>>> >I see two ways:
>>>
>>> There is a third way:
>>>
>>> You can use:
>>>
>>>         include "somefile"
>>>
>>> anywhere and everywhere in a VCL program.
>>>
>>> Before you start your varnishd, do this in a shell script:
>>>
>>>         echo "\"$ENVIRONMENT_VARIABLE_HOSTNAME\"" >
>>> /somewhere/hostname.vcl
>>>
>>> Then in VCL:
>>>
>>>         backend b0 {
>>>                 .host = include "/somewhere/hostname.vcl" ;
>>>                 .port 80
>>>                 ...
>>>
>>>
>>>
>>> --
>>> Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
>>> phk at FreeBSD.ORG         | TCP/IP since RFC 956
>>> FreeBSD committer       | BSD since 4.3-tahoe
>>> Never attribute to malice what can adequately be explained by
>>> incompetence.
>>>
>> _______________________________________________
>> varnish-misc mailing list
>> varnish-misc at varnish-cache.org
>> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>
-- 
Sent from my iPhone
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20190910/26012477/attachment.html>


More information about the varnish-misc mailing list