krakend / krakend-ce

KrakenD Community Edition: High-performance, stateless, declarative, API Gateway written in Go.
https://www.krakend.io
Apache License 2.0
2.01k stars 454 forks source link

Building a Krakend image to run on k8s #757

Closed Amf1k closed 1 year ago

Amf1k commented 1 year ago

Hi! I have a question about building an image for ci/cd and running Krakend in k8s. What is the best practice about create an image with a flexible config? https://www.krakend.io/docs/configuration/flexible-config/ I mean, that I have config with some env variables (e.g. AMQP URL with user/password). If we look at the instruction https://www.krakend.io/docs/deploying/docker/ we can see that is compile time build and I must provide some credentials for my environment at this time (at gitlab ci/cd pipeline), but I can't provide some credentials. I don't want to create an image with my credentials from production, it isn't safe.

Amf1k commented 1 year ago

I had to invent it myself. The only option that works is to use the flexibility config as an artifact. That is, do not build it as the instruction suggests https://www.krakend.io/docs/deploying/docker/, but simply build it at runtime at startup (at the same time, check and linter checks are performed in ci / cd). I didn’t understand this implementation https://github.com/krakendio/krakend-ce/issues/586#issuecomment-1263319613 - why make a template from a template and then separate the processing of variables.

My Dockerfile

FROM devopsfaith/krakend:2.4.1

COPY --chown=krakend:nogroup config .

ENV FC_ENABLE=1
ENV FC_PARTIALS_PATH=partials
ENV FC_SETTINGS=settings
ENV FC_TEMPLATES=templates

After that we can use command in k8s or Docker run

docker run -it --env-file configs.yaml --env-file secrets.yaml $(IMAGE_NAME) run -c krakend.tmpl
github-actions[bot] commented 1 year ago

This issue was marked as resolved a long time ago and now has been automatically locked as there has not been any recent activity after it. You can still open a new issue and reference this link.