Skip to content

Latest commit

 

History

History
109 lines (80 loc) · 4.79 KB

File metadata and controls

109 lines (80 loc) · 4.79 KB
title sidebar_position
Deploying an Echo-Server as OCM Component
3

Echo Server Example

In this example, we use the Landscaper to deploy an echo server.

For prerequisites, see here.

The example uses the following resources:

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.

OCI Image Resource in the Component

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 section values for the Helm values. During the templating, we read the entry echo-server-image of the component descriptor, extract the field access.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 its values 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).

Procedure

The procedure to install the helm chart with Landscaper is as follows:

  1. Add the kubeconfig of your target cluster to your target.yaml.

  2. 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>
  3. 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.