Sha256: 10ab7922d4c624f5f7f1014e77c0a67a3cc525658e3dc2b79f1718e223a97643

Contents?: true

Size: 1.77 KB

Versions: 24

Compression:

Stored size: 1.77 KB

Contents

---
title: Multiple Environments with Layering
nav_text: Multiple Environments
categories: patterns
---

You can use Kubes to easily create multiple environments with the same YAML configs.  This is thanks to [Kubes Layering]({% link _docs/layering.md %}). We'll walk through an example to help understand how it works.

## Creating Multiple Environments

To create multiple environments like dev and prod just change KUBES_ENV. Example:

    KUBES_ENV=dev  kubes deploy
    KUBES_ENV=prod kubes deploy

Different env files will be layered and merged to produce YAML files specific to each environment.

## Project Structure

Here's an example structure, so we can understand how layering works to create multiple environments.

    .kubes/resources/
    ├── base
    │   ├── all.yaml
    │   └── deployment.yaml
    └── web
        ├── deployment
        │   ├── dev.yaml
        │   └── prod.yaml
        ├── deployment.yaml
        └── service.yaml

## Concrete Example

Let's look at a concrete web/deployment.yaml.

Here are the files that get layered when `KUBES_ENV=dev`:

    .kubes/resources/base/all.yaml
    .kubes/resources/base/deployment.yaml
    .kubes/resources/web/deployment.yaml
    .kubes/resources/web/deployment/dev.yaml

And when `KUBES_ENV=prod`:

    .kubes/resources/base/all.yaml
    .kubes/resources/base/deployment.yaml
    .kubes/resources/web/deployment.yaml
    .kubes/resources/web/deployment/prod.yaml

Layering allows us to have common settings that are processed before your main `.kubes/resources/web/deployment.yaml` YAML manifest. And then add **environment** specific YAML files that get merged.

## Variables and Helpers

Additional, you can use variables and helpers to provide environment specific values.

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
kubes-0.9.3 docs/_docs/patterns/multiple-envs.md
kubes-0.9.2 docs/_docs/patterns/multiple-envs.md
kubes-0.9.1 docs/_docs/patterns/multiple-envs.md
kubes-0.9.0 docs/_docs/patterns/multiple-envs.md
kubes-0.8.10 docs/_docs/patterns/multiple-envs.md
kubes-0.8.9 docs/_docs/patterns/multiple-envs.md
kubes-0.8.8 docs/_docs/patterns/multiple-envs.md
kubes-0.8.7 docs/_docs/patterns/multiple-envs.md
kubes-0.8.6 docs/_docs/patterns/multiple-envs.md
kubes-0.8.5 docs/_docs/patterns/multiple-envs.md
kubes-0.8.4 docs/_docs/patterns/multiple-envs.md
kubes-0.8.3 docs/_docs/patterns/multiple-envs.md
kubes-0.8.2 docs/_docs/patterns/multiple-envs.md
kubes-0.8.1 docs/_docs/patterns/multiple-envs.md
kubes-0.8.0 docs/_docs/patterns/multiple-envs.md
kubes-0.7.10 docs/_docs/patterns/multiple-envs.md
kubes-0.7.9 docs/_docs/patterns/multiple-envs.md
kubes-0.7.8 docs/_docs/patterns/multiple-envs.md
kubes-0.7.7 docs/_docs/patterns/multiple-envs.md
kubes-0.7.6 docs/_docs/patterns/multiple-envs.md