Let’s illustrate a very simple “Hello World” example application and show how to leverage OCM to build an application component containing a Helm Chart and an OCI Image and deploy it to a local kind k8s cluster.
The topics ocmlocalization and configuration are NOT part of this very simple example, but is covered in other tutorials.
As base we use the podinfo application from Stefan Prodan’s Github repo.
All files can be found here.
At the end of the tutorial you will have created one OCM component for your business application podinfo.
This component will be composed using the OCM guidelines and consist of multiple resources, alongside an OCI image and a Helm chart.
For building multiple components in one shot the “all-in-one” mechanism becomes handy.
First we build an OCM component which contains Helm Charts in different kind of formats. This 101 guide explains all possible formats a HelmChart resource can have in OCM, but in reality you’ll just pick the one most appropriate to you.
We are leveraging Kubernetes deployments which often use Helm charts. The OCM specification supports Helm charts as artifact type. For this simple example, we will re-use existing open source community Helm charts.
The OCM CLI supports referencing Helm charts stored in an OCI registry or Helm chart repositories, as well as local archives or folders. The preferred option is to store Helm charts in an OCI registry or Helm repository, as this allows for easy sharing and versioning of the Helm charts.
Helm charts can be embedded in the component archive in four different ways:
referenced in OCI registry
referenced in Helm repository
as local *.tgz file
as local folder containing a Helm Chart file
To demonstrate No. 3. and 4. we need a Helm chart on our local machine. For the sake of the this simplified guide, we download and unpack an already existing open source Helm chart for podinfo. In a real world application, this would be your own Helm chart. You will most likely store your own Helm charts within a git repository and leverage a CI/CD pipeline to build *.tgz Helm chart files in order to push them to your OCI registry or Helm repository.
Downloading Helm charts can easily be achieved using the Helm CLI:
For the podinfo example:
The Helm chart is then stored in the current working directory as podinfo-6.7.0.tgz and can be referenced as path from there in the component-constructor.yaml file (see below).
Unpack podinfo-6.7.0.tgz to simulate the process as if this helm chart is our own and not downloaded from a public repository:
The corresponding input file for building our component version (component-constructor.yaml) looks like:
Some frequently changing parameters have been extracted as variables. The OCM CLI uses
templating to fill them with values. The templating mechanism is described
here. For this example
we use the default template engine type subst.
Note the differences between the various components:
From the input file component-constructor.yaml the common transport archive can be created with the
OCM CLI. We need to provide values for all variables, which can be passed in the
command line or stored in a file. For many variables, having a values file is more convenient.
The corresponding file settings.yaml may look like this:
Create the transport archive with the following commands:
You can view all component versions in a transport archive using the command:
You can store the transport archive in an OCI registry (this step needs a proper
configuration of credentials for the OCM CLI):
Using the --copy-resources flag the OCM CLI will copy also copy all referenced resources to the OCI registry, making the resources part of the OCM component version, creating a self-contained component version.
Note: Be careful with the -f or --overwrite flag. This will replace existing component
versions in the OCI registry. During development it is useful being able to overwrite
existing component versions until something is ready for release.
For released versions you should never use this flag!
Released component versions should be immutable and
should never be overwritten. They serve as source of truth for what the release is made of
and should never be changed.
By this step we have created a transport archive containing all required parts (images and Helm charts) for
installing the application. This archive is self-contained and can be transferred to an OCI registry with a single
command from the OCM tooling. After pushing this archive to an OCI registry we have a shared location
that can be used as a source of deployment without any external references. As an alternative, you can
transport the archive using offline mechanisms (file transfer, USB-stick) and push it on a target
location in an OCI registry.
To actually deploy the application we need to get access to the Helm charts contained in the archive.
We can use the OCM CLI to retrieve their location. See the example below.
Let’s assume that we have pushed the transport archive to an OCI registry. We need the identity of the
component version and the location of the component-descriptors in the OCI registry: