Mastering Kubernetes Federation: Install, Join Clusters, and Sync Resources
This guide explains the purpose of Kubernetes Federation, its benefits for multi‑cluster management, step‑by‑step installation using Helm and kubefedctl, how to join and unjoin clusters, enable resource federation, and provides a cheat sheet of common commands for reliable cross‑cluster deployments.
Background
Federation aims to manage multiple Kubernetes clusters from a single control plane, across regions, cloud providers, or on‑premise clusters.
After federation, the Federation API can uniformly manage resources such as Deployments, Services, replica counts, etc.
Benefits include simplified component management, workload distribution for reliability, cross‑cluster orchestration, easier migration, geo‑aware service discovery, and multi‑cloud or hybrid‑cloud deployments.
Installation
Helm
Install Helm according to its documentation.
Controller Plane
Deploy the controller plane with Helm (v2) using the official chart:
<code>$ helm repo add kubefed-charts https://raw.githubusercontent.com/kubernetes-sigs/kubefed/master/charts
$ helm search repo kubefed
$ helm --namespace kube-federation-system upgrade -i kubefed kubefed-charts/kubefed --version=0.6.1 --create-namespace</code>kubefedctl
Download the binary from the GitHub releases page and install it:
<code>$ wget https://github.com/kubernetes-sigs/kubefed/releases/download/v0.6.1/kubefedctl-0.6.1-linux-amd64.tgz
$ tar -zxvf kubefedctl-0.6.1-linux-amd64.tgz
$ mv kubefedctl /usr/local/bin/</code>Cluster Operations
Set context on the host cluster
Use
kubectl config get-contextsand
kubectl config use-context <name>to select the host cluster.
Join a member cluster
<code>$ kubefedctl join <cluster-name> --cluster-context <member-context> --host-cluster-context <host-context> --v=2</code>Unjoin a cluster
<code>$ kubefedctl unjoin <cluster-name> --cluster-context <member-context> --host-cluster-context <host-context> --v=2</code>Get cluster information
<code>$ kubectl -n kube-federation-system get kubefedclusters
$ kubectl -n kube-federation-system get kubefedclusters -o yaml <cluster></code>Enabling Resource Federation
Use
kubefedctl enable <API‑type>to make a resource type federatable. Supported identifiers include Kind (e.g., Deployment), plural name (deployments), group‑qualified name (deployment.apps), and short alias (deploy).
After enabling, a CRD such as
federatedvirtualservicesappears in the host cluster.
Sample Workflow
Apply the demo namespace and federated namespace, then deploy sample resources:
<code>kubectl apply -f example/sample1/namespace.yaml -f example/sample1/federatednamespace.yaml
kubectl apply -R -f example/sample1</code>If a resource type is not yet enabled, the command will fail with an “unable to recognize …” error; enable the missing type (e.g.,
ClusterRoleBinding) and re‑apply.
Common Commands Cheat Sheet
<code>helm list --all-namespaces
helm --namespace kube-federation-system upgrade -i kubefed kubefed-charts/kubefed --version=0.6.1 --create-namespace
kubefedctl join <cluster> --cluster-context <ctx> --host-cluster-context <host> --v=2
kubectl config get-contexts
kubectl -n kube-federation-system get kubefedclusters
kubectl api-resources | grep kubefed
kubefedctl unjoin <cluster> --cluster-context <ctx> --host-cluster-context <host> --v=2
kubectl -n kube-federation-system delete FederatedTypeConfig --all
helm --namespace kube-federation-system uninstall kubefed</code>Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.