🚀 How to use YTT and Vendir: Your Lightsabers in the World of Kubernetes: Part 1

Table of Contents
- Introduction 📜
- Section 1: Understanding YTT 🧙♂️
- Section 2: Introducing Vendir 🤖
- Section 3: Working with YTT 🛠️
- Section 4: Combining YTT and Vendir for a Galactic Kubernetes Configuration 🌌
- Section 6: Additional Tips and Best Practices 🚀
- Conclusion 🎉
Introduction 📜
In the vast and dynamic world of Kubernetes, managing configurations can be akin to orchestrating order in a galaxy teeming with diverse planets, species, and systems. Kubernetes, like the Star Wars galaxy, is vast, filled with myriad resources, services, and complexities. Just as the Rebel Alliance sought to bring balance to the Force and the Empire sought to control the galaxy, Kubernetes administrators grapple with orchestrating a harmonious coexistence of containerized applications, networking, storage, and more.
Configuring Kubernetes resources efficiently, ensuring compatibility between various components, and deploying applications at scale can be a daunting task.
The Galactic Kubernetes Challenge is not merely about keeping the Death Star plans safe or protecting the hidden Jedi temple; it’s about ensuring your applications and infrastructure run smoothly in an ever-evolving Kubernetes galaxy. Fortunately, just as Jedi Masters trained Padawans to harness the Force, we have powerful tools at our disposal to master the intricacies of Kubernetes configurations. And that’s where YTT and Vendir come into play. Together, they provide the Jedi wisdom and droid-like efficiency to help you conquer the Kubernetes galaxy. So, ‘May the YTT be with you 🌟’ as we embark on this epic journey.
References:
Section 1 : Understanding YTT 🧙♂️
YTT, the YAML Templating Tool, is your guiding presence in the Kubernetes galaxy, much like a wise and experienced Jedi Master. Just as a Jedi Master mentors their Padawan, YTT is here to mentor you in mastering Kubernetes YAML configurations. It simplifies the process of YAML templating, customization, and the generation of Kubernetes resource files. YTT enables you to transform raw YAML templates into powerful, accurate, and customized configurations, much like a Jedi using the Force to transform their surroundings.
Concept
- Templating Capabilities: YTT offers a range of templating features, allowing you to customize configurations by injecting values, parameters, and conditional logic.
- Readability: YTT promotes YAML configurations that are easy to read and understand. The structured and clean YAML files are akin to the clarity of a Jedi’s teachings, ensuring that others can comprehend and collaborate efficiently.
- Ease of Use: YTT’s user-friendly nature ensures that even those new to Kubernetes can learn its ways.
How it works
let’s break down how a YTT and Carvel project works in detail.
- 📄 Configuration File
YTT and Carvel work with YAML-based configuration files, which define the resources and settings for your Kubernetes applications.
2. 🧩 YTT Templating
You define your base configuration files, which can contain placeholders or tags that YTT will replace with actual values during the templating process.
3. 📝 Custom Values
Custom values are parameters that you can provide to YTT to customize the templating process for your project. These values are typically defined in a separate YAML file, often called a values file, and they can be used to replace placeholders in your base configuration files.
4. 🧰 Templates and Functions
YTT supports a variety of built-in functions and operators that you can use in your templates. You can perform operations like arithmetic, string manipulation, and conditional logic to create dynamic configurations.
5. 🔀 Merging Values
YTT allows you to merge multiple values files and custom values by specifying their paths. This enables you to customize your configuration based on different sources or environments.
5. 🚀 Outputs
Once YTT processes your base configuration files with the custom values and templates, it generates the final configuration files.
Section 2 : Introducing Vendir 🤖
Meet Vendir, the trusty droid sidekick in our Kubernetes adventure. Vendir simplifies the management of dependencies and external resources, ensuring a smooth and reliable Kubernetes journey. Think of Vendir as the R2-D2 of your configurations, supporting you by seamlessly integrating external resources. Refer to vendir source and check how it is used in details, Nevertheless we will use it later so patience my little padawan.
Section 3: Working with YTT 🛠️

Here, we’ll guide you through the basic steps of wielding YTT, emphasizing the art of configuration crafting.
Training Begins — Understanding Your YAML: Much like a Jedi understanding the nuances of the Force, your first step is to comprehend your YAML templates. Familiarize yourself with the structure, resources, and variables within your configurations. I really suggest that you go through these documents and read it carefully.
Mastering Templating — Harnessing the Force (YTT): YTT allows you to harness the Force of templating. Channel your newfound knowledge into your YAML templates by injecting variables and logic. Customize your configurations to suit the needs of your applications.
“Using the Force (YTT) to Customize Your Empire’s Death Star ⭐️”
Section 4: Combining YTT and Vendir for a Galactic Kubernetes Configuration 🌌
Let’s take an example on how to use YTT to customize our configuration.
Suppose you want to use Star Wars movie SSH and Telnet server and deploy it to multiple environments called ‘customers’, you want to have the base application not replicated across all the customers in order to fulfill the desired state of the deployed application.
vader_to_vendir
|_Taskfile.yaml
|_vendir.ytt.yml
|_vendir.ymlMake sure to use .yml for vendir files. Let’s explore our files before setting your environment for the big test.
- vendir.yml
#@ load("@ytt:data", "data")
apiVersion: vendir.k14s.io/v1alpha1
kind: Config
directories:
- path: config
contents:
#@ for chart in data.values:
- path: #@ chart.name
helmChart:
name: #@ chart.helmChart.name
version: #@ chart.helmChart.version
repository:
url: #@ chart.helmChart.repository.url
includePaths:
- values.yaml
- Chart.yaml
#@ end. vendir.ytt.yml
#@data/values
---
- name: ascii-movie
helmChart:
name: ascii-movie
version: 0.12.1
repository:
url: https://charts.gabe565.com. Taskfile.yaml
version: '3'
env:
BASE_DIR: ./config
RELEASES_DIR: ./charts
OUTPUT_DIR: "output"
VALUES_FILE: "vendir.ytt.yml"
TEMPLATE_FILE: "vendir.yml"
CUSTOM: no
tasks:
generate_and_sync:
desc: Generate and sync files using vendir and ytt
silent: true
cmds:
- "if ! command -v ytt &> /dev/null; then echo 'Error: ytt is not installed. Please install ytt before running this script.'; exit 1; fi"
- "if ! command -v vendir &> /dev/null; then echo 'Error: vendir is not installed. Please install vendir before running this script.'; exit 1; fi"
- "ytt -f \"$TEMPLATE_FILE\" -f \"$VALUES_FILE\" --output-files \"$OUTPUT_DIR\""
- "if [ ! -d \"$OUTPUT_DIR\" ]; then echo 'Error: Failed to generate the output file.'; exit 1; fi"
- "vendir sync -f \"$OUTPUT_DIR\"/vendir.yml"
- "rm -rf \"$OUTPUT_DIR\""This YAML configurations, guided by the Force 🌌, utilizes vendir and ytt to manage Helm charts like a Jedi manages lightsabers. The vendir.yaml structure, akin to a lightsaber hilt, orchestrates the placement of Helm charts. The data/values.yaml, a holocron of external data, contains details on charts like the "ascii-movie."
Explanation:
#@ load("@ytt:data", "data"):
This directive loads external data into the configuration. In this case, it loads the data from the values.yaml file using the data variable.
Referencing Variables from data:
Within the vendir.yaml file, you can reference variables from the loaded data using the #@ syntax. For example:
#@ chart.name: Refers to the name of a Helm chart in the external data (e.g vendir.ytt.yml).#@ chart.helmChart.name: Refers to the name of the Helm chart within the specific entry in the external data.
Similar references are used for version and repository URL.
Looping Over External Data:
#@ for chart in data.values: initiates a loop over the external data. For each iteration, it dynamically generates an entry in the vendir configuration based on the variables from the external data.
This combination of #@ load("@ytt:data", "data") and #@ references enables dynamic templating in the vendir.yaml file, allowing you to adapt the configuration based on external data. When you run ytt, it replaces these placeholders with the actual values from the external data, creating a customized Kubernetes configuration.
Before starting we need to setup our environment. For that we nee to install carvel packages and task binary. To do so please run these on your linux machine.
wget -O- https://carvel.dev/install.sh > install.sh sudo bash install.sh sudo snap install task --classic
Then to test run task command where the Taskfile exists.
task generate_and_sync
I know you are wondering what is this file used for ?? it is the nice version of make files. I will not go in details but feel free to read the docs.
After generating the above command now your root hierarchy will be as follow:
vader_to_vendir
|_Taskfile.yaml
|_vendir.lock.yml
|_vendir.ytt.yml
|_vendir.yml
|_config
|_ascii-movie
|_Chart.yaml
|_values.yamlEnvironment Variables (env):
Specifies environment variables used throughout the taskfile, such as the base directory, releases directory, output directory, values file, template file, and a custom flag.
Tasks (tasks):
Defines a task named generate_and_sync responsible for generating and syncing files.
- Task Description (
desc):
- Provides a brief description of the task.
2. Silent Execution (silent):
- Indicates that the task should execute silently without displaying output.
3. Commands (cmds):
- Lists a series of shell commands to be executed sequentially as part of the task.
3.1 Check ytt Installation:
- Ensures that the
ytttool is installed; if not, it displays an error message and exits.
3.2 Check vendir Installation:
- Ensures that the
vendirtool is installed; if not, it displays an error message and exits.
3.3 Generate YAML with ytt:
- Invokes
yttto generate YAML files based on the specified template and values files, storing the output in the specified directory.
3.4 Check Output Directory Existence:
- Verifies if the output directory exists; if not, it displays an error message and exits.
3.5 Sync with vendir:
- Uses
vendirto sync the generated files, referencing the vendir configuration file within the output directory.
3.6 Clean Up Output Directory:
- Removes the temporary output directory to clean up after the synchronization.
This taskfile streamlines the process of generating and syncing files using ytt and vendir, incorporating checks for tool installations and handling errors gracefully. The task generate_and_sync encapsulates a series of commands to ensure a smooth workflow.
Section 6: Additional Tips and Best Practices 🚀
As you venture deeper into the jungle of YTT, imagine the Tatooine of the Kubernetes galaxy, where configurations are like exotic creatures waiting to be discovered. Much like a Jedi exploring a new planet, I recommend you visit the YTT Playground — the Tatooine of YTT, where you can wield your lightsaber and experiment with the Force of templating. This interactive playground is your gateway to unlocking the secrets of YTT, allowing you to navigate the dense YTT jungle with ease. Harness the Force of templating, sculpt your configurations, and unveil the mysteries hidden within the YAML realms.
Conclusion: A Galactic Mastery Unveiled 🌌
As our journey through the Kubernetes galaxy concludes, remember that YTT and Vendir are your lightsabers and droids in the cosmic jungle of configurations. Explore the Tatooine of YTT in the playground, wield the Force, and master the art of YAML. May your Kubernetes adventures be epic, and may the Force be with your deployments always. 🚀🌠✨
Till next part where we will deep dive into YTT and Kubernetes configuration and deploy them into our cluster based on customers needs.
Connect with me on LinkedIn: ebenamor
Github: Profile






