title | sidebar_position |
---|---|
Deploying an Echo-Server as OCM Component |
3 |
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 here, and uploaded in an OCI registry,
- a Helm chart which you can also find here and uploaded in an OCI registry,
- the Docker image hashicorp/http-echo as an external resource.
All of these resources are bundled in a component. The component's configuration file is shown here.
Describing required resources in a standard format (for which we use the "Open Component Model") has several advantages. This Guided Tour can not go into all the details about that model, so you might want to read about the core concepts, the benefits and the available tools on the official website under https://ocm.software.
Without a consistent description for your component and its technical resources, you would have to search images spread somewhere in charts, perhaps even mixed with some templating. Moreover, such standardized components can be used by other tools to perform other lifecycle management activities like consistent transports into other environments or to do signing/verification of software components.
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. In detail, the connection is the following:
-
The component contains a resource with name
echo-server-image
and a reference to the actual image:resources: - name: echo-server-image type: ociImage version: v0.2.3 access: type: ociArtifact 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 template of the chart takes the image from the Helm values:
containers: - image: {{ .Values.image }}
NOTE: Since Kubernetes does not support OCM (yet ;) ), we need the oci reference of the container image, here. Consequently, to actually use this component with landscaper, the container image that has to be deployed in a pod cannot be embedded into the component as a local blob (though it make sense to do so, as an intermediate step during transport of the component).
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.