Kubernetes - Find out service ip range CIDR programatically

不想你离开。 提交于 2021-02-08 05:29:20

问题


I need a way to get service cluster ip range (as CIDR) that works accross all Kubernetes clusters.

I tried the following, which works fine for clusters created with kubeadm as it greps arguments of apiserver pod:

$ kubectl cluster-info dump  | grep service-cluster-ip-range
                        "--service-cluster-ip-range=10.96.0.0/12",

This does not work on all Kubernetes clusters, i.e. gcloud

So the question is, what is the best way to get service ip range programatically?


回答1:


I don't think there is a way to access such information through K8s Api, there is an open issue to address lack of this functionality: https://github.com/kubernetes/kubernetes/issues/25533 . If you have access to the etcd of the k8s cluster in question, then there is a key with information about service cidr range: /registry/ranges/serviceips . You can get the value, by using etcdctl (assuming, you have the proper permissions): etcdctl --enpoints=<your etcd> --<any authentication flags> get "/registry/ranges/serviceips" --prefix=true.



来源:https://stackoverflow.com/questions/44154425/kubernetes-find-out-service-ip-range-cidr-programatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!