The next scenario to look at is when we have multiple servers. Letโs say in this case weโre accessing a set of web service providers, so it doesnโt matter which one we hit. Letโs assume we always want access to the service via at least two routers because we donโt want any single points of failure in our solution.
The simplest way to do this is to just add another address to the config:
ziti edge create config test-host-config host.v2 '
{
"terminators" : [
{ "address": "192.168.3.136", "port" : 8080, "protocol": "tcp" },
{ "address": "192.168.3.137", "port" : 8080, "protocol": "tcp" }
]
}
'
ziti edge create service test -c test-host-config --terminator-strategy smartrouting
ziti edge create edge-router edge-router-1 --tunneler-enabled
ziti edge create edge-router edge-router-2 --tunneler-enabled
# skipping router enrollment steps
ziti edge update identity edge-router-1 --role-attributes 'test-hosts'
ziti edge update identity edge-router-2 --role-attributes 'test-hosts'
ziti edge create service-edge-router-policy test-serp --service-roles '@test' --edge-router-roles '#all'
ziti edge create service-policy test-bind Bind --service-roles '@test' --identity-roles '#test-hosts'
Now when we list terminators, weโll see four. Each router will have a terminator for each server.
$ ziti fabric list terminators
โญโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโฌโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโฎ
โ ID โ SERVICE โ ROUTER โ BINDING โ ADDRESS โ IDENTITY โ COST โ PRECEDENCE โ DYNAMIC COST โ
โโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโโโโโโค
โ ZAOz โ test โ edge-router-1 โ tunnel โ f20bde9b-7cd6-4a8a-a1f4-8f4cd1079277 โ โ 0 โ default โ 0 โ
โ dnmz โ test โ edge-router-2 โ tunnel โ 566e2c00-fd4b-45a7-86bf-a53515eb09ce โ โ 0 โ default โ 0 โ
โ doRz โ test โ edge-router-1 โ tunnel โ bc6f7c56-ad7a-4610-b771-805f82f6fb70 โ โ 0 โ default โ 0 โ
โ dyVZ โ test โ edge-router-2 โ tunnel โ 53cedebd-d9da-44d9-8458-3f16fb0811a9 โ โ 0 โ default โ 0 โ
โฐโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโโโโโโโฏ
results: 1-4 of 4
If one of the servers goes down, connections to it will fail. This will increase the cost of that terminator and the other server will be preferred. The cost will slowly come down and eventually it will be retried. If itโs back up, weโll start using it again. If itโs still down, the cost will jump back up.
We can be more proactive with our health checking though, by defining some health checks in the server config.
ziti edge update config test-host-config host.v2 --data '
{
"terminators" : [
{
"address": "192.168.3.136",
"port" : 8080,
"protocol": "tcp",
"portChecks" : [
{
"address" : "192.168.3.136:8080",
"interval" : "5s",
"timeout" : "100ms",
"actions" : [
{
"trigger" : "fail",
"consecutiveEvents" : 3,
"action" : "mark unhealthy"
},
{
"trigger" : "pass",
"consecutiveEvents" : 3,
"action" : "mark healthy"
}
]
}
]
},
{
"address": "192.168.3.137",
"port" : 8080,
"protocol": "tcp",
"portChecks" : [
{
"address" : "192.168.3.137:8080",
"interval" : "5s",
"timeout" : "100ms",
"actions" : [
{
"trigger" : "fail",
"consecutiveEvents" : 3,
"action" : "mark unhealthy"
},
{
"trigger" : "pass",
"consecutiveEvents" : 3,
"action" : "mark healthy"
}
]
}
]
}
]
}
'
This defines a simple port check which will run every 5 seconds. If the connect fails or times out, the check will fail. After 3 consecutive checks fail, the terminator will be marked as failed
, which will it prevent it from being used, as long as there are any other healthy terminators. The health check will continue to run and once it has three checks pass in a row, the terminator will be returned to its original precedence of default
.
In addition to simple port checks, ziti also supports http checks.
Next weโll take a look at how to handle failover when youโve got a primary server that should always be used until it fails, at which point you want to fail over to a secondary.