Helm Deployment

Learn how to prepare a Helm chart for the deployment of a Vehicle App in a Kubernetes cluster.

This tutorial will show you how to:

  • Prepare a Helm chart.
  • Deploy your Vehicle App to a local K3D cluster.

Prerequisites

Use the sample Helm chart

If the Vehicle App has been created from one of our template repositories, a sample Helm chart is already available inside our maintained runtime-k3d of the devenv-runtimes package at ./runtime-k3d/src/app_deployment/config/helm/ and can be used as it is without any modification. This sample chart is using the values from ./runtime-k3d/src/app_deployment/config/helm/values.yaml file.

Prepare a new Helm chart

If you would like to write a new helm chart, this section will guide you to adapt and deploy a new Vehicle App, which is called my_vehicle_app for this walkthrough.

  1. Start Visual Studio Code and open the previously created Vehicle App repository.

  2. Create a new folder my_vehicle_app under deploy

  3. Copy all files from the devenv-runtimes/runtime-k3d/src/app_deployment/config/helm folder to the new folder deploy/my_vehicle_app.

  4. Rename the file deploy/my_vehicle_app/helm/templates/vehicleapp.yaml to deploy/my_vehicle_app/helm/templates/my_vehicle_app.yaml

  5. Open deploy/my_vehicle_app/helm/Chart.yaml and change the name of the chart to my_vehicle_app and provide a meaningful description.

    apiVersion: v2
    name: my-vehicle-app
    description: Short description for my-vehicle-app
    
    # A chart can be either an 'application' or a 'library' chart.
    #
    # Application charts are a collection of templates that can be packaged into versioned archives
    # to be deployed.
    #
    # Library charts provide useful utilities or functions for the chart developer. They're included as
    # a dependency of application charts to inject those utilities and functions into the rendering
    # pipeline. Library charts do not define any templates and cannot be deployed as a result.
    type: application
    
    # This is the chart version. This version number should be incremented each time you make changes
    # to the chart and its templates, including the app version.
    # Versions are expected to follow Semantic Versioning (https://semver.org/)
    version: 0.1.0
    
    # This is the version number of the application being deployed. This version number should be
    # incremented each time you make changes to the application. Versions are not expected to
    # follow Semantic Versioning. They should reflect the version the application is using.
    appVersion: 1.16.0
    
  6. Open deploy/my_vehicle_app/helm/values.yaml and change name, repository and daprAppid to my-vehicle-app. Rename the root node from imageVehicleApp to imageMyVehicleApp.

    imageMyVehicleApp:
      name: my-vehicle-app
      repository: k3d-registry.localhost:12345/my-vehicle-app
      pullPolicy: Always
      # Overrides the image tag whose default is the chart appVersion.
      tag: "#SuccessfulExecutionOfReleaseWorkflowUpdatesThisValueToReleaseVersionWithoutV#"
      daprAppid: my-vehicle-app
      daprPort: 50008
    
      nameOverride: ""
      fullnameOverride: ""
    
  7. Open deploy/my_vehicle_app/helm/templates/my_vehicle_app.yaml and replace imageVehicleApp with imageMyVehicleApp:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: {{.Values.imageMyVehicleApp.name}}
    labels:
        app: {{.Values.imageMyVehicleApp.name}}
    spec:
    selector:
        matchLabels:
        app: {{.Values.imageMyVehicleApp.name}}
    template:
        metadata:
        annotations:
            dapr.io/enabled: "true"
            dapr.io/app-id: "{{.Values.imageMyVehicleApp.daprAppid}}"
            dapr.io/app-port: "{{.Values.imageMyVehicleApp.daprPort}}"
            dapr.io/log-level: "debug"
            dapr.io/config: "config"
            dapr.io/app-protocol: "grpc"
        labels:
            app: {{.Values.imageMyVehicleApp.name}}
            {{- include "helm.selectorLabels" . | nindent 8 }}
        spec:
        containers:
            - name: {{.Values.imageMyVehicleApp.name}}
            image: "{{ .Values.imageMyVehicleApp.repository }}:{{ .Values.imageMyVehicleApp.tag | default .Chart.AppVersion }}"
            imagePullPolicy: {{ .Values.imageMyVehicleApp.pullPolicy }}
    

At this point, the Helm chart is prepared for the next step and the folder structure under deploy/my_vehicle_app should look like this:

deploy
├── my_vehicle_app
│   └── helm
│       └── templates
│           └── _helpers.tpl
│           └── my_vehicle_app.yaml
│────────── .helmignore
│────────── Chart.yaml
└────────── values.yaml

Deploy your Vehicle App to the local K3D cluster

Prerequisites

  • A local K3D installation must be available. For how to setup K3D, check out this tutorial .

After the Helm chart has been prepared, you can deploy it to the local K3D cluster by following the steps:

  1. Building and pushing the Docker image for your Vehicle App
DOCKER_BUILDKIT=1 docker build -f ./app/Dockerfile --progress=plain -t localhost:12345/my-vehicle-app:local . --no-cache

docker push localhost:12345/my-vehicle-app:local
  1. Installing the Helm Chart
helm install my-vapp-chart ./deploy/my_vehicle_app --values ./deploy/my_vehicle_app/values.yaml --wait --timeout 60s

These steps are building the local source code of the application into a container, pushing it to the local cluster registry and deploying the app via a helm chart to the K3D cluster. Rerun the steps after you have changed the source code of your application to re-deploy with the latest changes.

If you have issues installing the helm chart again try uninstalling the chart upfront:

helm uninstall my-vapp-chart

Next steps