Consul
Services overview
This topic provides overview information about services and how to make them discoverable in Consul when your network operates on virtual machines. If service mesh is enabled in your network, refer to the following articles for additional information about connecting services in a mesh:
Introduction
A service is an entity in your network that performs a specialized operation or set of related operations. In many contexts, a service is software that you want to make available to users or other programs with access to your network. Services can also refer to native Consul functionality, such as service mesh proxies and gateways, that enable you to establish connections between different parts of your network.
You can define and register services with Consul, which makes them discoverable to other services in the network. You can also define various types of health checks that perform several safety functions, such as allowing a web balancer to gracefully remove failing nodes and allowing a database to replace a failed secondary.
Workflow
For service discovery, the core Consul workflow for services consists of three stages:
Define services and health checks: A service definition lets you define various aspects of the service, including how it is discovered by other services in the network. You can define health checks in the service definitions to verify the health of the service. Refer to Define Services and Define Health Checks for additional information.
Register services and health checks: After defining your services and health checks, you must register them with a Consul agent. Refer to Register Services and Health Checks for additional information.
Query for services: After registering your services and health checks, other services in your network can use the DNS to perform static or dynamic lookups to access your service. Refer to DNS Usage Overview for additional information about the different ways to discover services in your datacenters.
Service mesh use cases
Consul redirects service traffic through sidecar proxies if you use Consul service mesh. As a result, you must specify upstream configurations in service definitions. The service mesh experience is different for virtual machine (VM) and Kubernetes environments.
Virtual machines
You must define upstream services in the service definition. Consul uses the upstream configuration to bind the service with its upstreams. After registering the service, you must start a sidecar proxy on the VM to enable mesh connectivity. Refer to Deploy sidecar services for additional information.
Kubernetes
If you use Consul on Kubernetes, enable the service mesh injector in your Consul Helm chart and Consul automatically adds a sidecar to each of your pods using the Kubernetes Service
definition as a reference. You can specify upstream annotations in the Deployment
definition to bind upstream services to the pods.
Refer to connectInject
and the upstreams annotation documentation for additional information.
Multiple services
You can define common characteristics for services in your mesh, such as the admin partition, namespace, or upstreams, by creating and applying a service-defaults
configuration entry. You can also define override configurations for specific upstreams or service instances. To use service-defaults
configuration entries, you must enable Consul service mesh in your network.
Refer to Define Service Defaults for additional information.