Resolved

Environment variable naming inconsistency causes Azure OpenAI job failure

Kubernetes
Azure
OpenAI
Environment Variables
Debugging
DevOps

A Kubernetes job failed due to a mismatch between the environment variable name in the job configuration and the expected name in the script and secrets. The issue was resolved by aligning the naming conventions across all components.

Issue

A Kubernetes job responsible for indexing Bloomberg articles failed during startup due to an environment variable mismatch. The job crashed immediately with the error AZURE_OPENAI_API_KEY environment variable not set, despite the secret containing the correct key-value pair. This prevented the processing of Bloomberg articles and blocked the indexing pipeline.

Culprit

The issue stemmed from inconsistent naming across three components:

  1. Kubernetes Secret: Correctly stored the key as AZURE_OPENAI_API_KEY.
  2. Job YAML: Incorrectly referenced the environment variable as AZURE_OPENAI_KEY (missing the _API_ segment).
  3. Python Script: Correctly validated for AZURE_OPENAI_API_KEY.

This mismatch occurred because the job YAML was initially created with a shorter variable name, but the secret was later standardized to include _API_ for clarity. The script validation was updated to match the secret, but the job YAML was never updated to reflect this change.

Solution

Naming Alignment

Updated the job YAML to ensure consistency across all components:

  • Job Configuration: Changed the environment variable name from AZURE_OPENAI_KEY to AZURE_OPENAI_API_KEY to match the secret and script.
  • Security: No secret values were exposed or modified; only the reference name was corrected.

Prevention Measures

  1. Standardized Naming: Added standardized environment variable names to a reference file (e.g., .env.example) to ensure consistency.
  2. Validation Checklist: Created a checklist for new secrets to ensure that the secret key name, deployment/Job environment variable name, and code references all match exactly.

Technical Impact

  • Validation: The script’s environment variable validation now receives the expected value.
  • Compatibility: The change maintains backward compatibility with existing secret structures.

This fix resolved the job failure and ensured that all components use consistent environment variable naming conventions.