Home Explore Blog CI



kubernetes

3rd chunk of `content/en/blog/_posts/2016-10-00-Globally-Distributed-Services-Kubernetes-Cluster-Federation.md`
9c68b85de8c2f6d4f686dac9c5f5861226cdd66c831c3f8d0000000100000fc6
gce-us-central1-a    Ready     1m  
gce-us-central1-b    Ready     53s  
gce-us-central1-c    Ready     39s
  ```



|You can download the source used in this blog post [here](https://github.com/allannaim/federated-ingress-sample). The source consists of the following files:|
|---|---|
|configmaps/zonefetch.yaml| retrieves the zone from the instance metadata server and concatenates into volume mount path|
|replicasets/nginx-rs.yaml | deploys a Pod consisting of an nginx and busybox container|
|ingress/ingress.yaml | creates a load balancer with a global VIP  that distributes requests to the closest nginx backend|
|services/nginx.yaml| exposes the nginx backend as an external service|




In our example, we’ll be deploying the service and ingress object using the federated control plane. The [ConfigMap](/docs/user-guide/configmap/) object isn’t currently supported by Federation, so we’ll be deploying it manually in each of the underlying Federation clusters. Our cluster deployment will look as follows:



We’re going to deploy a Service that is sharded across our 9 clusters. The backend deployment will consist of a Pod with 2 containers:

- busybox container that fetches the zone and outputs an HTML with the zone embedded in it into a Pod volume mount path
- nginx container that reads from that Pod volume mount path and serves an HTML containing the zone it’s running in


Let’s start by creating a federated service object in the federation-cluster context.



```
$ kubectl --context=federation-cluster create -f services/nginx.yaml
 ```



It will take a few minutes for the service to propagate across the 9 clusters.




```
$ kubectl --context=federation-cluster describe services nginx


Name:                   nginx  
Namespace:              default  
Labels:                 app=nginx  
Selector:               app=nginx  
Type:                   LoadBalancer  
IP:  
LoadBalancer Ingress:   108.59.xx.xxx, 104.199.xxx.xxx, ...  
Port:                   http    80/TCP

NodePort:               http    30061/TCP  
Endpoints:              <none>  
Session Affinity:       None
 ```



Let’s now create a Federated Ingress. Federated Ingresses are created in much that same way as traditional [Kubernetes Ingresses](/docs/user-guide/ingress/): by making an API call which specifies the desired properties of your logical ingress point. In the case of Federated Ingress, this API call is directed to the Federation API endpoint, rather than a Kubernetes cluster API endpoint. The API for Federated Ingress is 100% compatible with the API for traditional Kubernetes Services.




```
$ cat ingress/ingress.yaml   

apiVersion: extensions/v1beta1  
kind: Ingress  
metadata:  
  name: nginx  
spec:  
  backend:  
    serviceName: nginx  
    servicePort: 80
 ```




```
$ kubectl --context=federation-cluster create -f ingress/ingress.yaml   
ingress "nginx" created
 ```



Once created, the Federated Ingress controller automatically:

1. 1.creates matching Kubernetes Ingress objects in every cluster underlying your Cluster Federation
2. 2.ensures that all of these in-cluster ingress objects share the same logical global L7 (i.e. HTTP(S)) load balancer and IP address
3. 3.monitors the health and capacity of the service “shards” (i.e. your Pods) behind this ingress in each cluster
4. 4.ensures that all client connections are routed to an appropriate healthy backend service endpoint at all times, even in the event of Pod, cluster, availability zone or regional outages
We can verify the ingress objects are matching in the underlying clusters. Notice the ingress IP addresses for all 9 clusters is the same.




```
$ for c in $(kubectl config view -o jsonpath='{.contexts[*].name}'); do kubectl --context=$c get ingress; done  

NAME      HOSTS     ADDRESS   PORTS     AGE  
nginx     \*                   80        1h  
NAME      HOSTS     ADDRESS          PORTS     AGE  
nginx     \*         130.211.40.xxx   80        40m  
NAME      HOSTS     ADDRESS          PORTS     AGE  

Title: Deploying a Sharded Service and Federated Ingress across Clusters
Summary
This section details deploying a sharded service across nine Kubernetes clusters using a federated control plane. It outlines the deployment of a service with pods containing a busybox container (to fetch the zone and output HTML with the zone embedded) and an nginx container (to serve the HTML). The process includes creating a federated service object, describing the service, and creating a federated ingress. The federated ingress controller automates the creation of matching Kubernetes Ingress objects in each cluster, ensures they share a global L7 load balancer and IP address, monitors service health, and routes client connections to healthy backend service endpoints. The verification step confirms that the ingress objects match across all nine clusters, with the same IP address.