Repository navigation
Detailed Setup
This page provides comprehensive setup instructions for deploying the microservice architecture template. Follow these steps to get your environment up and running.
First, set up your environment variables:
- Review and modify the
.envfile to customize your environment:
# Make a copy of the example .env file (if needed)
cp .env.example .env
# Edit the file with your preferred editor
nano .envThe following variables are important to review and adjust:
| Variable | Description | Default Value |
|---|---|---|
CONSUL_HTTP_PORT |
Consul UI and API port | 8500 |
CONSUL_DNS_PORT |
Consul DNS port | 8600 |
TRAEFIK_HTTP_PORT |
HTTP port | 80 |
TRAEFIK_HTTPS_PORT |
HTTPS port | 443 |
TRAEFIK_DASHBOARD_PORT |
Traefik dashboard port | 8080 |
VAULT_PORT |
Vault UI and API port | 8200 |
CONSUL_LOG_LEVEL |
Consul logging level | INFO |
TRAEFIK_LOG_LEVEL |
Traefik logging level | INFO |
VAULT_LOG_LEVEL |
Vault logging level | INFO |
For production environments, make the following changes:
- Generate a proper Consul encryption key (replace
CONSUL_ENCRYPT_KEY) - Set proper passwords and API keys
- Enable TLS (
TRAEFIK_TLS_ENABLED=true) - Disable insecure dashboard access (
TRAEFIK_DASHBOARD_INSECURE=false) - Set Vault to non-dev mode (
VAULT_DEV_MODE=false) - Enable Consul ACLs by uncommenting the ACL settings
Start the core services (Consul, Traefik, and Vault):
docker-compose up -dThis command starts:
- Consul server for service discovery and configuration
- Traefik as the API gateway and load balancer
- A helper container to register Traefik middleware configurations in Consul
- Vault for secret management
- Vault-init container to initialize and configure Vault
Check that all services are running properly:
docker-compose psAll services should show a status of Up or Up (healthy).
If you need to troubleshoot, check the logs:
# Check logs for all services
docker-compose logs
# Check logs for a specific service
docker-compose logs consul-server
docker-compose logs traefik
docker-compose logs vaultOnce the services are running, you can access their management dashboards:
- Consul Dashboard: http://localhost:8500
- Traefik Dashboard: http://localhost:8080
- Vault Dashboard: http://localhost:8200
To log in to Vault, you'll need the root token:
# Get the root token
cat ./vault/keys/root-token.txtUse this token to log in to the Vault UI or when using the Vault CLI.
To stop all services:
docker-compose downTo stop a specific service:
docker-compose stop <service-name>If you want to run without Vault, you have several options:
Edit the docker-compose.yaml file and comment out the Vault-related services:
services:
# Other services remain unchanged...
# Comment out Vault services
# vault:
# image: hashicorp/vault:1.16
# container_name: vault
# # ... rest of the configuration ...
# vault-init:
# image: hashicorp/vault:1.19
# container_name: vault-init
# # ... rest of the configuration ...Create a simplified docker-compose-no-vault.yaml file:
services:
consul-server:
# Consul configuration unchanged
# ...
traefik:
# Traefik configuration unchanged
# ...
traefik-consul-register:
# Registration script configuration unchanged
# ...
networks:
consul-net:
driver: bridge
traefik-net:
driver: bridge
volumes:
consul-data:
traefik-net:Use this file with:
docker-compose -f docker-compose-no-vault.yaml up -d- Update
ENABLE_VAULTvariable to your.envfile:ENABLE_VAULT=false
When running without Vault, you'll need an alternative way to manage secrets:
-
Environment Variables: Store secrets in
.envfiles or export them directlyecho "DB_PASSWORD=mypassword" >> .env
-
Config Files: Use configuration files with appropriate permissions
echo '{"username": "admin", "password": "secret"}' > config/credentials.json chmod 600 config/credentials.json
Regularly back up Consul data:
docker exec consul-server consul snapshot save /consul/data/backup.snap
docker cp consul-server:/consul/data/backup.snap ./backup.snapBack up Vault's encrypted data:
# Create a snapshot
vault operator raft snapshot save /vault/file/vault-backup.snap
# Copy the snapshot
docker cp vault:/vault/file/vault-backup.snap ./vault-backup.snapAfter setting up the core infrastructure, you can:
- Add services to your architecture
- Configure service registration
- Set up secret management for your services
- Implement health checks for all services
- Add your services (see [Adding Services](Adding-Services)) [Architecture Overview](Architecture-Overview) - Detailed explanation of the architecture design [Core Components](Core-Components) - Information about Consul, Traefik, and Vault [Detailed Setup](Detailed-Setup) - Step-by-step setup instructions [Adding Services](Adding-Services) - How to add microservices to the architecture [Service Registration](Service-Registration) - Methods for registering services with Consul [Service Routing](Service-Routing) - Configuring Traefik for routing to services [Secret Management](Secret-Management) - Working with Vault for secrets [Health Checks](Health-Checks) - Implementing and monitoring service health [Advanced Features](Advanced-Features) - Advanced capabilities of each component [Production Deployment](Production-Deployment) - Checklist and best practices for production