Local playground for testing and development §
- Environment prerequisites
- Running project locally
- Verify installation
- Run integration tests
- Cleaning
- Sample demo
Environment prerequisites §
-
Install gnu-sed if you don't have it. If you are on a Mac, install
gnu-sed
with Homebrewbrew install gnu-sed
-
Ensure you are able to push/pull from your docker registry
To run multiple clusters, reserve 8GB of memory*
* above screenshot is provided for Docker for Mac, options for other Docker distributions may vary -
install kubectl to operate k8s clusters
-
install helm3 to deploy k8gb and related test workloads
-
install k3d to run local k3s clusters (minimum 4.2 version is required)
-
install golangci-lint for code quality checks
Running project locally §
To spin-up a local environment using two k3s clusters and deploy a test application to both clusters, execute the command below:
make deploy-full-local-setup
Verify installation §
If local setup runs well, check if clusters are correctly installed
kubectl cluster-info --context k3d-test-gslb1 && kubectl cluster-info --context k3d-test-gslb2
Cluster test-gslb1 is exposing external DNS on default port :5053
while test-gslb2 on port :5054
.
dig @localhost localtargets-roundrobin.cloud.example.com -p 5053 && dig -p 5054 @localhost localtargets-roundrobin.cloud.example.com
As expected result you should see two A records divided between both clusters (IP addresses may differ).
...
...
;; ANSWER SECTION:
localtargets-roundrobin.cloud.example.com. 30 IN A 10.43.178.134
...
...
localtargets-roundrobin.cloud.example.com. 30 IN A 10.43.75.137
Both clusters have podinfo installed on the top. Run following command and check if you get two json responses.
curl localhost:80 -H "Host:roundrobin.cloud.example.com" && curl localhost:81 -H "Host:roundrobin.cloud.example.com"
Run integration tests §
There is wide range of scenarios which GSLB provides and all of them are covered within tests. To check whether everything is running properly execute terratest :
make terratest
Cleaning §
Clean up your local development clusters with
make destroy-full-local-setup
Sample demo §
Round Robin §
Both clusters have podinfo installed on the top, where each
cluster has been tagged to serve a different region. In this demo we will hit podinfo by wget -qO - roundrobin.cloud.example.com
and depending
on region will podinfo return us or eu. In current round robin implementation are IP addresses randomly picked.
See Gslb manifest with round robin strategy
Run several times command below and watch message
field.
make test-round-robin
As expected result you should see podinfo message changing
{
"hostname": "frontend-podinfo-856bb46677-8p45m",
...
"message": "us",
...
}
{
"hostname": "frontend-podinfo-856bb46677-8p45m",
...
"message": "eu",
...
}
Failover §
Both clusters have podinfo installed on the top where each
cluster has been tagged to serve a different region. In this demo we will hit podinfo by wget -qO - failover.cloud.example.com
and depending
on whether podinfo is running inside the cluster it returns only eu or us.
See Gslb manifest with failover strategy
Switch GLSB to failover mode:
make init-failover
Now both clusters are running in failover mode and podinfo is running on both of them.
Run several times command below and watch message
field.
make test-failover
You will see only eu podinfo is responsive:
{
"hostname": "frontend-podinfo-856bb46677-8p45m",
...
"message": "eu",
...
}
Stop podinfo on current (eu) cluster:
make stop-test-app
Several times hit application again
make test-failover
As expected result you should see only podinfo from second cluster (us) is responding:
{
"hostname": "frontend-podinfo-856bb46677-v5nll",
...
"message": "us",
...
}
It might happen that podinfo will be unavailable for a while due to DNS sync interval and default k8gb DNS TTL of 30 seconds
wget: server returned error: HTTP/1.1 503 Service Temporarily Unavailable
Start podinfo again on current (eu) cluster:
make start-test-app
and hit several times hit podinfo:
make test-failover
After DNS sync interval is over eu will be back
{
"hostname": "frontend-podinfo-6945c9ddd7-xksrc",
...
"message": "eu",
...
}
Optionally you can switch GLSB back to round-robin mode
make init-round-robin