From bd6ec230c31fefeae1efa20683885c7bcc11bd25 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 1 Oct 2018 10:35:09 -0700 Subject: [PATCH] website: clarify that downward API works in any pod spec --- website/source/docs/platform/k8s/run.html.md | 39 +++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/website/source/docs/platform/k8s/run.html.md b/website/source/docs/platform/k8s/run.html.md index 15bf7e9143..57608a90f0 100644 --- a/website/source/docs/platform/k8s/run.html.md +++ b/website/source/docs/platform/k8s/run.html.md @@ -130,7 +130,10 @@ For Consul installed via the Helm chart, a client agent is installed on each Kubernetes node. This is explained in the [architecture](/docs/platform/k8s/run.html#client-agents) section. To access the agent, you may use the [downward API](https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/). -An example pod specification is shown below: + +An example pod specification is shown below. In addition to pods, anything +with a pod template can also access the downward API and can therefore also +access Consul: StatefulSets, Deployments, Jobs, etc. ```yaml apiVersion: v1 @@ -155,6 +158,40 @@ spec: restartPolicy: Never ``` +An example `Deployment` is also shown below to show how the host IP can +be accessed from nested pod specifications: + +```yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: consul-example-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: consul-example + template: + metadata: + labels: + app: consul-example + spec: + 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 +``` + ### Upgrading Consul on Kubernetes To upgrade Consul on Kubernetes, we follow the same pattern as