How can I use the cluster CIDR (the ip address range containing all pod ip addresses) inside a pod? (Autmoatically, without putting it manually in an environment variable, ConfigMap or anywhere else.)
Exampel of what I would like to:
env:
- name: CLUSTER_CIDR
valueFrom: # ??? does a configMap like this exist ??? Or any other source for clusterCidr?
configMap:
key: clusterCidr
name: ...
my best partial solution:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: GUESSED_CLUSTER_CIDR
value: $(POD_IP)/16
I can find clusterCidr inside the configMap full-cluster-state
in namespace kube-system
somewhere in the value of key full-cluster-state
. But this value is a string containing json, and it looks vendor specific (in currentState.rkeConfig.services.kubeController.clusterCidr
). I can not extract part of the the value in deployment.yaml. And I prefer to have a vendor independent solution.
I have not idea where to find ComponentConfig mentioned in related issues and do not even know if it is in alpha still.
related k8s issues (all closed without (clear) fixing):
- https://github.com/kubernetes/kubernetes/issues/25533
- https://github.com/kubernetes/kubernetes/issues/46508
About finding the CIDR of the cluster manually:
- How do you find the cluster & service CIDR of a Kubernetes cluster?
- old about finding it programmatically: Kubernetes - Find out service ip range CIDR programatically
- using the CIDR for trusted proxy, what I want to: Kubernetes: add ingress internal ip to environment