|
| 1 | +--- |
| 2 | +--- |
| 3 | + |
| 4 | +This guide explains how to use replica sets in the Federation control plane. |
| 5 | + |
| 6 | + |
| 7 | +* TOC |
| 8 | +{:toc} |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +This guide assumes that you have a running Kubernetes Cluster |
| 13 | +Federation installation. If not, then head over to the |
| 14 | +[federation admin guide](/docs/admin/federation/) to learn how to |
| 15 | +bring up a cluster federation (or have your cluster administrator do |
| 16 | +this for you). Other tutorials, for example |
| 17 | +[this one](https://github.com/kelseyhightower/kubernetes-cluster-federation) |
| 18 | +by Kelsey Hightower, are also available to help you. |
| 19 | + |
| 20 | +You are also expected to have a basic |
| 21 | +[working knowledge of Kubernetes](/docs/getting-started-guides/) in |
| 22 | +general and [ReplicaSets](/docs/user-guide/replicasets/) in particular. |
| 23 | + |
| 24 | +## Overview |
| 25 | + |
| 26 | +Replica Sets in federation control plane (referred to as "federated replica sets" in |
| 27 | +this guide) are very similar to the traditional [Kubernetes |
| 28 | +ReplicaSets](/docs/user-guide/replicasets/), and provide the same functionality. |
| 29 | +Creating them in the federation control plane ensures that the desired number of |
| 30 | +replicas exist across the registered clusters. |
| 31 | + |
| 32 | + |
| 33 | +## Creating a Federated Replica Set |
| 34 | + |
| 35 | +The API for Federated Replica Set is 100% compatible with the |
| 36 | +API for traditional Kubernetes Replica Set. You can create a replica set by sending |
| 37 | +a request to the federation apiserver. |
| 38 | + |
| 39 | +You can do that using [kubectl](/docs/user-guide/kubectl/kubectl/) by running: |
| 40 | + |
| 41 | +``` shell |
| 42 | +kubectl --context=federation-cluster create -f myrs.yaml |
| 43 | +``` |
| 44 | + |
| 45 | +The '--context=federation-cluster' flag tells kubectl to submit the |
| 46 | +request to the Federation apiserver instead of sending it to a kubernetes |
| 47 | +cluster. |
| 48 | + |
| 49 | +Once a federated replica set is created, the federation control plane will create |
| 50 | +a replica set in all underlying kubernetes clusters. |
| 51 | +You can verify this by checking each of the underlying clusters, for example: |
| 52 | + |
| 53 | +``` shell |
| 54 | +kubectl --context=gce-asia-east1a get rs myrs |
| 55 | +``` |
| 56 | + |
| 57 | +The above assumes that you have a context named 'gce-asia-east1a' |
| 58 | +configured in your client for your cluster in that zone. |
| 59 | + |
| 60 | +These replica sets in underlying clusters will match the federation replica set |
| 61 | +except in the number of replicas. Federation control plane will ensure that the |
| 62 | +sum of replicas in each cluster match the desired number of replicas in the |
| 63 | +federation replica set. |
| 64 | + |
| 65 | +### Spreading Replicas in Underlying Clusters |
| 66 | + |
| 67 | +By default, replicas are spread equally in all the underlying clusters. For ex: |
| 68 | +if you have 3 registered clusters and you create a federated replica set with |
| 69 | +`spec.replicas = 9`, then each replica set in the 3 clusters will have |
| 70 | +`spec.replicas=3`. |
| 71 | +To modify the number of replicas in each cluster, you can specify |
| 72 | +[FederatedReplicaSetPreference](https://github.com/kubernetes/kubernetes/blob/{{page.githubbranch}}/federation/apis/federation/types.go) |
| 73 | +as an annotation with key `federation.kubernetes.io/replica-set-preferences` |
| 74 | +on federated replica set. |
| 75 | + |
| 76 | + |
| 77 | +## Updating a Federated Replica Set |
| 78 | + |
| 79 | +You can update a federated replica set as you would update a Kubernetes |
| 80 | +replica set; however, for a federated replica set, you must send the request to |
| 81 | +the federation apiserver instead of sending it to a specific Kubernetes cluster. |
| 82 | +The Federation control plan ensures that whenever the federated replica set is |
| 83 | +updated, it updates the corresponding replica sets in all underlying clusters to |
| 84 | +match it. |
| 85 | +If your update includes a change in number of replicas, the federation |
| 86 | +control plane will change the number of replicas in underlying clusters to |
| 87 | +ensure that their sum remains equal to the number of desired replicas in |
| 88 | +federated replica set. |
| 89 | + |
| 90 | +## Deleting a Federated Replica Set |
| 91 | + |
| 92 | +You can delete a federated replica set as you would delete a Kubernetes |
| 93 | +replica set; however, for a federated replica set, you must send the request to |
| 94 | +the federation apiserver instead of sending it to a specific Kubernetes cluster. |
| 95 | + |
| 96 | +For example, you can do that using kubectl by running: |
| 97 | + |
| 98 | +```shell |
| 99 | +kubectl --context=federation-cluster delete rs myrs |
| 100 | +``` |
| 101 | + |
| 102 | +Note that at this point, deleting a federated replica set will not delete the |
| 103 | +corresponding replica sets from underlying clusters. |
| 104 | +You must delete the underlying Replica Sets manually. |
| 105 | +We intend to fix this in the future. |
0 commit comments