June 20-22 Announcing HashiConf Europe full schedule: keynotes, sessions, labs & more Register Now
  • Overview
    • Consul on Kubernetes
    • Control access with Consul API Gateway
    • Discover Services with Consul
    • Enforce Zero Trust Networking with Consul
    • Load Balancing with Consul
    • Manage Traffic with Consul
    • Multi-Platform Service Mesh with Consul
    • Network Infrastructure Automation with Consul
    • Observability with Consul
  • Enterprise
  • Tutorials
  • Docs
  • API
  • CLI
  • Community
GitHub
Download
Try HCP Consul
    • v1.12.x (latest)
    • v1.11.x
    • v1.10.x
    • v1.9.x
    • v1.8.x
    • Overview
      • Overview
      • What is a Service Mesh?
      • Overview
      • Chef, Puppet, etc.
      • Nagios
      • SkyDNS
      • SmartStack
      • Serf
      • Eureka
      • Istio
      • Envoy and Other Proxies
      • Custom Solutions
    • Overview
    • Manual Bootstrap
    • Consul Agent
    • Glossary
    • Required Ports
    • Bootstrapping a Datacenter
    • Cloud Auto-join
    • Server Performance
    • Kubernetes
  • API
  • Commands (CLI)
    • Register Services - Service Definitions
    • Find Services - DNS Interface
    • Monitor Services - Check Definitions
    • Overview
    • How Service Mesh Works
    • Configuration
      • Overview
      • Ingress Gateway
      • Mesh
      • Exported Services
      • Proxy Defaults
      • Service Defaults
      • Service Intentions
      • Service Resolver
      • Service Router
      • Service Splitter
      • Terminating Gateway
      • Overview
      • Envoy
      • Built-in Proxy
      • Proxy Integration
      • Managed (Deprecated)
      • Overview
      • Proxy Service Registration
      • Sidecar Service Registration
    • Service-to-service permissions - Intentions
    • Service-to-service permissions - Intentions (Legacy Mode)
    • Transparent Proxy
      • Overview
      • UI Visualization
      • Overview
      • Discovery Chain
    • Connectivity Tasks
    • Distributed Tracing
      • Overview
        • WAN Federation
        • Enabling Service-to-service Traffic Across Datacenters
        • Enabling Service-to-service Traffic Across Admin Partitions
      • Ingress Gateways
      • Terminating Gateways
    • Nomad
    • Kubernetes
      • Overview
      • Go Integration
      • Overview
      • Built-In CA
      • Vault
      • ACM Private CA
    • Develop and Debug
    • Security
    • Overview
    • Installation
    • Technical Specifications
    • Common Errors
    • Upgrades
    • Overview
    • Architecture
      • Installing Consul on Kubernetes
      • Installing Consul K8s CLI
        • Minikube
        • Kind
        • AKS (Azure)
        • EKS (AWS)
        • GKE (Google Cloud)
        • Red Hat OpenShift
        • Self Hosted Kubernetes
        • Consul Clients Outside Kubernetes
        • Consul Servers Outside Kubernetes
        • Single Consul Datacenter in Multiple Kubernetes Clusters
        • Consul Enterprise
        • Overview
        • Federation Between Kubernetes Clusters
        • Federation Between VMs and Kubernetes
        • Overview
        • Systems Integration
          • Overview
          • Bootstrap Token
          • Enterprise License
          • Gossip Encryption Key
          • Partition Token
          • Replication Token
          • Server TLS
          • Service Mesh Certificates
          • Snapshot Agent Config
        • WAN Federation
      • Compatibility Matrix
      • Overview
      • Transparent Proxy
      • Ingress Gateways
      • Terminating Gateways
      • Ingress Controllers
      • Configuring a Connect CA Provider
      • Health Checks
        • Metrics
    • Service Sync
      • Overview
      • Upgrade An Existing Cluster to CRDs
    • Annotations and Labels
    • Consul DNS
      • Upgrading Consul on Kubernetes
      • Upgrading Consul K8s CLI
      • Uninstall
      • Certificate Rotation
      • Gossip Encryption Key Rotation
      • Configure TLS on an Existing Cluster
      • Common Error Messages
      • FAQ
    • Helm Chart Configuration
    • Consul K8s CLI Reference
    • Overview
    • Requirements
    • Task Resource Usage
      • Installation
      • Secure Configuration
      • Migrate Existing Tasks
      • Installation
      • Secure Configuration
      • ACL Controller
    • Architecture
    • Consul Enterprise
    • Configuration Reference
    • Overview
      • Installation
      • Requirements
      • Configure
      • Run Consul-Terraform-Sync
    • Architecture
      • Overview
      • Status
      • Tasks
      • Overview
      • task
    • Configuration
    • Tasks
    • Terraform Modules
      • Overview
      • License
      • Terraform Cloud Driver
      • Overview
      • Terraform
      • Terraform Cloud
    • Compatibility
    • Consul KV
    • Sessions
    • Watches
    • Overview
      • General
      • CLI Reference
      • Configuration Reference
    • Configuration Entries
    • Telemetry
    • Sentinel
    • RPC
    • Overview
      • ACL System Overview
      • Tokens
      • Policies
      • Roles
      • Rules Reference
      • Legacy Mode
      • Token Migration
      • ACLs in Federated Datacenters
        • Overview
        • Kubernetes
        • JWT
        • OIDC
        • AWS IAM
    • Encryption
      • Overview
      • Core
      • Network Infrastructure Automation
    • Overview
    • Admin Partitions
    • Audit Logging
    • Automated Backups
    • Automated Upgrades
    • Enhanced Read Scalability
    • Single sign-on - OIDC
    • Redundancy Zones
    • Advanced Federation
    • Network Segments
    • Namespaces
    • NIA with TFE
    • Sentinel
      • Overview
      • FAQ
    • Overview
    • Improving Consul Resilience
    • Anti-Entropy
    • Consensus Protocol
    • Gossip Protocol
    • Jepsen Testing
    • Network Coordinates
    • Consul Integration Program
    • NIA Integration Program
    • Vault Integration
    • Proxy Integration
  • Consul Tools
    • Overview
    • Compatibility Promise
    • Specific Version Details
      • Overview
      • General Process
      • Upgrading to 1.2.4
      • Upgrading to 1.6.9
      • Upgrading to 1.8.13
      • Upgrading to 1.10.0
    • Common Error Messages
    • FAQ
    • Overview
      • v1.11.x
      • v1.10.x
      • v1.9.x
      • v0.1.x
      • v0.2.x
      • v0.4.x
      • v0.3.x
      • v0.2.x
      • v0.5.x
      • v0.6.0-beta
    • Overview
    • ACL
  • Guides
Type '/' to Search

»Installing Consul API Gateway

This topic describes how to use the Consul API Gateway add-on module. It includes instructions for installation and configuration.

»Requirements

Ensure that the environment you are deploying Consul API Gateway in meets the requirements listed in the Technical Specifications. This includes validating that the requirements for minimum versions of software are met. See the Release Notes for the version of API Gateway you are deploying.

»Installation

NOTE: When you see VERSION in examples of commands or configuration settings, replace VERSION with the version number of the release you are installing, like 0.2.0. If there is a lower case "v" in front of VERSION the version number needs to follow the "v" as is v0.2.0

  1. Issue the following command to install the CRDs:

    $ kubectl apply --kustomize="github.com/hashicorp/consul-api-gateway/config/crd?ref=vVERSION"
    
    $ kubectl apply --kustomize="github.com/hashicorp/consul-api-gateway/config/crd?ref=vVERSION"
    
  2. Create a values.yaml file for your Consul API Gateway deployment. Copy the content below into the values.yaml file. The values.yaml will be used by the Consul Helm chart. Available versions of the Consul and Consul API Gateway Docker images can be found on DockerHub, with additional context on version compatibility published in GitHub releases. See Helm Chart Configuration - apiGateway for more available options on how to configure your Consul API Gateway deployment via the Helm chart.

    global:
      name: consul
    connectInject:
      enabled: true
    controller:
      enabled: true
    apiGateway:
      enabled: true
      image: hashicorp/consul-api-gateway:VERSION
    
    values.yaml
    global:
      name: consul
    connectInject:
      enabled: true
    controller:
      enabled: true
    apiGateway:
      enabled: true
      image: hashicorp/consul-api-gateway:VERSION
    
  3. Install Consul API Gateway using the standard Consul Helm chart and specify the custom values file. Available versions of the Consul Helm chart can be found in GitHub releases.

    $ helm install consul hashicorp/consul --version 0.43.0 --values values.yaml --create-namespace --namespace consul
    
    $ helm install consul hashicorp/consul --version 0.43.0 --values values.yaml --create-namespace --namespace consul
    

»Usage

  1. Verify that the requirements have been met.

  2. Verify that the Consul API Gateway CRDs and controller have been installed and applied (see Installation).

  3. Configure the artifacts described below in Configuration.

    apiGateway:
      managedGatewayClass:
        enabled: true
    
    values.yaml
    apiGateway:
      managedGatewayClass:
        enabled: true
    
  4. Issue the kubectl apply command to implement the configurations, e.g.:

    $ kubectl apply -f gateway.yaml routes.yaml
    
    $ kubectl apply -f gateway.yaml routes.yaml
    

»Configuration

Configure the following artifacts to facilitate ingress into your Consul service mesh:

  • GatewayClassConfig: Describes additional Consul API Gateway-related configuration parameters for the GatewayClass resource.
  • GatewayClass: Defines a class of gateway resources that you can use as a template for creating gateways.
  • Gateway: Defines the main infrastructure resource that links API gateway components. It specifies the name of the GatewayClass and one or more listeners (see Listeners), which specify the logical endpoints bound to the gateway's addresses.
  • Routes: Specifies the path from the client to the listener.

Note: Add the following managedGatewayClass configuration to the values.yaml Helm configuration to enable the GatewayClassConfig and GatewayClass to be created automatically. The gateway, listeners, and routes will need to be configured manually. When managedGatewayClass is enabled, the serviceType for a managed GatewayClass will also default to LoadBalancer, which is appropriate for most deployments to managed Kubernetes cloud offerings (i.e., EKS, GKE, AKS). Other deployments, such as to a kind cluster, may require specifying NodePort or ClusterIP, instead.

»GatewayClassConfig

The GatewayClassConfig object describes Consul API Gateway-related configuration parameters for the GatewayClass.

Add the kind: GatewayClassConfig option to the gateway values file to declare a gateway class. The following example creates a gateway class configuration called test-gateway-class-config:

apiVersion: api-gateway.consul.hashicorp.com/v1alpha1
kind: GatewayClassConfig
metadata:
  name: test-gateway-class-config
spec:
  useHostPorts: true
  logLevel: 'trace'
  consul:
    scheme: 'https'
    ports:
      http: 8501
      grpc: 8502
gateway.yaml
apiVersion: api-gateway.consul.hashicorp.com/v1alpha1
kind: GatewayClassConfig
metadata:
  name: test-gateway-class-config
spec:
  useHostPorts: true
  logLevel: 'trace'
  consul:
    scheme: 'https'
    ports:
      http: 8501
      grpc: 8502

The following table describes the allowed parameters for the spec array:

ParameterDescriptionTypeDefault
consul.addressSpecifies the address of the Consul server to communicate with in the gateway pod. If unspecified, the pod will attempt to use a local agent on the host on which the pod is running.StringN/A
consul.authentication.accountSpecifies the Kubernetes service account to use for authentication.StringN/A
consul.authentication.managedSet to true to enable deployments to run with managed service accounts created by the gateway controller. The consul.authentication.account field is ignored when this option is enabled.Booleanfalse
consul.authentication.methodSpecifies the Consul auth method used for initial authentication by Consul API Gateway.StringN/A
consul.authentication.namespaceSpecifies the Consul namespace to use for authentication.StringN/A
consul.ports.grpcSpecifies the gRPC port for Consul's xDS server.Integer8502
consul.ports.httpSpecifies the port for Consul's HTTP server.Integer8500
consul.schemeSpecifies the scheme to use for connecting to Consul. The supported values are "http" and "https".String"http"
copyAnnotations.serviceList of annotations to copy to the gateway service.Array["external-dns.alpha.kubernetes.io/hostname"]
image.consulAPIGatewayThe image to use for consul-api-gateway. View available image tags on DockerHub.String"hashicorp/consul-api-gateway:RELEASE_VERSION"
image.envoySpecifies the container image to use for Envoy. View available image tags on DockerHub.String"envoyproxy/envoy:RELEASE_VERSION"
logLevelSpecifies the error reporting level for logs. You can specify the following values: error, warning, info, debug, trace.String"info"
nodeSelectorSpecifies a set of parameters that constrain the nodes on which the pod can run. Defining nodes with the nodeSelector enables the pod to fit on a node. The selector must match a node's labels for the pod to be scheduled on that node. Refer to the Kubernetes documentation for additional information.ObjectN/A
serviceTypeSpecifies the ingress methods for a service. The following values are supported:
ClusterIP
NodePort
LoadBalancer.
StringN/A
useHostPortsIf set to true, then the Envoy container ports are mapped to host ports.Booleanfalse

Refer to the Consul API Gateway repository for the complete specification.

»GatewayClass

The GatewayClass resource is used as a template for creating Gateway resources. The specification includes the name of the controller (controllerName) and an API object containing controller-specific configuration resources within the cluster (parametersRef). The value of the controllerName field must be set to hashicorp.com/consul-api-gateway-controller.

When gateways are created from a GatewayClass, they use the parameters specified in the GatewayClass at the time of instantiation.

Add the kind: GatewayClass option to the the gateway values file to declare a gateway class. The following example creates a gateway class called test-gateway-class:

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: GatewayClass
metadata:
  name: test-gateway-class
spec:
  controllerName: 'hashicorp.com/consul-api-gateway-controller'
  parametersRef:
    group: api-gateway.consul.hashicorp.com
    kind: GatewayClassConfig
    name: test-gateway-class-config
gateway.yaml
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: GatewayClass
metadata:
  name: test-gateway-class
spec:
  controllerName: 'hashicorp.com/consul-api-gateway-controller'
  parametersRef:
    group: api-gateway.consul.hashicorp.com
    kind: GatewayClassConfig
    name: test-gateway-class-config

Refer to the Kubernetes Gateway API documentation for details about configuring gateway classes.

»Gateway

The gateway configuration is the main infrastructure resource that links API gateway components. It specifies the name of the GatewayClass and one or more listeners.

Add the kind: Gateway option to the configuration file to declare a gateway. The following example creates a gateway called example-gateway. The gateway is based on the test-gateway-class and includes a listener called https (see Listeners for details about the listener configuration).

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: Gateway
metadata:
  name: example-gateway
  annotations:
    'external-dns.alpha.kubernetes.io/hostname': DNS_HOSTNAME
spec:
  gatewayClassName: test-gateway-class
  listeners:
    - protocol: HTTPS
      hostname: DNS_HOSTNAME
      port: 443
      name: https
      allowedRoutes:
        namespaces:
          from: Same
      tls:
        certificateRefs:
          - name: gateway-production-certificate
gateway.yaml
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: Gateway
metadata:
  name: example-gateway
  annotations:
    'external-dns.alpha.kubernetes.io/hostname': DNS_HOSTNAME
spec:
  gatewayClassName: test-gateway-class
  listeners:
    - protocol: HTTPS
      hostname: DNS_HOSTNAME
      port: 443
      name: https
      allowedRoutes:
        namespaces:
          from: Same
      tls:
        certificateRefs:
          - name: gateway-production-certificate

Refer to the Kubernetes Gateway API documentation for details about configuring gateways:

»Listeners

Listeners are the logical endpoints bound to the gateway's addresses. Add the listener object to the gateway configuration and specify the following properties to define a listener:

ParameterDescriptionTypeDefault
hostnameSpecifies the virtual hostname to match for protocol types.Stringnone
portSpecifies the network port number.Integernone
protocolSpecifies the network protocol expected by the listener.Stringhttp
tlsCollection of parameters that specify TLS options for the listener. Refer to the GatewayTLSConfig documentation for additional information about configuring TLS.ObjectN/A
tls.modeSpecifies a mode for operating Consul API Gateway listeners over TLS.
You can only specify the Terminate mode, which configures the TLS session between the downstream client and the gateway to terminate at the gateway.
Refer to the TLSModeType documentation for additional information.
StringTerminate
tls.certificateRefsSpecifies the name of secret object used for Envoy SDS (Secret Discovery Service) to support terminating TLS. Refer to the []*SecretObjectReference documentation for additional information.StringN/A
tls.optionsSpecifies key/value pairs to enable extended TLS configuration specific to an implementation.ObjectN/A
tls.options.tls_min_versionSpecifies the minimum TLS version supported for the listener. The following values are supported: TLS_AUTO, TLSv1_0, TLSv1_1, TLSv1_2, TLSv1_3.StringTLS 1.2
tls.options.tls_max_versionSpecifies the maximum TLS version supported for the listener. The specified version must be greater than or equal to TLSMinVersion. The following values are supported: TLS_AUTO, TLSv1_0, TLSv1_1, TLSv1_2, TLSv1_3.StringTLS 1.3
tls.options.tls_cipher_suitesSpecifies the list of TLS cipher suites to support when negotiating connections using TLS 1.2 or earlier.
If unspecified, a more secure set of cipher suites than Envoy's current default server cipher list will be used.
The full list of supported cipher suites can seen in internal/common/tls.go and is dependent on underlying support in Envoy.
StringSee description

Refer to the Kubernetes Gateway API documentation for details about configuring listeners.

»Route

Routes are independent configuration objects that are associated with specific listeners.

Declare a route with either kind: HTTPRoute or kind: TCPRoute and configure the route parameters in the spec block. Refer to the Kubernetes Gateway API documentation for each object type for details:

  • HTTPRoute
  • TCPRoute

The following example creates a route named example-route associated with a listener defined in example-gateway.

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
  name: example-route
spec:
  parentRefs:
    - name: example-gateway
  rules:
    - backendRefs:
        - kind: Service
          name: echo
          port: 8080
routes.yaml
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
  name: example-route
spec:
  parentRefs:
    - name: example-gateway
  rules:
    - backendRefs:
        - kind: Service
          name: echo
          port: 8080

To create a route for a backendRef in a different namespace, you must also create a ReferencePolicy.

The following example creates a route named example-route in namespace gateway-namespace. This route has a backendRef in namespace service-namespace. Traffic is allowed because the ReferencePolicy, named reference-policy in namespace service-namespace, allows traffic from HTTPRoutes in gateway-namespace to Services in service-namespace.

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
  name: example-route
  namespace: gateway-namespace
spec:
  parentRefs:
    - name: example-gateway
  rules:
    - backendRefs:
        - kind: Service
          name: echo
          namespace: service-namespace
          port: 8080
---

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: ReferencePolicy
metadata:
  name: reference-policy
  namespace: service-namespace
spec:
  from:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      namespace: gateway-namespace
  to:
    - group: ""
      kind: Service
      name: echo
route_with_referencepolicy.yaml
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
  name: example-route
  namespace: gateway-namespace
spec:
  parentRefs:
    - name: example-gateway
  rules:
    - backendRefs:
        - kind: Service
          name: echo
          namespace: service-namespace
          port: 8080
---

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: ReferencePolicy
metadata:
  name: reference-policy
  namespace: service-namespace
spec:
  from:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      namespace: gateway-namespace
  to:
    - group: ""
      kind: Service
      name: echo

»MeshService

The MeshService configuration holds a reference to an externally-managed Consul service mesh service and can be used as a backendRef for a Route.

ParameterDescriptionTypeDefault
nameSpecifies the service name for a Consul service. It is assumed this service will exist in either the consulDestinationNamespace or mirrored Consul namespace from where this custom resource is defined, depending on the Helm configuration.

Refer to the Consul API Gateway repository for the complete specification.

github logoEdit this page
IntroGuidesDocsCommunityPrivacySecurityBrandConsent Manager