CREATING ZARF PACKAGES

CREATING ZARF PACKAGES

CREATING ZARF PACKAGES

HC

By Rob

August 28th, 2023

FOREWORD

FOREWORD

FOREWORD

FOREWORD

Zarf packages are growing in popularity as they offer an efficient and secure method of deploying applications on air-gapped environments. But creating one can seem like a daunting task for those new to the concept. So, let’s break it down and walk through the process of creating a Zarf package step-by-step.


Want to learn more right away?

Check out the Zarf docs.

Zarf packages are growing in popularity as they offer an efficient and secure method of deploying applications on air-gapped environments. But creating one can seem like a daunting task for those new to the concept. So, let’s break it down and walk through the process of creating a Zarf package step-by-step.


Want to learn more right away?

Check out the Zarf docs.

Zarf packages are growing in popularity as they offer an efficient and secure method of deploying applications on air-gapped environments. But creating one can seem like a daunting task for those new to the concept. So, let’s break it down and walk through the process of creating a Zarf package step-by-step.


Want to learn more right away?

Check out the Zarf docs.

Zarf packages are growing in popularity as they offer an efficient and secure method of deploying applications on air-gapped environments. But creating one can seem like a daunting task for those new to the concept. So, let’s break it down and walk through the process of creating a Zarf package step-by-step.


Want to learn more right away?

Check out the Zarf docs.

GRASPING ZARF

GRASPING ZARF

GRASPING ZARF

GRASPING ZARF

Before diving into the creation process, let’s understand what Zarf is.Zarf is a deployment tool designed for use in “air-gapped” or offline environments.It allows you to package software, configuration files, deployment scripts, and all other necessary components into one package.This Zarf package can then be moved onto your air-gapped system for deployment.

Before diving into the creation process, let’s understand what Zarf is.Zarf is a deployment tool designed for use in “air-gapped” or offline environments.It allows you to package software, configuration files, deployment scripts, and all other necessary components into one package.This Zarf package can then be moved onto your air-gapped system for deployment.

Before diving into the creation process, let’s understand what Zarf is.Zarf is a deployment tool designed for use in “air-gapped” or offline environments.It allows you to package software, configuration files, deployment scripts, and all other necessary components into one package.This Zarf package can then be moved onto your air-gapped system for deployment.

Before diving into the creation process, let’s understand what Zarf is.Zarf is a deployment tool designed for use in “air-gapped” or offline environments.It allows you to package software, configuration files, deployment scripts, and all other necessary components into one package.This Zarf package can then be moved onto your air-gapped system for deployment.

TOOLS

TOOLS

TOOLS

TOOLS

ZARF CLI

ZARF CLI

ZARF CLI

ZARF CLI

This is the command-line tool for creating and managing Zarf packages. It can be built from scratch or installed with Homebrew (macOS/Linux) read more here https://docs.zarf.dev/docs/the-zarf-cli/

This is the command-line tool for creating and managing Zarf packages. It can be built from scratch or installed with Homebrew (macOS/Linux) read more here https://docs.zarf.dev/docs/the-zarf-cli/

This is the command-line tool for creating and managing Zarf packages. It can be built from scratch or installed with Homebrew (macOS/Linux) read more here https://docs.zarf.dev/docs/the-zarf-cli/

This is the command-line tool for creating and managing Zarf packages. It can be built from scratch or installed with Homebrew (macOS/Linux) read more here https://docs.zarf.dev/docs/the-zarf-cli/

K3D

K3D

K3D

K3D

k3d allows us to run a very simple and yet powerful Kubernetes cluster on your local machine (although you could also run k3d on an EC2 instance or any supported machine)

k3d allows us to run a very simple and yet powerful Kubernetes cluster on your local machine (although you could also run k3d on an EC2 instance or any supported machine)

k3d allows us to run a very simple and yet powerful Kubernetes cluster on your local machine (although you could also run k3d on an EC2 instance or any supported machine)

Docker

Docker

Docker

Install Docker on your local machine here https://docs.docker.com/engine/install/

Install Docker on your local machine here https://docs.docker.com/engine/install/

Your app

Your app

Your app

You could use your own application, but to make things simple, we’ll be using the podinfo application

You could use your own application, but to make things simple, we’ll be using the podinfo application

Yaml file

Yaml file

Yaml file

You will also need a zarf.yaml file at the root of the directory. This acts as the blueprint for your package and also dictates what goes into your package and how it should be configured

You will also need a zarf.yaml file at the root of the directory. This acts as the blueprint for your package and also dictates what goes into your package and how it should be configured

Kubectl

Kubectl

This is the command line interface that allows you to interact with your k8s cluster

This is the command line interface that allows you to interact with your k8s cluster

SETUP

SETUP

SETUP

Firstly, lets begin by creating our local k8s cluster with k3d. Although Zarf does have a component that lets you setup k3s automatically, I prefer to have k3d installed primarly, just to make things a little easier to understand. Go ahead and install k3d with the following command (which is found on https://k3d.io)

Firstly, lets begin by creating our local k8s cluster with k3d. Although Zarf does have a component that lets you setup k3s automatically, I prefer to have k3d installed primarly, just to make things a little easier to understand. Go ahead and install k3d with the following command (which is found on https://k3d.io)

wget -q -O — [https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh](https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh) | bash

Once you have k3d installed, lets create our cluster on our local machine. Optionally, if you would like to setup k3d on a remote machine and access it from your local you can set SERVER_IP="" prior to running your k3d cluster create command:

Once you have k3d installed, lets create our cluster on our local machine. Optionally, if you would like to setup k3d on a remote machine and access it from your local you can set SERVER_IP="" prior to running your k3d cluster create command:

IMAGE_CACHE=${HOME}/.k3d-container-image-cache
mkdir -p ${IMAGE_CACHE}

After setting the IMAGE_CACHE, you can begin by creating your local k8s cluster with the following command.

After setting the IMAGE_CACHE, you can begin by creating your local k8s cluster with the following command.

k3d cluster create \
 — k3s-arg “ — tls-san=$SERVER_IP@server:0” \
 — volume /etc/machine-id:/etc/machine-id \
 — volume ${IMAGE_CACHE}:/var/lib/rancher/k3s/agent/containerd/io.containerd.content.v1.content \
 — k3s-arg “ — disable=traefik@server:0” \
 — port 80:80@loadbalancer \
 — port 443:443@loadbalancer \
 — api-port 6443

After setting the IMAGE_CACHE, you can begin by creating your local k8s cluster with the following command.

After setting the IMAGE_CACHE, you can begin by creating your local k8s cluster with the following command.

STEP BY STEP ZARF

STEP BY STEP ZARF

STEP BY STEP ZARF

If you haven’t done so, you’ll need to clone podinfo. Let’s navigate to our podinfo directory that we cloned from github, and then we can begin working on the zarf package.

If you haven’t done so, you’ll need to clone podinfo. Let’s navigate to our podinfo directory that we cloned from github, and then we can begin working on the zarf package.

ZARF INIT

ZARF INIT

ZARF INIT

We must initiate Zarf onto the Kubernetes(k8s) cluster that we have created. You can decline to use K3S, Gitea and Logging components by pressing the N key when prompted. Since we already have k3d we do not need the k3s component (Zarf will spin up a k3d cluster for you if this option is selected).

We must initiate Zarf onto the Kubernetes(k8s) cluster that we have created. You can decline to use K3S, Gitea and Logging components by pressing the N key when prompted. Since we already have k3d we do not need the k3s component (Zarf will spin up a k3d cluster for you if this option is selected).

PODINFO

PODINFO

Podinfo is a simple test application written in Go that can be used in an k8s environment. It gives us info about a Kubernetes pod that is running. By the end of the tutorial you'll be able to check the following items within an Air-gapped environment:

Podinfo is a simple test application written in Go that can be used in an k8s environment. It gives us info about a Kubernetes pod that is running. By the end of the tutorial you'll be able to check the following items within an Air-gapped environment:

/: Displays a simple homepage
/version: Displays the version of podinfo that's running
/env: Shows all environment variables
/headers: Shows HTTP request headers
/metrics: Provides Prometheus-compatible metrics
/healthz: Can be used for Kubernetes liveness probes
/readyz: Can be used for Kubernetes readiness probes

ZARF PACKAGE

ZARF PACKAGE

Lets create a new zarf.yaml in the root of the podinfo directory. We can define it as displayed in the example below:

Lets create a new zarf.yaml in the root of the podinfo directory. We can define it as displayed in the example below:

kind: ZarfPackageConfig
metadata:
  name: podinfo
  description: "Deploys podinfo from git repo"
  architecture: amd64

components:
  - name: podinfo
    required: true
    charts:
      - name: podinfo
        url: https://github.com/stefanprodan/podinfo.git
        gitPath: charts/podinfo
        namespace: podinfo
        version: 6.3.5
    images:
      - "ghcr.io/stefanprodan/podinfo:6.3.5"

BREAKDOWN

BREAKDOWN

We define our Zarf package with the ZarfPackageConfig:

We define our Zarf package with the ZarfPackageConfig:

kind: ZarfPackageConfig
metadata:
  name: podinfo
  description: "Deploys podinfo from git repo"
  architecture: amd64

We then create the component, which is the podinfo app and specify the github repository where it is hosted, as well as the location of the podinfo image. Zarf is designed to make deploying applications in an Airgapped environment super easy. A Zarf package will package up everything required for podinfo to work.

We then create the component, which is the podinfo app and specify the github repository where it is hosted, as well as the location of the podinfo image. Zarf is designed to make deploying applications in an Airgapped environment super easy. A Zarf package will package up everything required for podinfo to work.

CREATING A ZARF PACKAGE

CREATING A ZARF PACKAGE

If you are running on macOS with the M1 chip, you can specify arm64 as the architecture, otherwise amd64 will work just fine on Linux or ubuntu. Now that you have defined your zarf.yaml in the root of podinfo directory, we can create our zarf package with the following command:

If you are running on macOS with the M1 chip, you can specify arm64 as the architecture, otherwise amd64 will work just fine on Linux or ubuntu. Now that you have defined your zarf.yaml in the root of podinfo directory, we can create our zarf package with the following command:

zarf package create --confirm

Which will create and produce your Zarf package with the name zarf-package-podinfo-amd64.tar.zst. We can now get started deploying our Zarf package.

Which will create and produce your Zarf package with the name zarf-package-podinfo-amd64.tar.zst. We can now get started deploying our Zarf package.

DEPLOYING A ZARF PACKAGE

DEPLOYING A ZARF PACKAGE

Assuming all has been successfully completed, lets deploy our podinfo zarf package. Run the following command:

Assuming all has been successfully completed, lets deploy our podinfo zarf package. Run the following command:

zarf package deploy zarf-package-podinfo-amd64.tar.zst

You'll be prompted if you would like to deploy the package... well what are you waiting for? Follow the command prompt and press Y key to deploy.

Keep an extra terminal open and watch the magic happen by executing this command:

You'll be prompted if you would like to deploy the package... well what are you waiting for? Follow the command prompt and press Y key to deploy.

Keep an extra terminal open and watch the magic happen by executing this command:

watch kubectl get pods -A

The final product in k9s:

The final product in k9s:

CONCLUSION

CONCLUSION

Finally, to view the podinfo frontend, we can forward the port with zarf connect podinfo or kubectl port-forward svc/podinfo -n podinfo 9898:http and navigate to http://localhost:9898/ to see what podinfo is doing.


So there you have it, you can see the power of Zarf and how easy it can be to deploy your applications into an Air-gapped environment with minimal configuration time. For further reading, check out the Zarf docs to get a more in-depth understanding of Zarf and Zarf packages.


Until next time!

Finally, to view the podinfo frontend, we can forward the port with zarf connect podinfo or kubectl port-forward svc/podinfo -n podinfo 9898:http and navigate to http://localhost:9898/ to see what podinfo is doing.


So there you have it, you can see the power of Zarf and how easy it can be to deploy your applications into an Air-gapped environment with minimal configuration time. For further reading, check out the Zarf docs to get a more in-depth understanding of Zarf and Zarf packages.


Until next time!

^_^

What is robmcelvenny.com

robmcelvenny.com is a simple website for other software engineers alike. Eventually I hope to post much more professionally developed content.

Why subscribe?

Why subscribe?

Subscribing means you never miss out on my fun and boring journeys.

© 2023 robmcelvenny.com.