KrakenD Enterprise 2.0 released! Read the Release notes »

Documentation

Recent changes

Generating a Docker artifact

If you use containers, the recommended approach is to write your own Dockerfile and deploy an immutable artifact (embedding the config).

In its simplified form would be:

FROM 052351007912.dkr.ecr.us-east-1.amazonaws.com/krakend-ee:2.0.2
COPY krakend.json /etc/krakend/krakend.json
# Uncomment with Enterprise image:
# COPY LICENSE /etc/krakend/LICENSE

Volume or copy?
Even though you can use the official container directly and attach the configuration mounting an external volume (or ConfigMap in Kubernetes), a custom image with your configuration copied inside has benefits. It guarantees that you can do safe rollbacks and have effective testing and debugging. If you break something at any point, you only need to deploy the previous container, while if you use a volume, you are exposed to downtime or impossible scaling until you fix it.

A more real-life example illustrates below a combination of the check command with a multi-stage build to compile a flexible configuration in a Dockerfile:

FROM 052351007912.dkr.ecr.us-east-1.amazonaws.com/krakend-ee:2.0.2 as builder
ARG ENV=prod

COPY krakend.tmpl .
COPY config .

## Save temporary file to /tmp to avoid permission errors
RUN FC_ENABLE=1 \
    FC_OUT=/tmp/krakend.json \
    FC_PARTIALS="/etc/krakend/partials" \
    FC_SETTINGS="/etc/krakend/settings/$ENV" \
    FC_TEMPLATES="/etc/krakend/templates" \
    krakend check -d -t -c krakend.tmpl

# The linting needs the final krakend.json file
RUN krakend check -c /tmp/krakend.json --lint

FROM 052351007912.dkr.ecr.us-east-1.amazonaws.com/krakend-ee:2.0.2
COPY --from=builder --chown=krakend /tmp/krakend.json .
# Uncomment with Enterprise image:
# COPY LICENSE /etc/krakend/LICENSE

The Dockerfile above has two stages: The check command compiles the template krakend.tmpl and any included sub-template inside and outputs (FC_OUT) the resulting /tmp/krakend.json file. The krakend.json file is the only addition to the final Docker image.

The example above assumes you have a file structure like this:

.
├── config
│   ├── partials
│   ├── settings
│   │   ├── prod
│   │   │   └── env.json
│   │   └── test
│   │       └── env.json
│   └── templates
│       └── some.tmpl
├── Dockerfile
└── krakend.tmpl

Generate the skeleton above with:

mkdir -p config/{partials,settings,templates}
mkdir -p config/settings/{prod,test}
touch Dockerfile krakend.tmpl

Now the only missing step to generate the image, is to build it, making sure that the environment argument matches our folder inside the settings folder:

Docker build 
$docker build --build-arg ENV=prod -t mykrakend . 

The resulting image, including your configuration, weighs around 80MB.

Unresolved issues?

The documentation is only a piece of the help you can get! Whether you are looking for Open Source or Enterprise support, see more support channels that can help you.

We use cookies to understand how you use our site and to improve your overall experience. By continuing to use our site, you accept our Privacy Policy. More information