In this example, we use the Landscaper to deploy an echo server.
For prerequisites, see here.
The example uses the following resources:
- a blueprint, which you can find locally, and uploaded in an OCI registry,
- a Helm chart which you can also find locally and uploaded in an OCI registry,
- the Docker image hashicorp/http-echo as an external resource.
All these resources are listed in the component descriptor. It is an advantage to have them all in one place, in a standard format. Otherwise, you would have to search images spread somewhere in charts, perhaps even mixed with some templating. Moreover, the component descriptor can be used by other tools for example for transport or signing.
The echo-server Helm chart in this example consists of a Deployment
and a Service
.
The Deployment
uses a container image. However, instead of a hard-coded image reference in
the deployment.yaml, we rather maintain the image reference in the
component descriptor. In detail, the connection is the following:
-
The component descriptor contains a resource with name
echo-server-image
and a reference to the actual image:name: echo-server-image type: ociImage version: v0.2.3 relation: external access: type: ociRegistry imageReference: hashicorp/http-echo:0.2.3
-
The blueprint contains a template for a
DeployItem
. Part of this is a sectionvalues
for the Helm values. During the templating, we read the entryecho-server-image
of the component descriptor, extract the fieldaccess.imageReference
, and write it into the section with Helm values:values: {{ $imageResource := getResource .cd "name" "echo-server-image" }} image: {{ $imageResource.access.imageReference }}
After the templating, the resulting
DeployItem
contains the image reference in itsvalues
section:values: image: hashicorp/http-echo:0.2.3
-
Finally, the deployment.yaml of the chart takes the image from the Helm values:
containers: - image: {{ .Values.image }}
The procedure to install the helm chart with Landscaper is as follows:
-
Add the kubeconfig of your target cluster to your target.yaml.
-
On the Landscaper resource cluster, create namespace
example
and apply the context.yaml, the target.yaml, and the installation.yaml:kubectl create ns example kubectl apply -f <path to context.yaml> kubectl apply -f <path to target.yaml> kubectl apply -f <path to installation.yaml>
-
To try out the echo server, first define a port forwarding on the target cluster:
kubectl port-forward -n example service/echo-server 8080:80
Then open
localhost:8080
in a browser.The response should be "hello world", which is the text defined in the values.yaml of the chart.