Create a template

In order for you not to have to modify the current deployments specifically for k8sbox, we create your own template.

The final template will look like this

id = "${CI_SLUG}"
name = "test environment"
namespace = "test"
variables = "${PWD}/examples/environments/.env"

[[boxes]]
type = "helm"
chart = "${PWD}/examples/environments/box1/Chart.yaml"
values = "${PWD}/examples/environments/box1/values.yaml"
name = "first-box-2"
    [[boxes.applications]]
    name = "service-nginx-1"
    chart = "${PWD}/examples/environments/box1/templates/api-nginx-service.yaml"
    [[boxes.applications]]
    name = "deployment-nginx-1"
    chart = "${PWD}/examples/environments/box1/templates/api-nginx-deployment.yaml"

[[boxes]]
type = "helm"
chart = "${PWD}/examples/environments/box2/Chart.yaml"
values = "${PWD}/examples/environments/box2/values.yaml"
name = "second-box-2"
    [[boxes.applications]]
    name = "service-nginx-2"
    chart = "${PWD}/examples/environments/box2/templates/api-nginx-service.yaml"
    [[boxes.applications]]
    name = "deployment-nginx-2"
    chart = "${PWD}/examples/environments/box2/templates/api-nginx-deployment.yaml"

[[boxes]]
type = "helm"
chart = "${PWD}/examples/environments/ingress/Chart.yaml"
name = "third-box"
values = "${PWD}/examples/environments/ingress/values.yaml"
    [[boxes.applications]]
    name = "www-ingress-toml"
    chart = "${PWD}/examples/environments/ingress/templates/ingress.yaml"

Let's talk about the basic blocks and properties.

The environment is your final deployment. It contains one or more boxes.

A box is your microservice or application. It's just a specification of your helm chart and values. It also includes a bunch of your applications.

The application is your actual k8s deployment. Just yaml files, which are usually stored in forlder templates if you use helm to deploy your service.

The environment configuration file is the file that helps k8sbox understand everything it needs to deploy or remove your microservice or application. It should be stored where you want it, and you will pass the location of this file under the k8sbox run command flag.

Fields:

  1. id* - string (we're also provide deletion method to clean up your test environment. Id is a key to find the already deployed environment and clean everything up)

  2. name* - string

  3. namespace - string (if you want to deploy all your boxes under randomly generated different namespaces - leave it blank)

  4. variables - string (path to your .env variables file)

  5. boxes* - array

  6. boxes[i].type* - string (currently we're support only helm type)

  7. boxes[i].name* - string

  8. boxes[i].chart* - string (path to your Chart.yaml file)

  9. boxes[i].values* - string (path to your values.yaml file)

  10. boxes[i].namespace - string (you could specify different namespace specifically for a box, it would create automatically on first deploy)

  11. boxes[i].applications* - array

  12. boxes[i].applications[j].name* - string

  13. boxes[i].applications[j].chart* - string (specify a path to .yaml file)

To make k8sbox even more dynamic and flexible, we have implemented a system for getting boxes via http. You don't have to specify box specifications in the main file, just provide a link to them.

load_boxes_from = "https://example.com/example_boxes.toml"
[load_boxes_headers]
    [load_boxes_headers.0]
    name = "Content-Type"
    value = "application/toml"
    [load_boxes_headers.1]
    name = "Accept"
    value = "application/toml"

An example is available here: https://github.com/twelvee/k8sbox/tree/main/examples

Last updated