Creating a Zarf Package
In this tutorial, we will demonstrate the process to create a Zarf package for an application from defining a zarf.yaml
, finding resources with zarf dev
commands and finally building the package with zarf package create
.
When creating a Zarf package, you must have a network connection so that Zarf can fetch all of the dependencies and resources necessary to build the package. If your package is using images from a private registry or is referencing repositories in a private repository, you will need to have your credentials configured on your machine for Zarf to be able to fetch the resources.
- You’ll need an internet connection so Zarf can pull in anything required to build the package in this tutorial.
Before beginning this tutorial you will need the following:
- Zarf binary installed on your $PATH: (Installing Zarf)
- A text editor or development environment such as VSCode
In order to create a Zarf package you first need to have an idea of what application(s) you want to package. In this example we will be using the WordPress chart from Bitnami but the steps and tools used below are very similar for other applications.
A zarf.yaml
file follows the Zarf Package Schema and allows us to specify package metadata and a set of components for us to deploy. We start a package definition with the kind
of package we are making and metadata
that describes the package. You can start our WordPress package by creating a new zarf.yaml
with the following content:
Components are the unit of Zarf Packages that define an application stack. These are defined under the components
key and allow many different resource types to be brought into a package. You can learn more about components on the Understanding Zarf Components page. To add our WordPress component, add the following to the bottom of our zarf.yaml
:
In addition to this component definition, we also need to create the valuesFiles
we have specified. In this case we need to create a file named wordpress-values.yaml
in the same directory as our zarf.yaml
with the following contents:
Once you have the above defined we can now work on setting the images that we will need to bring with us into the air gap. For this, Zarf has a helper command you can run with zarf dev find-images
. Running this command in the directory of your zarf.yaml will result in the following output:
From here you can copy the images
key and array of images into the wordpress
component we defined in our zarf.yaml
We now have a deployable package definition, but it is currently not very configurable and might not fit every environment we want to deploy it to. If we deployed it as-is we would always have a Zarf Blog and a zarf
user with an autogenerated password.
To resolve this, we can add configuration options with Zarf Variables. For this package we will add a variables
section to our zarf.yaml
above components
that will allow us to setup the user and the blog.
To use these variables in our chart we must add their corresponding templates to our wordpress-values.yaml
file. Zarf can template chart values, manifests, included text files and more.
As-is, our package could be configured to interface with an ingress provider to provide access to our blog, but this may not be desired for every service, particularly those that provide a backend for other frontend services. To help with debugging, Zarf allows you to specify Zarf Connect Services that will be displayed after package deployment to quickly connect into our deployed application.
For this package we will define two services, one for the blog and the other for the admin panel. These are normal Kubernetes services with special labels and annotations that Zarf watches out for, and to defined them create a connect-services.yaml
with the following contents:
To add this to our zarf.yaml
we can simply specify it under our wordpress
component using the manifests
key:
Once you have followed the above you should now have a zarf.yaml
file that matches the one found on the WordPress example page.
Creating this package is as simple as running the zarf package create
command with the directory containing our zarf.yaml
. Zarf will show us the zarf.yaml
one last time asking if we would like to build the package, and upon confirmation Zarf will pull down all of the resources and bundle them into a package tarball.
When you execute the zarf package create
command, Zarf will prompt you to confirm that you want to create the package by displaying the package definition and asking you to respond with either y
or n
.
This will create a zarf package in the current directory with a package name that looks something like zarf-package-wordpress-amd64-16.0.4.tar.zst
, although it might be slightly different depending on your system architecture.
Congratulations! You’ve built the WordPress package. Now, you can learn how to inspect the SBOMs or head straight to deploying it!