Hashicorp Consul, Agent/Client access Hashicorp Consul, Agent/Client access kubernetes kubernetes

Hashicorp Consul, Agent/Client access


You can use the Kubernetes downward API to inject the IP of host as an environment variable for your pod.

apiVersion: v1kind: Podmetadata:  name: consul-examplespec:  containers:    - name: example      image: 'consul:latest'      env:        - name: HOST_IP          valueFrom:            fieldRef:              fieldPath: status.hostIP      command:        - '/bin/sh'        - '-ec'        - |          export CONSUL_HTTP_ADDR="${HOST_IP}:8500"          consul kv put hello world  restartPolicy: Never

See https://www.consul.io/docs/k8s/installation/install#accessing-the-consul-http-api for more info.