Skip to content

Environment Variable Missing

Error message

                Error: Required environment variable DATABASE_URL is not set
              

Quick summary

A required environment variable is missing, causing the application to crash or malfunction on startup.

Why this happens

  • The environment variable was not set in the container spec or ConfigMap

  • The variable name is misspelled (case-sensitive)

  • The wrong ConfigMap or Secret is referenced in the Pod spec

  • The variable is set in one environment but not in another (dev vs prod)

Minimal example

✗ Broken code
spec:
  containers:
    - name: app
      image: myapp
      # Missing DATABASE_URL env var
✓ Fixed code
spec:
  containers:
    - name: app
      image: myapp
      env:
        - name: DATABASE_URL
          valueFrom:
            secretKeyRef:
              name: db-secret
              key: url

The broken code is missing the DATABASE_URL variable. The fix adds it, pulling the value from a Secret.

How to diagnose

  • Check the error message for the specific variable name

  • Inspect the Pod's environment: kubectl exec <pod> -- env | grep <VAR>

  • Verify the Pod spec, ConfigMap, and Secret references

  • Check if the variable is defined in the deployment YAML

How to fix

  • Add the missing environment variable to the container spec

  • Create a ConfigMap or Secret with the required value and reference it

  • Correct the variable name spelling (environment variables are case-sensitive)

  • Ensure the variable is set in all environments (dev, staging, prod)

How to prevent

  • Document all required environment variables

  • Use ConfigMaps and Secrets to manage environment-specific values

  • Validate that all required variables are set in CI before deploying

Related Resources

Related Glossary

← Back to language