> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Gateways

> Overview of Istio Gateways, explaining ingress and egress roles, TLS termination, routing with Gateways, VirtualService and DestinationRule, configuration examples, and traffic flow

A Gateway in Istio is the entry and exit point between the service mesh and the outside world. Gateways are optional — if your workloads only communicate inside the mesh, you may not need one. For internal routing, a VirtualService alone is often sufficient.

Gateways let you:

* Expose services to external clients (Ingress Gateway).
* Control and centralize outbound traffic from the mesh (Egress Gateway).
* Perform TLS termination, protocol handling, and host/port binding at the mesh boundary.

When to use a Gateway

* Use an Ingress Gateway to expose services to external users or APIs.
* Use an Egress Gateway to centralize outbound policies, logging, or TLS for traffic leaving the mesh.
* Skip Gateways if services are internal-only and no external exposure or control is required.

Types of Gateways

| Gateway Type    | Purpose                                | Typical Use Case                                     |
| --------------- | -------------------------------------- | ---------------------------------------------------- |
| Ingress Gateway | Manages incoming traffic to the mesh   | Expose web services to the public (HTTP(S), gRPC)    |
| Egress Gateway  | Manages outgoing traffic from the mesh | Centralize outbound TLS, logging, or egress policies |

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/zDpSzOByf0QVxNkX/images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/egress-gateway-kubernetes-namespace-pods-diagram.jpg?fit=max&auto=format&n=zDpSzOByf0QVxNkX&q=85&s=2a75c518001f03a3a87e1efdccd39542" alt="A schematic diagram titled &#x22;Egress Gateway&#x22; showing a Kubernetes namespace with deployments, pods/containers and a service, with dashed arrows routing outgoing traffic to an external Egress Gateway (cloud) icon." width="1920" height="1080" data-path="images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/egress-gateway-kubernetes-namespace-pods-diagram.jpg" />
</Frame>

Enabling Gateways via Istio Operator

You choose which gateways to enable when installing Istio. Profiles (such as `default`, `demo`, `minimal`, `remote`, `empty`, `preview`, and `ambient`) include different core components. For example, the `demo` profile commonly includes both ingress and egress gateways, while `minimal` might include only ingress.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/zDpSzOByf0QVxNkX/images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/istio-profile-core-components-chart.jpg?fit=max&auto=format&n=zDpSzOByf0QVxNkX&q=85&s=b4a62538ef2ecd3ec4aac07657ef5c51" alt="A chart titled &#x22;Istio Profile Core Components&#x22; showing rows for components like istio-egressgateway, istio-ingressgateway, istiod, CNI and Ztunnel and columns for profiles (default, demo, minimal, remote, empty, preview, ambient). Green checkmarks in the cells indicate which components are included in each profile." width="1920" height="1080" data-path="images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/istio-profile-core-components-chart.jpg" />
</Frame>

After installation, verify gateway pods in the Istio system namespace with:

* kubectl get pods -n istio-system

You will see Envoy-based pods for ingress (and egress if enabled). Gateways are selected by label selectors configured in Gateway resources, so make sure selectors match the labels on those pods.

<Callout icon="warning" color="#FF6B6B">
  Ensure the Gateway selector matches the label on the gateway pods. Common labels are `istio=ingressgateway` or `istio=egressgateway` (labels vary by installation). If the selector is incorrect, the Gateway resource will not be bound to the gateway pods and external traffic will not be routed.
</Callout>

TLS termination, protocols, and routing

Gateways commonly perform TLS termination (managing encryption/decryption and certificates) and support multiple protocols: HTTP(S), TCP, and gRPC. Gateways can route traffic based on ports, headers, and URL paths, but most advanced routing rules are defined in VirtualService objects.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/zDpSzOByf0QVxNkX/images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/tls-termination-ingress-kubernetes-service-pods.jpg?fit=max&auto=format&n=zDpSzOByf0QVxNkX&q=85&s=195fe7ff3c26d131faf2a19d77f1fe3e" alt="A diagram titled &#x22;TLS Termination&#x22; showing an ingress gateway forwarding encrypted traffic into a Kubernetes namespace to a service, replica set and deployment that route to multiple pods and containers. Lock icons indicate where TLS encryption/decryption occurs." width="1920" height="1080" data-path="images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/tls-termination-ingress-kubernetes-service-pods.jpg" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/zDpSzOByf0QVxNkX/images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/protocols-http-tcp-grpc-routing.jpg?fit=max&auto=format&n=zDpSzOByf0QVxNkX&q=85&s=839b493b8d4192ac00c5cc5b82079ee9" alt="A slide titled &#x22;Protocols&#x22; with three colored boxes labeled HTTP/S, TCP, and gRPC. Each box briefly explains routing: HTTP/S routes HTTP traffic, TCP routes based on TCP connections, and gRPC routes traffic based on gRPC calls." width="1920" height="1080" data-path="images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/protocols-http-tcp-grpc-routing.jpg" />
</Frame>

Key configuration objects

* Gateway — declares ports, protocols, hostnames to listen on and uses a selector to target gateway pods.
* VirtualService — defines routing rules (host, path, headers) and is how you bind Gateway traffic to services.
* DestinationRule — optional for basic routing but required for subsets, load balancing policies, connection pools, or TLS settings.

Comparison at a glance:

| Resource        | Primary Responsibility                                       | Required to expose service externally?        |
| --------------- | ------------------------------------------------------------ | --------------------------------------------- |
| Gateway         | Bind Envoy gateway pods to ports/protocols/hosts             | Yes (for external traffic)                    |
| VirtualService  | Route traffic to service destinations and define match rules | No (can work for internal-only)               |
| DestinationRule | Configure subsets, LB, TLS for destinations                  | No (but needed for subsets/advanced features) |

Example: VirtualService + DestinationRule (internal routing and traffic-splitting)

```yaml theme={null}
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: ingress-app-vs
  namespace: frontend
spec:
  hosts:
  - app-svc
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        host: app-svc.frontend.svc.cluster.local
        port:
          number: 80
        subset: v1
      weight: 50
    - destination:
        host: app-svc.frontend.svc.cluster.local
        port:
          number: 80
        subset: v2
      weight: 50
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: app-ds
  namespace: frontend
spec:
  host: app-svc
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
```

Expose the service externally: Gateway + VirtualService

A Gateway resource defines which ports, hosts, and protocols the gateway listens on and must target gateway pods via a selector. Example (Ingress Gateway):

```yaml theme={null}
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: ingress-app-gateway
  namespace: istio-system
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - app.example.com
```

Notes:

* The `selector` above targets ingress gateway pods in the `istio-system` namespace. If your installation used a different label (for example `istio=ingress`), change the selector accordingly.
* For production, use port `443` and HTTPS with proper `tls` server settings.

Bind the Gateway to routes by referencing it from a VirtualService. Place the VirtualService in the same namespace as the Gateway to refer to it by name, or prefix with the namespace when in another namespace.

```yaml theme={null}
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: ingress-app-vs
  namespace: istio-system
spec:
  hosts:
  - app-svc
  - "app.example.com"
  gateways:
  - ingress-app-gateway
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        host: app-svc.frontend.svc.cluster.local
        port:
          number: 80
        subset: v1
      weight: 50
    - destination:
        host: app-svc.frontend.svc.cluster.local
        port:
          number: 80
        subset: v2
      weight: 50
```

* `app-svc` allows internal service-to-service routing rules to match.
* `"app.example.com"` applies the same routing for external requests coming through the Gateway.

Incoming traffic flow (high level)

1. External client sends HTTP/HTTPS to the Ingress Gateway public IP (e.g., `app.example.com`).
2. The Ingress Gateway (Envoy) receives the request and optionally terminates TLS.
3. Envoy uses the Gateway configuration to determine port/protocol handling.
4. The request is matched by a VirtualService (host/path) to select routing.
5. Traffic is forwarded to the Kubernetes Service and then to the target pods.
6. The service responds and the response flows back to the client.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/zDpSzOByf0QVxNkX/images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/incoming-traffic-ingress-envoy-virtualservice-workload.jpg?fit=max&auto=format&n=zDpSzOByf0QVxNkX&q=85&s=eed9a8f1dc9d19112f76cdf3044e82a3" alt="A flowchart titled &#x22;Incoming Traffic Flow&#x22; that diagrams how an external HTTP/HTTPS request travels through an Ingress Gateway and Envoy proxy, consults a Virtual Service, and is forwarded to a workload. The final step shows the service processing the request and sending a response." width="1920" height="1080" data-path="images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/incoming-traffic-ingress-envoy-virtualservice-workload.jpg" />
</Frame>

Important relationships

* A Gateway needs a corresponding VirtualService to route traffic into the mesh.
* A VirtualService can operate without a Gateway for internal routing.
* DestinationRules are optional for simple routing but required when using subsets, load balancing, or connection pool/TLS settings.

Egress Gateway (outgoing traffic control)

An Egress Gateway centralizes outbound traffic control and is useful for logging, monitoring, policy enforcement, and centralized TLS. You can allow specific outbound hosts or use a wildcard to permit all.

Example Egress Gateway allowing HTTP and HTTPS:

```yaml theme={null}
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: egress-app-gateway
  namespace: istio-system
spec:
  selector:
    istio: egressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
  - port:
      number: 443
      name: https
      protocol: HTTPS
    hosts:
    - "*"
```

Using `"*"` in `hosts` permits outbound connections to any host (subject to additional mesh policies). Restrict outbound traffic by listing specific hostnames instead of `"*"` when required.

To force traffic through the egress gateway:

* Create a ServiceEntry (if the external host is not part of the mesh DNS) to allow mesh resolution/reachability.
* Create a VirtualService that references the egress Gateway (use `namespace/gateway-name` if in different namespaces).

Example VirtualService that forces traffic to `api.example.com` through the egress gateway:

```yaml theme={null}
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: egress-app-vs
  namespace: frontend
spec:
  hosts:
  - api.example.com
  gateways:
  - istio-system/egress-app-gateway
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        host: api.example.com
        port:
          number: 443
```

Outgoing traffic flow (high level)

1. A workload's sidecar Envoy intercepts outbound traffic.
2. The VirtualService routing rules send matching outbound requests to the Egress Gateway.
3. The Egress Gateway applies policies, logging, and TLS, then forwards the request to the external service.
4. Responses return via the Egress Gateway back to the originating workload.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/zDpSzOByf0QVxNkX/images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/outgoing-traffic-envoy-egress-gateway-flow.jpg?fit=max&auto=format&n=zDpSzOByf0QVxNkX&q=85&s=168f61b7319da39b38c1dd4aeb1dc65c" alt="A slide titled &#x22;Outgoing Traffic Flow&#x22; showing a four-step flow diagram: Envoy proxy intercepts outbound traffic, routes it to an Egress Gateway which processes the request, and the gateway handles the external client response." width="1920" height="1080" data-path="images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/outgoing-traffic-envoy-egress-gateway-flow.jpg" />
</Frame>

Gateway configuration notes

There are fewer configuration options on Gateways than on VirtualServices or DestinationRules, but Gateways support:

* TLS modes and `serverTLSSettings`
* Port and protocol definitions
* Host binding and redirects

Consult the Istio Gateway reference for full options and examples.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/zDpSzOByf0QVxNkX/images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/istio-gateway-options-tls-port-slide.jpg?fit=max&auto=format&n=zDpSzOByf0QVxNkX&q=85&s=4f7400e818e8bdef289ce0e185cf98a0" alt="A presentation slide titled &#x22;Gateway Options&#x22; containing documentation-style boxes and tables that describe Gateway, TLS mode, Port, and ServerTLSSettings (Istio networking configuration). The slide includes a KodeKloud copyright and a link to istio.io at the bottom." width="1920" height="1080" data-path="images/Prep-Course-Istio-Certified-Associate-ICA-Certification/Traffic-Management/Gateways/istio-gateway-options-tls-port-slide.jpg" />
</Frame>

<Callout icon="lightbulb" color="#1CB2FE">
  Tip: Review the "Reference: Networking — Gateway" section in the Istio docs for examples on `tls` settings, `serverTLSSettings`, and protocol handling: [https://istio.io/latest/docs/reference/config/networking/gateway/](https://istio.io/latest/docs/reference/config/networking/gateway/). Understanding Gateway selectors, servers, and how VirtualService integrates with Gateways is key for deployment and certification exams.
</Callout>

Summary

This article covered:

* What Istio Gateways are and when to use them.
* Differences between Ingress and Egress Gateways and how they integrate with VirtualService and DestinationRule.
* Example YAMLs for VirtualService, DestinationRule, Ingress Gateway, and Egress Gateway.
* High-level incoming and outgoing traffic flows and configuration considerations.

Next steps

* Practice configuring a Gateway + VirtualService end-to-end.
* Test TLS termination and host/path-based routing.
* Explore ServiceEntry + Egress Gateway patterns for controlled outbound access.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/istio-certified-associate/module/f3f5ca4b-b8d6-4788-9553-9ed765709933/lesson/0ebb40cd-28de-4216-9dc7-9aa26eb3640d" />
</CardGroup>
