3

I'm trying to make a Kubernetes multi-cluster, and I need a unique value to distinguish between cluster.

Does Kubernetes provide a UID to distinguish each cluster?

If not, is the best way to separate each cluster by the UID of the kube-system namespace?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
H.jenny
  • 171
  • 1
  • 2
  • 11
  • Good question, not that I'm aware of. You can provide kubeadm a unique name for the cluster at creation time but that isn't really in the API. – Matt Aug 14 '20 at 05:26
  • [It seems a no from this qa](https://stackoverflow.com/questions/38242062/how-to-get-kubernetes-cluster-name-from-k8s-api). If you give kubeadm a unique name it will be available in a [config map](https://stackoverflow.com/a/55684901). The kube-system ns UUID is unlikely to be replaced, but could be duplicated if you restored data. It's more of a etcd dataset UUID, but that's pretty equivalent to a cluster. – Matt Aug 14 '20 at 05:27
  • @Matt when you said `could be duplicated if you restored data`, which data you're referring to? – Kamol Hasan Aug 14 '20 at 06:56
  • The data in the kubernetes etcd store, basically everything you can `kubectl get` from the api – Matt Aug 14 '20 at 06:58
  • @Matt that's interesting. So, if I want to create 2 different clusters with the same UID (i.e. kube-system ns uid), it's theoretically possible? – Kamol Hasan Aug 14 '20 at 07:50
  • The option available is to use Kube-system namespace uid to differentiate between clusters. Reference - https://groups.google.com/g/kubernetes-sig-architecture/c/mVGobfD4TpY/m/nkdbkX1iBwAJ?pli=1 – Rohit Aug 14 '20 at 08:31
  • Good question, i will try to find something in the etcd. But AFAIK the context in the only way to differ the clusters... – Mr.KoopaKiller Aug 14 '20 at 14:36
  • @KamolHasan yes it's possible, but you would need to be working at a level lower than the kubernetes API to be able to set UID's. – Matt Aug 15 '20 at 00:49
  • and might not be advisable if some form of cluster federation makes a return. – Matt Aug 15 '20 at 00:50
  • I believe this question should be reopened. Developers often use Kubernetes, wanting a better understanding of how it works should be within scope for SO. – Andrew Apr 14 '21 at 08:32

1 Answers1

0

if you have multi cluster and in each cluster you have multi user and namespace, and you want to handle switching between them, it is better to use kubernetes contexts, https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/ if you just need something unique about cluster, use certificate authority information(ca.crt or ca.key in /etc/kubernetes/pki/ directory). but be careful those files should be secured

mhafshari
  • 41
  • 3