Home Explore Blog CI



kubernetes

4th chunk of `content/en/blog/_posts/2016-07-00-Cross-Cluster-Services.md`
809b0e050ca9eee090dd0023d024a6d09efb3ebdac74c48100000001000009a7
![](https://lh6.googleusercontent.com/4_s4eMx0Dihz3RHENvFN16WnbaIyLadoQhYp3AYgSijDz5tTwmpuYXw4wufBKUTp1nM1vGyiFpIy6LRu3wJoj4_RXvXj6XqqlBzBB2FCttvLZw-RLaqIVXDjPwHtsGE_Q_920Zqy)



**Creating a Federated Service**



Let’s list out all the clusters in our federation:



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

NAME               STATUS    VERSION   AGE  
gce-asia-east1     Ready               1m  
gce-europe-west1   Ready               57s  
gce-us-central1    Ready               47s  
gce-us-east1       Ready               34s
 ```



Let’s create a federated service object:




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



The '--context=federation-cluster' flag tells kubectl to submit the request to the Federation API endpoint, with the appropriate credentials. The federated service will automatically create and maintain matching Kubernetes services in all of the clusters underlying your federation.



You can verify this by checking in each of the underlying clusters, for example:




```
kubectl --context=gce-asia-east1a get svc nginx  
NAME      CLUSTER-IP     EXTERNAL-IP      PORT(S)   AGE  
nginx     10.63.250.98   104.199.136.89   80/TCP    9m
 ```



The above assumes that you have a context named 'gce-asia-east1a' configured in your client for your cluster in that zone. The name and namespace of the underlying services will automatically match those of the federated service that you created above.



The status of your Federated Service will automatically reflect the real-time status of the underlying Kubernetes services, for example:




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

Name:                   nginx  
Namespace:              default  
Labels:                 run=nginx  
Selector:               run=nginx  
Type:                   LoadBalancer  
IP:           
LoadBalancer Ingress:   104.XXX.XX.XXX, 104.XXX.XX.XXX, 104.XXX.XX.XXX, 104.XXX.XXX.XX  
Port:                   http    80/TCP  
Endpoints:              \<none\>  
Session Affinity:       None  
No events.
 ```



The 'LoadBalancer Ingress' addresses of your federated service corresponds with the 'LoadBalancer Ingress' addresses of all of the underlying Kubernetes services. For inter-cluster and inter-cloud-provider networking between service shards to work correctly, your services need to have an externally visible IP address. Service Type: Loadbalancer is typically used here.

Title: Creating and Verifying a Federated Service in Kubernetes
Summary
This section outlines the process of creating a federated service in Kubernetes and verifying its deployment. It starts by listing the clusters in the federation, then creates a federated service object using `kubectl`. The `--context=federation-cluster` flag directs the request to the Federation API endpoint, which then automatically creates and maintains matching Kubernetes services in all underlying clusters. Verification involves checking individual clusters for the created service. The status of the Federated Service reflects the real-time status of the underlying Kubernetes services, with the 'LoadBalancer Ingress' addresses corresponding to those of the underlying services. Services require externally visible IP addresses, typically achieved using Service Type: Loadbalancer for inter-cluster and inter-cloud-provider networking.