Carvel Tools Introduction – Part 1 – [ ytt ]

Carvel is an open source suite of tools. Carvel provides a set of reliable, single-purpose, composable tools that aid in your application building, configuration, and deployment to Kubernetes. Carvel was earlier known as k14s and renamed later on. This is an alternative to Helm but more powerful than it.

Carvel tools are not tied with VMware Tanzu Kubernetes Cluster only and they work same with other types of k8s clusters. However, with the Tanzu Kubernetes cluster, kapp-controller is pre-installed and hence you can quickly start using it else you need to install kapp-controller manually on the k9s cluster.

If you are looking for quick intro video of Carvel tools, here is the one https://www.youtube.com/watch?v=LBCmMTofNxw

Currently Carvel contains the following single-purpose tools:

  • ytt
  • kbld
  • kapp
  • imgpkg
  • kapp-controller
  • vendir

In this post, we will talk about ytt in detail with few examples and other tools will be covered in the upcoming parts.

ytt Introduction

ytt is one of the tool under Carvel too set as you can see in the below screenshot too.

ytt is a command-line tool used to template and patch YAML files. It also provides the means to collect fragments and piles of YAML into modular chunks for easy re-use.

A plain YAML file is turned into a ytt template by adding specially formatted comments, that is: annotating. Through these annotations, one can inject input values, logic like conditionals and looping, and perform transformations on the content.

Those “input values” are called “Data Values” in ytt. Such inputs are included in a separate file.

ytt can also be used to patch YAML files. These edits are called “Overlays” and are themselves written in YAML.

ytt Installation

Installation of ytt is very simple and straight forward. Since Carvel follows unix philosophy, so they get installed as one of the utility as you can see below.

$ wget -O- https://carvel.dev/install.sh > install.sh

# Run the Install
$ sudo bash install.sh

$ ytt version                                 
ytt version 0.36.0

ytt Usage Example

Let’s look at a few basic examples of ytt usage. The way to introduce a variable in ytt is to:

  1. declare it as a “Data Value” by naming it in a schema file,
  2. reference it in templates, and
  3. configure it through Data Value inputs.

– You want to update the yaml file values during runtime for a load balancer IP in a service yaml.

So, here first let’s declare the data value.

Save the below yaml content in a “schema.yml” file.

#@data/values-schema
---
load_balancer:
  enabled: true
  external_ip: ""

declares three Data Values:

  • load_balancer is a map that contains two map items: enabled and external_ip.
  • load_balancer.enabled is a boolean; by default it is true.
  • load_balancer.external_ip is a string; by default it is an empty string.

Next is referencing the Data Values.

Those Data Values can then be used in a template via the @ytt:data module.

Save the below content in a “config.yml” file.

#@ load("@ytt:data", "data")
---
service: #@ data.values.load_balancer

Next is Configuring Data Values.

Further, those Data Values can be customised by a Consumer by providing their own data values:

Save the below content in a “values.yml” file.

#@data/values
---
load_balancer:
  external_ip: 192.168.1.10

You can change the IP address based on your environment, if needed.

Now, let’s execute the ytt command and see how it uses the external IP address and replace the correct IP address.

$ ytt -f schema.yml -f values.yml -f config.yml
service:
  load_balancer:
    enabled: true
    external_ip: 192.168.1.10

  • load_balancer.enabled is the default as set in schema.yml
  • load_balancer.external_ip is the configured value from values.yml

Above one was very simple example of ytt. You can refer below links to learn more about ytt.

Reference Links

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s