env.yaml


Overview

env.yaml is a Kubernetes Secret manifest template designed for use within a Helm chart deployment. Its primary purpose is to centralize and securely manage environment variables for the Ragflow application pods. This file dynamically generates secret data based on Helm values, ensuring that each pod receives the necessary configuration and sensitive credentials, such as passwords and host connection details, without exposing them in plain text.

The template selectively includes environment variables, validates required secrets, and configures service connection endpoints using Kubernetes internal DNS conventions. It also enforces configuration correctness by failing the Helm release if mandatory environment variables are missing or misconfigured.


Detailed Explanation

File Type


Key Sections and Logic

Metadata

metadata:
  name: {{ include "ragflow.fullname" . }}-env-config

Secret Type

type: Opaque

stringData Field

This field holds key-value pairs representing environment variables as strings. Kubernetes converts these automatically into base64-encoded data.

stringData:
  {{- range $key, $val := .Values.env }}
  {{- if $val }}
  {{ $key }}: {{ quote $val }}
  {{- end }}
  {{- end }}

Cluster Service Hostnames

REDIS_HOST: {{ printf "%s-redis.%s.svc" (include "ragflow.fullname" .) .Release.Namespace }}
MYSQL_HOST: {{ printf "%s-mysql.%s.svc" (include "ragflow.fullname" .) .Release.Namespace }}
MINIO_HOST: {{ printf "%s-minio.%s.svc" (include "ragflow.fullname" .) .Release.Namespace }}

Required Password Validation

REDIS_PASSWORD: {{ .Values.env.REDIS_PASSWORD | required "REDIS_PASSWORD is required" }}

Special Handling for MySQL Passwords

{{- with .Values.env.MYSQL_PASSWORD | required "MYSQL_PASSWORD is required" }}
MYSQL_PASSWORD: {{ . }}
MYSQL_ROOT_PASSWORD: {{ . }}
{{- end }}

Special Handling for MinIO Passwords

{{- with .Values.env.MINIO_PASSWORD | required "MINIO_PASSWORD is required" }}
MINIO_PASSWORD: {{ . }}
MINIO_ROOT_PASSWORD: {{ . }}
{{- end }}

Doc Engine Specific Environment Variables

{{- if eq .Values.env.DOC_ENGINE "elasticsearch" }}
ES_HOST: {{ ... }}
ELASTIC_PASSWORD: {{ required "ELASTIC_PASSWORD is required" }}
{{- else if eq .Values.env.DOC_ENGINE "infinity" }}
INFINITY_HOST: {{ ... }}
{{- else if eq .Values.env.DOC_ENGINE "opensearch" }}
OS_HOST: {{ ... }}
OS_PORT: "9201"
OPENSEARCH_PASSWORD: {{ required "OPENSEARCH_PASSWORD is required" }}
OPENSEARCH_INITIAL_ADMIN_PASSWORD: {{ required "OPENSEARCH_PASSWORD is required" }}
{{- else }}
{{ fail "env.DOC_ENGINE must be either 'elasticsearch', 'opensearch' or 'infinity'" }}
{{- end }}

Usage Example

Assuming you have a Helm values file values.yaml like:

env:
  REDIS_PASSWORD: "redis-secret"
  MYSQL_PASSWORD: "mysql-secret"
  MINIO_PASSWORD: "minio-secret"
  DOC_ENGINE: "elasticsearch"
  ELASTIC_PASSWORD: "elastic-secret"
  SOME_OTHER_VAR: "value"

During helm install or helm upgrade, this template will generate a Kubernetes Secret named <release-name>-env-config containing:

This secret can then be mounted or injected as environment variables into Ragflow pods.


Important Implementation Details


Interaction with Other System Components


Visual Diagram

flowchart TD
    A[Helm Values (.Values.env)] --> B[env.yaml Template]
    B --> C[Generate Kubernetes Secret]
    C --> D[Secret: <release>-env-config]
    D --> E[Ragflow Pods]
    E --> F{Use Environment Variables}
    F --> G[Connect to Redis Service]
    F --> H[Connect to MySQL Service]
    F --> I[Connect to MinIO Service]
    F --> J[Connect to Document Engine Service]
    subgraph DocEngine
        J --> K[Elasticsearch]
        J --> L[OpenSearch]
        J --> M[Infinity]
    end

Summary

env.yaml is a critical Helm template that consolidates environment variable secrets for the Ragflow application. It dynamically builds Kubernetes secrets with required credentials and service hostnames, enforces configuration correctness, and supports multiple document engines. Its design promotes secure, reliable, and flexible application configuration within Kubernetes. The TODO note indicates plans for future improvement by splitting secrets to enhance security.