// Module included in the following assemblies:
//
// * networking/ingress_load_balancing/configuring_ingress_cluster_traffic/assigning-network-addresses-gateways.adoc
//
:_mod-docs-content-type: PROCEDURE
[id="configuring-automatic-address-assignment-gateway_{context}"]
= Configure automatic address assignment for a gateway

[role="_abstract"]
When you create a gateway resource, you must configure it for automatic address provisioning to successfully deploy the gateway without violating {product-title} manual address constraints. By intentionally omitting the addresses field, you allow the controller to seamlessly provision and bind the necessary external network addresses to your gateway.

.Prerequisites

* You have access to the cluster as a user with the `cluster-admin` role.
* You have installed the {oc-first}.
* You have an existing `GatewayClass` resource, such as `openshift-default`.

.Procedure

. Create a YAML file, such as `hello-gateway.yaml`, that defines your `Gateway` object without the addresses field:
+
[source,yaml]
----
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: sample-gateway
  namespace: openshift-ingress
spec:
  gatewayClassName: openshift-default
  listeners:
  - name: http
    hostname: "*.gwapi.<cluster_domain>" 
    port: 80
    protocol: HTTP
    allowedRoutes:
      namespaces:
        from: All
----
+
* `metadata.name`: The name of your `Gateway` object. The name must consist of a maximum of 63 lowercase alphanumeric characters or hyphens (`-`). The name must also start and end with an alphanumeric character.
* Replace `<cluster_domain>` with your actual cluster ingress domain (for example, `example.com`). 
* The `spec.addresses` field is omitted from this configuration to ensure automatic assignment.
* The `gatewayClassName` dictates which controller provisions the address and populates the `status.addresses` field.

. Apply the `Gateway` configuration by running the following command:
+
[source,terminal]
----
$ oc apply -f hello-gateway.yaml
----

. Verify that the controller automatically assigned an address to your gateway by running the following command:
+
[source,terminal]
----
$ oc -n openshift-ingress get gateway sample-gateway
----
+
.Example output
[source,terminal]
----
NAME             CLASS               ADDRESS             PROGRAMMED   AGE
sample-gateway   openshift-default   <gateway_address>   True         6m16s
----
+
The `ADDRESS` column in the output displays the dynamically provisioned network address for your gateway.