CodeBlanks Logo Icon CodeBlanks

Summary - Multi-cluster

Combine kubeconfig and cross-cluster service to switch contexts.

Summary: multi-cluster

In this group:

  • Multiple clusters are used for isolation, availability, regulation and scale; the cost is operational load.
  • Distribution: GitOps (Argo CD ApplicationSet, Flux) or managers like Karmada; KubeFed was abandoned.
  • Kubeconfig: clusters + users + contexts; --context, KUBECONFIG merging, exec-based credentials.
  • Cross-cluster services: MCS (ServiceExport, clusterset.local), a mesh or an internal LB; CIDRs must not overlap.
  • A cluster registry is a set of labelled records; the ApplicationSet cluster generator deploys by label.
for c in uretim-eu uretim-tr; do kubectl --context $c get deploy -n magaza; done

Practice Checking all clusters

Write a one-line shell loop: for c in uretim-eu uretim-tr; do kubectl --context $c get deploy -n magaza; done. Then, on a separate line, print the ready replica count of the api deployment in magaza in the uretim-tr context with jsonpath='{.status.readyReplicas}'.

Starter code

terminal
# buraya yaz

Sample solution

terminal
for c in uretim-eu uretim-tr; do kubectl --context $c get deploy -n magaza; done
kubectl --context uretim-tr get deploy api -n magaza -o jsonpath='{.status.readyReplicas}'

Expected output

NAME   READY   UP-TO-DATE   AVAILABLE   AGE
api    4/4     4            4           12d
web    3/3     3            3           12d
NAME   READY   UP-TO-DATE   AVAILABLE   AGE
api    2/2     2            2           9d
web    2/2     2            2           9d
2

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is a good way to reduce the risk of running a command on the wrong cluster?

  • Giving the clusters the same name
  • Writing --context explicitly on every command in scripts Correct answer
  • Sharing a single kubeconfig
  • Relying on current-context

Explanation: The active context may have been changed in another terminal.

2 Run the command on a specific cluster.

Question
kubectl ____ uretim-tr get pods -n magaza
Answer
kubectl --context uretim-tr get pods -n magaza

Explanation: --context picks a target without changing the active context.

3 Match.

Term Meaning
--context Single-command target
ApplicationSet Multi-cluster deployment
ServiceExport Cross-cluster service
kubeconfig Connection info

All lessons in Expert