Create YAML Manifest Templates in Minutes

Table of contents

What is YAML Templating?

YAML templating allows for the creation of reusable files that can be extensively configured by using variables and conditionals. With YAML templating, devs can generate files specific to any need or requirement.

In fact, you can use Monokle, a set of tools that helps create and manage quality Kubernetes deployments, to generate and manage your own YAML files!  

First, let’s see what the structure of monokle-template.json for a Monokle template looks like: 

This is an example of a template that creates a pod (found here)

You can find out more about how Monokle helps you create and manage templates, here 

Ready to dive into Monokle and start generating your own? Click here to Download

How to create a YAML Templates (the old fashioned way)

To create a YAML template, first define the structure of the YAML file by using valid syntax. Afterwards, replace values that can change with any variables. These can be defined at the beginning of the template and then defined through the entire file. Next, make the YAML file flexible and customizable, by using conditionals so that the template can be reusable across multiple configurations.  

Making reusable templates are vital to your lifecycle and efficiency, so here’s 3 tips when it comes to putting your best template forward.

Top 3 Things to Remember when Creating Reusable YAML Templates

  1. The Single Responsibility Principle
    The Single Responsibility Principle states that every YAML template should have one responsibility, containing the configuration needed for only a single component or service. Doing this will make your templates easier to read, maintain and use again! Also, don’t forget to keep your YAML templates organized so they can be shared and updated across the team!
  2. Aggregate Templates
    When working with complex configurations that require multiple components or services, Aggregate templates are used to combine multiple YAML templates into a single file. With this technique, developers can easily maintain large configurations while still following the Single Responsibility Principle mentioned above. Complex configurations are difficult to manage, but by using Aggregate Templates, you can remove a huge burden.
  3. Use parameters
    There is no need to hard code anything within your templates. Simply add all configurations to parameters.

If you’re still having trouble tackling the YAML Monster, check out the articles below 

YAML Basics 

Common Errors Found in Kubernetes Manifests 

How To Create a YAML Manifest Template in Monokle