Annotations and Labels

Overview

Consul on Kubernetes provides a few options for customizing how connect-inject or service sync behavior should be configured. This allows the user to configure natively configure Consul on select Kubernetes resources (i.e. pods, services).

The noun connect is used throughout this documentation to refer to the connect subsystem that provides Consul’s service mesh capabilities.

Consul Service Mesh

Annotations

The following Kubernetes resource annotations could be used on a pod to control connect-inject behavior:

Labels

Resource labels could be used on a Kubernetes service to control connect-inject behavior.

  • consul.hashicorp.com/service-ignore - This label can be set on a Kubernetes Service. If set to “true”, the service will not be used to register a Consul endpoint. This can be useful in cases where 2 or more services point to the same deployment. Consul cannot register multiple endpoints to the same deployment. This label can be used to tell the endpoint registration to ignore all services except for the one which should be used for routing requests using Consul.

Service Sync

Annotations

The following Kubernetes resource annotations could be used on a pod to Service Sync behavior:

  • consul.hashicorp.com/service-sync: If this is set to true, then the Kubernetes service is explicitly configured to be synced to Consul.

    1. annotations:
    2. 'consul.hashicorp.com/service-sync': 'true'
  • consul.hashicorp.com/service-port: Configures the port to register to the Consul Catalog for the Kubernetes service. The annotation value may be a name of a port (recommended) or an exact port value. Refer to service ports for more information.

    1. annotations:
    2. 'consul.hashicorp.com/service-port': 'http'
  • consul.hashicorp.com/service-tags: A comma separated list of strings (without whitespace) to use for registering tags to the service registered to Consul. These custom tags automatically include the k8s tag which can’t be disabled.

    1. annotations:
    2. 'consul.hashicorp.com/service-tags': 'primary,foo'
  • consul.hashicorp.com/service-meta-KEY: A map for specifying service metadata for Consul services. The “KEY” below can be set to any key. This allows you to set multiple meta values.

    1. annotations:
    2. 'consul.hashicorp.com/service-meta-KEY': 'value'
  • consul.hashicorp.com/service-weight: - Configures ability to support weighted loadbalancing by service annotation for Catalog Sync. The integer provided will be applied as a weight for the passing state for the health of the service. Refer to weights in service configuration for more information on how this is leveraged for services in the Consul catalog.

    1. annotations:
    2. consul.hashicorp.com/service-weight: 10