Kubernetes Gateway API
The Gateway APIs do not come installed by default on most Kubernetes clusters. Install the Gateway API CRDs if they are not present:
Install Istio using the profile:
$ istioctl install --set profile=minimal -y
Differences from Istio APIs
The Gateway APIs share a lot of similarities to the Istio APIs such as Gateway and VirtualService. The main resource shares the same name, Gateway
, and the resources serve similar goals.
The new Gateway APIs aim to take the learnings from various Kubernetes ingress implementations, including Istio, to build a standardized vendor neutral API. These APIs generally serve the same purposes as Istio Gateway and VirtualService, with a few key differences:
- In Istio APIs, a
Gateway
configures an existing gateway Deployment/Service that has been deployed. In the Gateway APIs, theGateway
resource both configures and deploys a gateway. See for more information. - In the Istio
VirtualService
, all protocols are configured within a single resource. In the Gateway APIs, each protocol type has its own resource, such asHTTPRoute
andTCPRoute
. - While the Gateway APIs offer a lot of rich routing functionality, it does not yet cover 100% of Istio’s feature set. Work is ongoing to extend the API to cover these use cases, as well as utilizing the APIs extensibility to better expose Istio functionality.
See the Gateway API documentation for information about the APIs.
In this example, we will deploy a simple application and expose it externally using a Gateway
.
First, deploy the
httpbin
test application:$ kubectl apply -f @samples/httpbin/httpbin.yaml@
Deploy the Gateway API configuration including a single exposed route (i.e.,
/get
):$ kubectl create namespace istio-ingress
$ kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: Gateway
metadata:
name: gateway
namespace: istio-ingress
spec:
gatewayClassName: istio
listeners:
- name: default
hostname: "*.example.com"
port: 80
protocol: HTTP
allowedRoutes:
namespaces:
from: All
---
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
name: http
namespace: default
spec:
parentRefs:
- name: gateway
hostnames: ["httpbin.example.com"]
rules:
- matches:
- path:
type: PathPrefix
value: /get
backendRefs:
- name: httpbin
port: 8000
EOF
Access the
httpbin
service using curl:$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST/get"
server: istio-envoy
...
Note the use of the
-H
flag to set the Host HTTP header to “httpbin.example.com”. This is needed because theHTTPRoute
is configured to handle “httpbin.example.com”, but in your test environment you have no DNS binding for that host and are simply sending your request to the ingress IP.Access any other URL that has not been explicitly exposed. You should see an HTTP 404 error:
$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST/headers"
HTTP/1.1 404 Not Found
...
Update the route rule to also expose
/headers
and to add a header to the request:$ kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
name: http
namespace: default
spec:
parentRefs:
- name: gateway
namespace: istio-ingress
hostnames: ["httpbin.example.com"]
rules:
- matches:
- path:
type: PathPrefix
value: /get
- path:
type: PathPrefix
value: /headers
filters:
- type: RequestHeaderModifier
requestHeaderModifier:
- name: my-added-header
value: added-value
backendRefs:
- name: httpbin
port: 8000
EOF
Access
/headers
again and notice headerMy-Added-Header
has been added to the request:
Deployment methods
In the example above, you did not need to install an ingress gateway Deployment
prior to configuring a Gateway. In the default configuration, a gateway Deployment
and Service
is automatically provisioned based on the Gateway
configuration. For advanced use cases, manual deployment is still allowed.
By default, each Gateway
will automatically provision a Service
and Deployment
of the same name. These configurations will be updated automatically if the Gateway
changes (for example, if a new port is added).
These resources can be customized in a few ways:
Annotations and labels on the
Gateway
will be copied to theService
andDeployment
. This allows configuring things such as Internal load balancers that read from these fields.The
Service.spec.loadBalancerIP
field can be explicit set by configuring theaddresses
field:apiVersion: gateway.networking.k8s.io/v1alpha2
kind: Gateway
metadata:
name: gateway
spec:
addresses:
- value: 192.0.2.0
type: IPAddress
...
Note: only one address may be specified.
- (Advanced) The generated Pod configuration can be configured by .
Manual Deployment
If you do not want to have an automated deployment, a Deployment
and Service
can be .
When this option is done, you will need to manually link the Gateway
to the Service
, as well as keep their port configuration in sync.
To link a Gateway
to a Service
, configure the addresses
field to point to a single Hostname
.
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: Gateway
metadata:
name: gateway
spec:
addresses:
- value: ingress.istio-gateways.svc.cluster.local
type: Hostname
...
This feature is under development and pending .
The Gateway API can also be used to configure mesh traffic. This is done by configuring the parentRef
, to point to the istio
Mesh
. This resource does not actually exist in the cluster and is only used to signal that the Istio mesh should be used.
For example, to redirect calls to example.com
to an in-cluster Service
named example
:
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
name: mesh
spec:
parentRefs:
- kind: Mesh
name: istio
hostnames: ["example.com"]
rules:
- backendRefs:
- name: example
port: 80
Cleanup
Uninstall Istio and the sample: