"Requested address is not valid" trying to access Consul server in K8S from client outside K8S

6/18/2019

I have a K8S cluster (running Linux) in Stratoscale's Symphony. It has a cluster IP address IP1, assigned by Symphony. I've installed Consul in the cluster. I'm able to 'put' a Consul KV key in one pod (through the command-line interface available from the pod's web page) and 'get' it from another. The K8S Consul service called 'consul-consul-server' has this spec, as far as the ports are concerned:

{
  "kind": "Service",
  "metadata": {
    "name": "consul-consul-server",
    "namespace": "consul",
    ...
  },
  "spec": {
    "ports": [
      {
        "name": "http",
        "protocol": "TCP",
        "port": 8500,
        "targetPort": 8500,
        "nodePort": 30323
      },
      {
        "name": "serflan-tcp",
        "protocol": "TCP",
        "port": 8301,
        "targetPort": 8301,
        "nodePort": 31056
      },
      {
        "name": "serflan-udp",
        "protocol": "UDP",
        "port": 8301,
        "targetPort": 8301,
        "nodePort": 31056
      },
      {
        "name": "serfwan-tcp",
        "protocol": "TCP",
        "port": 8302,
        "targetPort": 8302,
        "nodePort": 30717
      },
      {
        "name": "serfwan-udp",
        "protocol": "UDP",
        "port": 8302,
        "targetPort": 8302,
        "nodePort": 30717
      },
      {
        "name": "server",
        "protocol": "TCP",
        "port": 8300,
        "targetPort": 8300,
        "nodePort": 32091
      },
      {
        "name": "dns-tcp",
        "protocol": "TCP",
        "port": 8600,
        "targetPort": "dns-tcp",
        "nodePort": 31688
      },
      {
        "name": "dns-udp",
        "protocol": "UDP",
        "port": 8600,
        "targetPort": "dns-udp",
        "nodePort": 31688
      }
    ],
    "selector": {
      "app": "consul",
      "component": "server",
      "release": "consul"
    },
    "clusterIP": "10.104.86.253",
    "type": "NodePort",
    "externalTrafficPolicy": "Cluster",
  },
  "status": {
    "loadBalancer": {}
  }
}

How do I start the Consul client agent from the command-line from outside the cluster? Based on what I read in https://www.consul.io/docs/agent/cloud-auto-join.html#kubernetes-k8s-, I tried the following:

consul agent -retry-join "provider=k8s namespace=consul label_selector=\"app=consul,component=server\" host_network=true" -client=<IP1> -bind=<LocalIP> -join=<IP1> -config-file=C:\Config\consul.hcl -server-port=32091

and a few other combinations but they all result in this error:

==> Starting Consul agent...
==> Error starting agent: 2 errors occurred:
        * listen udp 161.92.250.34:8600: bind: The requested address is not valid in its context.
        * listen tcp 161.92.250.34:8600: bind: The requested address is not valid in its context.

Any idea what I'm doing wrong? Thanks in advance.

-- Venkatesh MC
consul
kubernetes

1 Answer

6/21/2019

It turns out that I should've called "consul agent -retry-join" differently:

consul agent --retry-join=<IP1>:8500 -bind=<LocalIP>

This worked for me.

-- Venkatesh MC
Source: StackOverflow