Consul Servers Outside of Kubernetes

If you have a Consul cluster already running, you can configure your Consul clients inside Kubernetes to join this existing cluster.

The below config.yaml file shows how to configure the Helm chart to install Consul clients that will join an existing cluster.

The global.enabled value first disables all chart components by default so that each component is opt-in. This allows us to only setup the client agents. We then opt-in to the client agents by setting client.enabled to true.

Next, client.exposeGossipPorts can be set to true or false depending on if you want the clients to be exposed on the Kubernetes internal node IPs (true) or their pod IPs (false).

Finally, client.join is set to an array of valid -retry-join values. In the example above, a fake cloud auto-join value is specified. This should be set to resolve to the proper addresses of your existing Consul cluster.

  1. # config.yaml
  2. global:
  3. enabled: false
  4. client:
  5. enabled: true
  6. # Set this to true to expose the Consul clients using the Kubernetes node
  7. # IPs. If false, the pod IPs must be routable from the external servers.
  8. exposeGossipPorts: true
  9. join:
  10. - 'provider=my-cloud config=val ...'

Networking: Note that for the Kubernetes nodes to join an existing cluster, the nodes (and specifically the agent pods) must be able to connect to all other server and client agents inside and outside of Kubernetes over LAN. If this isn’t possible, consider running a separate Consul cluster inside Kubernetes and federating it with your cluster outside Kubernetes. You may also consider adopting Consul Enterprise for network segments.

Configuring TLS with Auto-encrypt

Note: Consul on Kubernetes currently does not support external servers that require mutual authentication for the HTTPS clients of the Consul servers, that is when servers have either verify_incoming or verify_incoming_https set to true. As noted in the Security Model, that setting isn’t strictly necessary to support Consul’s threat model as it is recommended that all requests contain a valid ACL token.

Consul’s auto-encrypt feature allows clients to automatically provision their certificates by making a request to the servers at startup. If you would like to use this feature with external Consul servers, you need to configure the Helm chart with information about the servers so that it can retrieve the clients’ CA to use for securing the rest of the cluster. To do that, you must add the following values, in addition to the values mentioned above:

  1. global:
  2. tls:
  3. enabled: true
  4. enableAutoEncrypt: true
  5. externalServers:
  6. enabled: true
  7. hosts:
  8. - 'provider=my-cloud config=val ...'

In most cases, externalServers.hosts will be the same as client.join, however, both keys must be set because they are used for different purposes: one for Serf LAN and the other for HTTPS connections. Please see the reference documentation for more info. If your HTTPS port is different from Consul’s default 8501, you must also set externalServers.httpsPort.

Configuring ACLs

If you are running external servers with ACLs enabled, there are a couple of ways to configure the Helm chart to help initialize ACL tokens for Consul clients and consul-k8s components for you.

Manually Bootstrapping ACLs

If you would like to call the ACL bootstrapping API yourself or if your cluster has already been bootstrapped with ACLs, you can provide the bootstrap token to the Helm chart. The Helm chart will then use this token to configure ACLs for Consul clients and any consul-k8s components you are enabling.

First, create a Kubernetes secret containing your bootstrap token:

  1. kubectl create secret generic bootstrap-token --from-literal='token=<your bootstrap token>'

Then provide that secret to the Helm chart:

  1. global:
  2. acls:
  3. manageSystemACLs: true
  4. bootstrapToken:
  5. secretName: bootstrap-token
  6. secretKey: token

The bootstrap token requires the following minimal permissions:

Next, configure external servers. The Helm chart will use this configuration to talk to the Consul server’s API to create policies, tokens, and an auth method. If you are enabling Consul Connect, k8sAuthMethodHost should be set to the address of your Kubernetes API server so that the Consul servers can validate a Kubernetes service account token when using the Kubernetes auth method with consul login.

  1. externalServers:
  2. enabled: true
  3. hosts:
  4. - 'provider=my-cloud config=val ...'
  5. k8sAuthMethodHost: 'https://kubernetes.example.com:443'

Your resulting Helm configuration will end up looking similar to this:

  1. global:
  2. enabled: false
  3. acls:
  4. manageSystemACLs: true
  5. bootstrapToken:
  6. secretName: bootstrap-token
  7. secretKey: token
  8. client:
  9. enabled: true
  10. # Set this to true to expose the Consul clients using the Kubernetes node
  11. # IPs. If false, the pod IPs must be routable from the external servers.
  12. exposeGossipPorts: true
  13. join:
  14. - 'provider=my-cloud config=val ...'
  15. externalServers:
  16. enabled: true
  17. hosts:
  18. - 'provider=my-cloud config=val ...'
  19. k8sAuthMethodHost: 'https://kubernetes.example.com:443'

Bootstrapping ACLs via the Helm chart

If you would like the Helm chart to call the bootstrapping API and set the server tokens for you, then the steps are similar. The only difference is that you don’t need to set the bootstrap token. The Helm chart will save the bootstrap token as a Kubernetes secret.

  1. global:
  2. enabled: false
  3. acls:
  4. manageSystemACLs: true
  5. client:
  6. enabled: true
  7. # Set this to true to expose the Consul clients using the Kubernetes node
  8. # IPs. If false, the pod IPs must be routable from the external servers.
  9. exposeGossipPorts: true
  10. join:
  11. - 'provider=my-cloud config=val ...'
  12. externalServers:
  13. enabled: true
  14. hosts:
  15. - 'provider=my-cloud config=val ...'
  16. k8sAuthMethodHost: 'https://kubernetes.example.com:443'