Download the command line tools from Github and
install them in your $PATH
(e.g. /usr/local/sbin
).
Create a new project in your Google Cloud Console and note down the project name.
Generate a Google Cloud Platform secret key in JSON format and store it in this location: $HOME/.federation-key.json
.
You can generate it under IAM & Admin / Service accounts. Select Create key from the menu next to the default service account.
WARNING: this creates several clusters in Google Cloud Platform! Watch out for your billing!
-
make sure
kubefed
andkubectl
are in$PATH
-
Adjust some variables:
Change
FED_PROJECT
andFED_DNS_ZONE
in theMakefile
and inscripts/settings.source
to match your GCE project name and some domain name that you can control (although actually changing DNS configuration it is not required for this demo). -
Reserve two global IP adddress:
gcloud compute addresses create kubernetes-ingress --global gcloud compute addresses create geoserver-admin --global
Note down those IPs, they are needed later.
-
Set up a firewall rule:
Assuming you have clusters in
us-east1-b
,europe-west1-b
andasia-east1-a
, run:gcloud compute firewall-rules create my-federated-ingress-firewall-rule --source-ranges 130.211.0.0/22 --allow "icmp,tcp:80,tcp:443 tcp:30000-33000" --target-tags "cluster-europe-west1-b,cluster-asia-east1-a,cluster-us-east1-b" --network default
See kubernetes/kubernetes#37306 for the reason behind this step.
-
Create the clusters:
Change folder to
scripts
./init.sh
This operation make take a long time.
-
Update the local kubeconfig file
./credentials.sh
-
Initialise the federation:
./init-federation.sh
-
Join the clusters together:
./join.sh
-
Setup the variable to the
geoserver-admin
manifest for handling the federation via API calls../clusters
-
Deploy Federated Service and Ingress and the federated application
kubectl --context=federation create -f manifests/geoserver-service.yaml kubectl --context=federation create -f manifests/geoserver-ingress.yaml kubectl --context=federation create -f manifests/geoserver-replica.yaml
-
Deploy the demo application:
kubectl --context=federation create -f manifests/geoserver-admin.yaml
Point your browser to the IP address you generated in step 2 (geoserver-admin). You can always find it again later by executing:
gcloud compute addresses list | grep geoserver-admin
You should see the clusters appearing on a map, but no traffic yet.
The script scripts/start-traffic.sh
will create a micro-instance in the desired Google
datacenter and execute a small script that generates traffic on the federated cluster.
Launch it as often as you want with different regions as argument.
Important: Do not launch it in the same regions as the Kubernetes clusters, as this will not work nicely with the Maps user interface.
The required arguments are the region where to generate traffic from, the IP address of the global ingress load balancer and the IP address of the admin service (from step 2 above).
# replace the two IP addresses with your own created in step 2:
scripts/start-traffic.sh asia-northeast1 130.211.41.245 104.155.43.73
scripts/start-traffic.sh us-central1 130.211.41.245 104.155.43.73
To remove the VM generating traffic again, run scripts/stop-traffic.sh REGION
. This
may also be useful to clean up when setting up traffic generation might have failed for some reason.
You can now move around the map, and enable or disable either clusters or traffic sources (green markers with a house icon). You should see the traffic numbers in the statistics window changing and lines between traffic sources and datacenters, depending on what the next healthy datacenter to a traffic source is.
If you don't want to or can't create a cluster, or if you want to hack on the map frontend, you can simulate the demo.
Just build and run the binary in ADMIN
mode, then open your browser and add ?simulate
to the URL:
make build
ADMIN=1 ./kubernetes-federation-demo
open http://localhost:8080/?simulate
You can modify the demo by changing the canned JSON responses in static/simulate.js
.
-
Make sure you have a DockerHub or GCR account
If you haven't got a DockerHub account yet, create one at hub.docker.com. Alternatively, you should be equally successful using the Google Container Registry.
-
Adjust the IMAGE variable
Change the
IMAGE
variable in theMakefile
to match your own image registry account. -
Make your changes to the code, then build and push
make push