Home Explore Blog CI



kubernetes

4th chunk of `content/en/blog/_posts/2016-12-00-Cluster-Federation-In-Kubernetes-1-5.md`
a9d40d74894b4e0c227ef83257e8bb6fba68ad44784f91aa000000010000093f
The federation context will become our administration entry point. Now it’s time to join clusters (4-joinfed.sh):

```
$ cat 4-joinfed.sh && . 4-joinfed.sh

kubefed --context=federation join cluster-europe-west1-b --cluster-context=gke\_${FED\_PROJECT}\_europe-west1-b\_gce-europe-west1-b --host-cluster-context=gke\_${FED\_PROJECT}\_${FED\_HOST\_CLUSTER}\_gce-${FED\_HOST\_CLUSTER}


kubefed --context=federation join cluster-asia-east1-a --cluster-context=gke\_${FED\_PROJECT}\_asia-east1-a\_gce-asia-east1-a --host-cluster-context=gke\_${FED\_PROJECT}\_${FED\_HOST\_CLUSTER}\_gce-${FED\_HOST\_CLUSTER}


kubefed --context=federation join cluster-us-east1-b --cluster-context=gke\_${FED\_PROJECT}\_us-east1-b\_gce-us-east1-b --host-cluster-context=gke\_${FED\_PROJECT}\_${FED\_HOST\_CLUSTER}\_gce-${FED\_HOST\_CLUSTER}
 ```


Note that cluster gce-us-east1-b is used here to run the federation control plane and also to work as a worker cluster. This circular dependency helps to use resources more efficiently and it can be verified by using the kubectl --context=federation get clusters command:  

```
$ kubectl --context=federation get clusters

NAME                        STATUS    AGE

cluster-asia-east1-a        Ready     7s

cluster-europe-west1-b      Ready     10s

cluster-us-east1-b          Ready     10s
 ```



We are good to go.



**Using Federation To Run An Application**  

In our [repository](https://github.com/ContainerSolutions/k8shserver) you will find instructions on how to build a docker image with a web service that displays the container’s hostname and the Google Cloud Platform (GCP) zone.


An example output might look like this:


```
{"hostname":"k8shserver-6we2u","zone":"europe-west1-b"}
 ```


Now we will deploy the Replica Set ([k8shserver.yaml](https://github.com/ContainerSolutions/k8shserver/blob/master/rs/k8shserver.yaml)):  

```
$ kubectl --context=federation create -f rs/k8shserver
 ```



And a Federated Service ([k8shserver.yaml](https://github.com/ContainerSolutions/k8shserver/blob/master/services/k8shserver.yaml)):  

```
$ kubectl --context=federation create -f service/k8shserver
 ```



As you can see, the two commands refer to the “federation” context, i.e. to the federation control plane. After a few minutes, you will realize that underlying clusters run the Replica Set and the Service.  

Title: Joining Clusters to the Federation and Deploying an Application
Summary
This section details joining pre-existing clusters (europe-west1-b, asia-east1-a, and us-east1-b) to a Kubernetes federation using the 'kubefed join' command, noting that the host cluster (us-east1-b) also functions as a worker node. It then describes how to deploy a sample web service application using a Replica Set and a Federated Service, applying the configurations from the federation control plane.