When building applications with KOTS and Helm, you may need to allow users to provide raw YAML configuration data such as arbitrary key-value pairs for labels, annotations, or environment variables. This article demonstrates how to use the textarea
config type in KOTS to achieve this functionality.
Basic Implementation
Step 1: Define the Config Schema
Use the textarea
type in your KOTS config to accept raw YAML input:
apiVersion: kots.io/v1beta1
kind: Config
metadata:
name: my-app-config
spec:
groups:
- name: extra_config
title: Extra Configuration
description: Extra settings
items:
- name: podAnnotations
title: Pod Annotations
type: textarea
Step 2: Reference Config in HelmChart Resource
Pass the configuration to your Helm chart using template functions:
apiVersion: kots.io/v1beta2
kind: HelmChart
metadata:
name: my-chart
spec:
chart:
name: my-chart
chartVersion: 0.1.0
values:
podAnnotations: repl{{ ConfigOption "podAnnotations" | nindent 8 }}
Step 3: Use Values in Helm Templates
In your Helm template, consume the values with proper YAML handling:
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
Base64 Encoding for Safety
For complex configurations or when indentation safety is a concern, you can require users to provide base64-encoded values:
HelmChart with Base64 Decoding
apiVersion: kots.io/v1beta2
kind: HelmChart
metadata:
name: my-chart
spec:
chart:
name: my-chart
chartVersion: 0.1.0
values:
complexConfig: repl{{ ConfigOption "complexConfig" | Base64Decode | nindent 8 }}
Additional Resources
For passing arbitrary Helm values, see: How can I add the ability to provide arbitrary Helm values using the KOTS config?
For more other configuration patterns and examples, check out the platform-examples repository which demonstrates different configuration scenarios and best practices.