Add envoy proxy

This commit is contained in:
Eden Kirin
2024-01-14 12:45:30 +01:00
parent 304ce0678a
commit 018fd310cb
5 changed files with 896 additions and 693 deletions

View File

@ -13,7 +13,7 @@ services:
interval: 1s
timeout: 5s
retries: 10
machines-app:
machines-service:
build:
context: ./machines
dockerfile: Dockerfile
@ -23,8 +23,32 @@ services:
- DBNAME=komponiranje
- DBUSER=pero
- DBPASSWORD=pero.000
ports:
- 3000:3000
# ports:
# - 3000:3000
depends_on:
db:
condition: service_healthy
products-service:
build:
context: ./products
dockerfile: Dockerfile
environment:
- DBHOST=db
- DBPORT=5432
- DBNAME=komponiranje
- DBUSER=pero
- DBPASSWORD=pero.000
# ports:
# - 3000:3000
depends_on:
db:
condition: service_healthy
proxy:
image: envoyproxy/envoy:v1.28-latest
ports:
- "10000:10000"
volumes:
- ./proxy/envoy.yaml:/etc/envoy/envoy.yaml
depends_on:
- machines-service
- products-service

View File

@ -60,9 +60,12 @@ func initRouter(dbConn *gorm.DB) *gin.Engine {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
router.GET("/ping", handlePing)
router.GET("/", handleGetMachines(dbConn))
router.GET("/:machineId", handleGetMachine(dbConn))
routes := router.Group("/machines")
{
routes.GET("/ping", handlePing)
routes.GET("", handleGetMachines(dbConn))
routes.GET("/:machineId", handleGetMachine(dbConn))
}
return router
}

File diff suppressed because it is too large Load Diff

View File

@ -60,9 +60,12 @@ func initRouter(dbConn *gorm.DB) *gin.Engine {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
router.GET("/ping", handlePing)
router.GET("/", handleGetProducts(dbConn))
router.GET("/:productId", handleGetProduct(dbConn))
routes := router.Group("/products")
{
routes.GET("/ping", handlePing)
routes.GET("", handleGetProducts(dbConn))
routes.GET("/:productId", handleGetProduct(dbConn))
}
return router
}

65
proxy/envoy.yaml Normal file
View File

@ -0,0 +1,65 @@
static_resources:
listeners:
- address:
socket_address:
address: 0.0.0.0
port_value: 10000
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
codec_type: auto
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: backend
domains:
- "*"
routes:
- match:
prefix: "/machines"
route:
cluster: machines-app-service
- match:
prefix: "/products"
route:
cluster: products-app-service
http_filters:
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: machines-app-service
connect_timeout: 0.25s
type: strict_dns
lb_policy: round_robin
load_assignment:
cluster_name: machines-app-service
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: machines-service
port_value: 3000
- name: products-app-service
connect_timeout: 0.25s
type: strict_dns
lb_policy: round_robin
load_assignment:
cluster_name: products-app-service
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: products-service
port_value: 3000
admin:
access_log_path: "/dev/null"
address:
socket_address:
address: 0.0.0.0
port_value: 800