Local Consul join K8s Consul Mac

1/17/2020

So I'm currently running on my local Kubernetes cluster (running on docker) the stable/consul chart from helm.

  $ helm install -n wet-fish --namespace consul stable/consul

This creates two services

==> v1/Service
NAME                TYPE       CLUSTER-IP      EXTERNAL-IP  PORT(S)                                                                           AGE
wet-fish-consul     ClusterIP  None            <none>       8500/TCP,8400/TCP,8301/TCP,8301/UDP,8302/TCP,8302/UDP,8300/TCP,8600/TCP,8600/UDP  0s
wet-fish-consul-ui  NodePort   10.110.229.223  <none>       8500:30276/TCP     

So this means I can run localhost:30276 and see the consul ui.

Now I'm running on my local machine

  $ consul agent -dev -config-dir=./consul.d -node=machine
  $ consul join 127.0.0.1:30276

This just results in:

Error joining address '127.0.0.1:30276': Unexpected response code: 500 (1 error occurred:
        * Failed to join 127.0.0.1: received invalid msgType (72), expected pushPullMsg (6) from=127.0.0.1:30276

)
Failed to join any nodes.

and

2020/01/17 15:17:35 [WARN] agent: (LAN) couldn't join: 0 Err: 1 error occurred:
        * Failed to join 127.0.0.1: received invalid msgType (72), expected pushPullMsg (6) from=127.0.0.1:30276

    2020/01/17 15:17:35 [ERR] http: Request PUT /v1/agent/join/127.0.0.1:30276, error: 1 error occurred:
        * Failed to join 127.0.0.1: received invalid msgType (72), expected pushPullMsg (6) from=127.0.0.1:30276

 from=127.0.0.1:59693

There must be a way to have a local consul agent running that can connect to the k8s consul server...

This is on a Mac, so networking isn't as good....

-- Callum Linington
consul
docker
kubernetes
kubernetes-helm

1 Answer

1/19/2020

There may be two problems here, the first is that consul agent -dev starts the agent in dev mode. By default dev mode is going to start both a server and an agent. This might be part of the reason behind the error.

The other problem could be due to localhost, the server running in Kubernetes will attempt to health check local agents. It needs to be able to ping the local agent, so even if you manage to join in the first step, it would probably fail health checks.

I agree about networking on Mac it does not make things easy, one thing you will probably have to do is set the advertise address for the local agent (non kube). Docker for mac has a host name docker.for.mac.localhost which is a routable ip to the local machine from a container. When starting the local agent if you set the advertise address to the ip value of that host Kubernetes Consul server should be able to route to the locally running agent.

Potential fix: 1. Ensure local agent is starting in client mode (manually configure not -dev) 2. Set advertise advertise address to an ip address which is routable from Kubernetes docker.for.mac.localhost

Give me a shout if that does not work for you, I have used a setup like this myself, 9/10 it is networking between Docker and the local machine.

Kind regards,

Nic

-- Nic Jackson
Source: StackOverflow