I'm trying to run a single elasticsearch node locally with nomad and can't seem to get the http port to map correctly.
First, here is my job config:
job "elk-stack" {
datacenters = ["dc1"]
type = "service"
update {
max_parallel = 1
min_healthy_time = "10s"
healthy_deadline = "3m"
progress_deadline = "10m"
auto_revert = false
canary = 0
}
meta {
ES_CLUSTER_NAME = "es-cluster"
}
migrate {
max_parallel = 1
health_check = "checks"
min_healthy_time = "10s"
healthy_deadline = "5m"
}
group "es-cluster" {
count = 1
restart {
attempts = 2
interval = "30m"
delay = "5m"
mode = "fail"
}
ephemeral_disk {
size = 300
}
task "elasticsearch" {
driver = "docker"
config {
image = "docker.elastic.co/elasticsearch/elasticsearch:7.0.1"
port_map {
rest = 9200
}
}
env {
"discovery.type" = "single-node"
"bootstrap.memory_lock" = "true"
"cluster.name" = "${NOMAD_META_ES_CLUSTER_NAME}"
"http.port" = "${NOMAD_PORT_rest}"
"http.host" = "0.0.0.0"
"http.publish_port" = "${NOMAD_HOST_PORT_rest}"
"network.host" = "0.0.0.0"
"network.publish_host" = "${NOMAD_IP_rest}"
}
resources {
cpu = 500
memory = 256
network {
mbits = 25
port "rest" {
}
}
}
service {
name = "${NOMAD_JOB_NAME}"
tags = ["global", "db"]
port = "rest"
check {
name = "alive"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
}
}
}
With this config the task spins up fine and the check passes and I can see the port mapping with docker:
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e8712c2566c8 docker.elastic.co/elasticsearch/elasticsearch:7.0.1 "/usr/local/bin/dock…" 8 minutes ago Up 8 minutes 9300/tcp, 127.0.0.1:31531->9200/tcp, 127.0.0.1:31531->9200/udp elasticsearch-697eb6d4-14b0-a766-c1da-fc3c59761929
If I curl that endpoint I get:
> curl 127.0.0.1:31531
curl: (56) Recv failure: Connection reset by peer
But, if I run that same curl command from within the docker container it returns the expected healthy elasticsearch response:
[root@e8712c2566c8 elasticsearch]# curl localhost:31531
{
"name" : "e8712c2566c8",
"cluster_name" : "elashticstack-cluster",
"cluster_uuid" : "mQfaXVSKR7el4oKOxj1hLw",
"version" : {
"number" : "7.0.1",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "e4efcb5",
"build_date" : "2019-04-29T12:56:03.145736Z",
"build_snapshot" : false,
"lucene_version" : "8.0.0",
"minimum_wire_compatibility_version" : "6.7.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
Additionally, I can curl the IP address assigned to it by docker (172.17.0.2 in this case) and get the same response from outside the container. I've been struggling with this for most of the past week and haven't made much progress beyond characterizing the issue I'm having a little more.
Some things I've tried:
Changing the http.host and network.host settings to NOMAD_IP_rest, 127.0.0.1 or commenting them out haven't changed much. One of those combinations made it so I could only curl 127.0.0.1 within the docker container instead of localhost, but the behavior from outside the container was unchanged.
Changing the nomad bind_addr to 0.0.0.0 had no effect on the port mappings shown in docker ps.
I've seen suggestions in other places to switch to host networking but I'd prefer not to do that. I'm trying to really learn how running an ELK stack in Nomad works so would like to be able to expand this to a more production-like configuration eventually and host networking wouldn't work in that case.
So, my question is what config am I missing/doing wrong that I can't connect to elasticsearch using localhost? Any help with that would be greatly appreciated.