|
| 1 | +// Modules included in the following assemblies: |
| 2 | +// |
| 3 | +// * networking/configuring_ingress_cluster_traffic/ingress-gateway-api.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="nw-ingress-gateway-api-enable_{context}"] |
| 7 | += Getting started with Gateway API for the Ingress Operator |
| 8 | + |
| 9 | +When you create a GatewayClass as shown in the first step, it configures Gateway API for use on your cluster. |
| 10 | + |
| 11 | +.Procedure |
| 12 | + |
| 13 | +. Create a `GatewayClass` object: |
| 14 | + |
| 15 | +.. Create a YAML file, `openshift-default.yaml`, that contains the following information: |
| 16 | ++ |
| 17 | +.Example `GatewayClass` CR |
| 18 | +[source,yaml] |
| 19 | +---- |
| 20 | +apiVersion: gateway.networking.k8s.io/v1 |
| 21 | +kind: GatewayClass |
| 22 | +metadata: |
| 23 | + name: openshift-default |
| 24 | +spec: |
| 25 | + controllerName: openshift.io/gateway-controller/v1 <1> |
| 26 | +---- |
| 27 | +<1> The controller name. |
| 28 | ++ |
| 29 | +[IMPORTANT] |
| 30 | +==== |
| 31 | +The controller name must be exactly as shown for the Ingress Operator to manage it. If you set this field to anything else, the Ingress Operator ignores the `GatewayClass` object and all associated `Gateway`, `GRPCRoute`, and `HTTPRoute` objects. The controller name is tied to the implementation of Gateway API in {product-title}, and `openshift.io/gateway-controller/v1` is the only controller name allowed. |
| 32 | +==== |
| 33 | + |
| 34 | +.. Run the following command to create the `GatewayClass` resource: |
| 35 | ++ |
| 36 | +[source,terminal] |
| 37 | +---- |
| 38 | +$ oc create -f openshift-default.yaml |
| 39 | +---- |
| 40 | ++ |
| 41 | +.Example output |
| 42 | +[source,terminal] |
| 43 | +---- |
| 44 | +gatewayclass.gateway.networking.k8s.io/openshift-default created |
| 45 | +---- |
| 46 | ++ |
| 47 | +During the creation of the `GatewayClass` resource, the Ingress Operator installs a lightweight version of {SMProductName}, an Istio custom resource, and a new deployment in the `openshift-ingress` namespace. |
| 48 | + |
| 49 | +.. Optional: Verify that the new deployment, `istiod-openshift-gateway` is ready and available: |
| 50 | ++ |
| 51 | +[source,terminal] |
| 52 | +---- |
| 53 | +$ oc get deployment -n openshift-ingress |
| 54 | +---- |
| 55 | ++ |
| 56 | +.Example output |
| 57 | +[source,terminal] |
| 58 | +---- |
| 59 | +NAME READY UP-TO-DATE AVAILABLE AGE |
| 60 | +istiod-openshift-gateway 1/1 1 1 55s |
| 61 | +router-default 2/2 2 2 6h4m |
| 62 | +---- |
| 63 | + |
| 64 | +. Create a secret by running the following command: |
| 65 | ++ |
| 66 | +[source,terminal] |
| 67 | +---- |
| 68 | +$ oc -n openshift-ingress create secret tls gwapi-wildcard --cert=wildcard.crt --key=wildcard.key |
| 69 | +---- |
| 70 | + |
| 71 | +. Get the domain of the Ingress Operator by running the following command: |
| 72 | ++ |
| 73 | +[source,terminal] |
| 74 | +---- |
| 75 | +$ DOMAIN=$(oc get ingresses.config/cluster -o jsonpath={.spec.domain}) |
| 76 | +---- |
| 77 | + |
| 78 | +. Create a `Gateway` object: |
| 79 | + |
| 80 | +.. Create a YAML file, `example-gateway.yaml`, that contains the following information: |
| 81 | ++ |
| 82 | +.Example `Gateway` CR |
| 83 | +[source,yaml] |
| 84 | +---- |
| 85 | +apiVersion: gateway.networking.k8s.io/v1 |
| 86 | +kind: Gateway |
| 87 | +metadata: |
| 88 | + name: example-gateway |
| 89 | + namespace: openshift-ingress <1> |
| 90 | +spec: |
| 91 | + gatewayClassName: openshift-default <2> |
| 92 | + listeners: |
| 93 | + - name: https <3> |
| 94 | + hostname: "*.gwapi.${DOMAIN}" <4> |
| 95 | + port: 443 |
| 96 | + protocol: HTTPS |
| 97 | + tls: |
| 98 | + mode: Terminate |
| 99 | + certificateRefs: |
| 100 | + - name: gwapi-wildcard <5> |
| 101 | + allowedRoutes: |
| 102 | + namespaces: |
| 103 | + from: All |
| 104 | +---- |
| 105 | +<1> The `Gateway` object must be created in the `openshift-ingress` namespace. |
| 106 | +<2> The `Gateway` object must reference the name of the previously created `GatewayClass` object. |
| 107 | +<3> The HTTPS listener listens for HTTPS requests that match a subdomain of the cluster domain. You use this listener to configure ingress to your applications by using Gateway API `HTTPRoute` resources. |
| 108 | +<4> The hostname must be a subdomain of the Ingress Operator domain. If you use a domain, the listener tries to serve all traffic in that domain. |
| 109 | +<5> The name of the previously created secret. |
| 110 | + |
| 111 | +.. Apply the resource by running the following command: |
| 112 | ++ |
| 113 | +[source,terminal] |
| 114 | +---- |
| 115 | +$ oc apply -f example-gateway.yaml |
| 116 | +---- |
| 117 | + |
| 118 | +.. Optional: When you create a `Gateway` object, {SMProductName} automatically provisions a deployment and service with the same name. Verify this by running the following commands: |
| 119 | +*** To verify the deployment, run the following command: |
| 120 | ++ |
| 121 | +[source,terminal] |
| 122 | +---- |
| 123 | +$ oc get deployment -n openshift-ingress example-gateway-openshift-default |
| 124 | +---- |
| 125 | ++ |
| 126 | +.Example output |
| 127 | +[source,terminal] |
| 128 | +---- |
| 129 | +NAME READY UP-TO-DATE AVAILABLE AGE |
| 130 | +example-gateway-openshift-default 1/1 1 1 25s |
| 131 | +---- |
| 132 | +*** To verify the service, run the following command: |
| 133 | ++ |
| 134 | +[source,terminal] |
| 135 | +---- |
| 136 | +$ oc get service -n openshift-ingress example-gateway-openshift-default |
| 137 | +---- |
| 138 | ++ |
| 139 | +.Example output |
| 140 | +[source,terminal] |
| 141 | +---- |
| 142 | +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 143 | +example-gateway-openshift-default LoadBalancer 10.1.2.3 <external_ipname> <port_info> 47s |
| 144 | +---- |
| 145 | + |
| 146 | +.. Optional: The Ingress Operator automatically creates a `DNSRecord` CR using the hostname from the listeners, and adds the label `gateway.networking.k8s.io/gateway-name=example-gateway`. Verify the status of the DNS record by running the following command: |
| 147 | ++ |
| 148 | +[source,terminal] |
| 149 | +---- |
| 150 | +$ oc -n openshift-ingress get dnsrecord -l gateway.networking.k8s.io/gateway-name=example-gateway -o yaml |
| 151 | +---- |
| 152 | ++ |
| 153 | +.Example output |
| 154 | +[source,yaml] |
| 155 | +---- |
| 156 | +kind: DNSRecord |
| 157 | + ... |
| 158 | +status: |
| 159 | + ... |
| 160 | + zones: |
| 161 | + - conditions: |
| 162 | + - message: The DNS provider succeeded in ensuring the record |
| 163 | + reason: ProviderSuccess |
| 164 | + status: "True" |
| 165 | + type: Published |
| 166 | + dnsZone: |
| 167 | + tags: |
| 168 | + ... |
| 169 | + - conditions: |
| 170 | + - message: The DNS provider succeeded in ensuring the record |
| 171 | + reason: ProviderSuccess |
| 172 | + status: "True" |
| 173 | + type: Published |
| 174 | + dnsZone: |
| 175 | + id: ... |
| 176 | +---- |
| 177 | + |
| 178 | +. Create an `HTTPRoute` resource that directs requests to your already-created namespace and application called `example-app/example-app`: |
| 179 | + |
| 180 | +.. Create a YAML file, `example-route.yaml`, that contains the following information: |
| 181 | ++ |
| 182 | +.Example `HTTPRoute` CR |
| 183 | +[source,yaml] |
| 184 | +---- |
| 185 | +apiVersion: gateway.networking.k8s.io/v1 |
| 186 | +kind: HTTPRoute |
| 187 | +metadata: |
| 188 | + name: example-route |
| 189 | + namespace: example-app-ns <1> |
| 190 | +spec: |
| 191 | + parentRefs: <2> |
| 192 | + - name: example-gateway |
| 193 | + namespace: openshift-ingress |
| 194 | + hostnames: ["example.gwapi.${DOMAIN}"] <3> |
| 195 | + rules: |
| 196 | + - backendRefs: <4> |
| 197 | + - name: example-app <5> |
| 198 | + port: 8443 |
| 199 | +---- |
| 200 | +<1> The namespace you are deploying your application. |
| 201 | +<2> This field must point to the `Gateway` object you previously configured. |
| 202 | +<3> The hostname must match the one specified in the `Gateway` object. In this case, the listeners use a wildcard hostname. |
| 203 | +<4> This field specifies the backend references that point to your service. |
| 204 | +<5> The name of the `Service` for your application. |
| 205 | + |
| 206 | +.. Apply the resource by running the following command: |
| 207 | ++ |
| 208 | +[source,terminal] |
| 209 | +---- |
| 210 | +$ oc apply -f example-route.yaml |
| 211 | +---- |
| 212 | ++ |
| 213 | +.Example output |
| 214 | +[source,terminal] |
| 215 | +---- |
| 216 | +httproute.gateway.networking.k8s.io/example-route created |
| 217 | +---- |
| 218 | + |
| 219 | +.Verification |
| 220 | + |
| 221 | +. Verify that the `Gateway` object is deployed and has the condition `Programmed` by running the following command: |
| 222 | ++ |
| 223 | +[source,terminal] |
| 224 | +---- |
| 225 | +$ oc wait -n openshift-ingress --for=condition=Programmed gateways.gateway.networking.k8s.io example-gateway |
| 226 | +---- |
| 227 | ++ |
| 228 | +.Example output |
| 229 | +[source,terminal] |
| 230 | +---- |
| 231 | +gateway.gateway.networking.k8s.io/example-gateway condition met |
| 232 | +---- |
| 233 | + |
| 234 | +. Send a request to the configured `HTTPRoute` object hostname: |
| 235 | ++ |
| 236 | +[source,terminal] |
| 237 | +---- |
| 238 | +$ curl -I --cacert <local cert file> https://example.gwapi.${DOMAIN}:443 |
| 239 | +---- |
0 commit comments