how can i assign my host ip address into kubernetes configmap?

1.1k views Asked by At

I assigned my host IP address in the config map. Yaml But my host IP address always changes How can I assign my host MAC address or any possible solution?

apiVersion: v1
kind: ConfigMap
metadata:
name: app-configmap
data:
   display: 10.0.10.123:0.0
1

There are 1 answers

0
David Maze On BEST ANSWER

You can't put "the host" IP address into a ConfigMap. Consider a cluster with multiple nodes and multiple replicas of your Deployment: you could have three identical Pods running, all mounting the same ConfigMap, but all running on different hosts.

If you do need the host's IP address for some reason, you can use the downward API to get it:

# In your pod spec, not a ConfigMap
env:
  - name: HOST_IP
    valueFrom:
      fieldRef:
        fieldPath: status.hostIP

Again, though, note that each replica could be running on a different node, so this is only useful if you can guarantee some resource is running on every node (maybe a Kubernetes DaemonSet is launching it). That configuration suggests an X Window System display server address, and typically this would be located outside the cluster, not on the nodes actually running the pods.