Externalizing Configuration with Etcd, HashiCorp Consul, and Spring Cloud Config in Python Flask Applications

Johan Louwers
4 min readOct 11, 2024
Find the config

In today’s dynamic cloud-native environments, maintaining a stateless architecture is crucial for scaling and agility. One of the pillars of statelessness is the externalization of configuration data. Storing configuration outside of the application deployment enables smooth updates, better management, and improved security. In this post, we will look at three powerful tools — Etcd, HashiCorp Consul, and Spring Cloud Config — which serve as external configuration stores for microservices, ensuring that configuration remains separate from the application itself.

Etcd

Etcd, a distributed, consistent key-value store, is designed to store configuration data and state for distributed systems. It is often the go-to choice in environments that require high availability and strong consistency, such as Kubernetes clusters. Its simple interface and strong consistency make it a perfect tool for externalizing application configuration.

from flask import Flask
import etcd3

app = Flask(__name__)

# Connect to Etcd
etcd = etcd3.client(host='configserver.internal.com', port=2379)

@app.route('/')
def get_config():
# Fetch a key-value from Etcd
config_value, _ = etcd.get('my_app/config')
return f'Config Value…

--

--

Johan Louwers

Johan Louwers is a technology enthousiasts with a long background in supporting enterprises and startups alike as CTO, Chief Enterprise Architect and developer.