|
| 1 | +# Gateway API |
| 2 | +Gateway API is included since MicroShift 4.18 as a dev preview feature, meaning limited suport. In order to use the feature let's see the basic use case to enable it in your applications. |
| 3 | +The example listed here is the same as [basic north/south use case](https://gateway-api.sigs.k8s.io/concepts/use-cases/#basic-northsouth-use-case) except for TLS and DNS, not included for simplicity. |
| 4 | + |
| 5 | +> Gateway API is based on OpenShift Service Mesh 3. There is no support for service mesh capabilities outside the ones mentioned here. |
| 6 | +
|
| 7 | +## Installing |
| 8 | +Gateway API functionality is released as a separate RPM in the same way as other optional components, such as OLM or Multus. To install it you only need to do: |
| 9 | +```bash |
| 10 | +$ sudo dnf install -y microshift-gateway-api |
| 11 | +``` |
| 12 | +There is also a separate RPM package with the release information: |
| 13 | +```bash |
| 14 | +$ sudo dnf install -y microshift-gateway-api-release-info |
| 15 | +``` |
| 16 | +For the purpose of this document only the first RPM is required. |
| 17 | + |
| 18 | +> Please note the RPM was released alongside MicroShift 4.18. |
| 19 | +
|
| 20 | +## Verifying the install |
| 21 | +Once installed you should be able to see the gateway api resources in the api server: |
| 22 | +```bash |
| 23 | +# Available resources for gateway api functionality. Note that not all of these are used/supported. |
| 24 | +$ oc api-resources | egrep "istio|gateway" |
| 25 | +wasmplugins extensions.istio.io/v1alpha1 true WasmPlugin |
| 26 | +gatewayclasses gc gateway.networking.k8s.io/v1 false GatewayClass |
| 27 | +gateways gtw gateway.networking.k8s.io/v1 true Gateway |
| 28 | +grpcroutes gateway.networking.k8s.io/v1 true GRPCRoute |
| 29 | +httproutes gateway.networking.k8s.io/v1 true HTTPRoute |
| 30 | +referencegrants refgrant gateway.networking.k8s.io/v1beta1 true ReferenceGrant |
| 31 | +destinationrules dr networking.istio.io/v1 true DestinationRule |
| 32 | +envoyfilters networking.istio.io/v1alpha3 true EnvoyFilter |
| 33 | +gateways gw networking.istio.io/v1 true Gateway |
| 34 | +proxyconfigs networking.istio.io/v1beta1 true ProxyConfig |
| 35 | +serviceentries se networking.istio.io/v1 true ServiceEntry |
| 36 | +sidecars networking.istio.io/v1 true Sidecar |
| 37 | +virtualservices vs networking.istio.io/v1 true VirtualService |
| 38 | +workloadentries we networking.istio.io/v1 true WorkloadEntry |
| 39 | +workloadgroups wg networking.istio.io/v1 true WorkloadGroup |
| 40 | +istiocnis sailoperator.io/v1alpha1 false IstioCNI |
| 41 | +istiorevisions istiorev sailoperator.io/v1alpha1 false IstioRevision |
| 42 | +istios sailoperator.io/v1alpha1 false Istio |
| 43 | +remoteistios sailoperator.io/v1alpha1 false RemoteIstio |
| 44 | +authorizationpolicies ap security.istio.io/v1 true AuthorizationPolicy |
| 45 | +peerauthentications pa security.istio.io/v1 true PeerAuthentication |
| 46 | +requestauthentications ra security.istio.io/v1 true RequestAuthentication |
| 47 | +telemetries telemetry telemetry.istio.io/v1 true Telemetry |
| 48 | + |
| 49 | +# A gateway class for applications to use gateways on |
| 50 | +$ oc get gatewayclass openshift-gateway-api -o yaml |
| 51 | +apiVersion: gateway.networking.k8s.io/v1 |
| 52 | +kind: GatewayClass |
| 53 | +metadata: |
| 54 | + creationTimestamp: "2024-11-05T13:15:50Z" |
| 55 | + generation: 1 |
| 56 | + name: openshift-gateway-api |
| 57 | + resourceVersion: "1518" |
| 58 | + uid: 2490e78e-9000-42cf-8234-d3e5482825a9 |
| 59 | +spec: |
| 60 | + controllerName: openshift.io/gateway-controller |
| 61 | +status: |
| 62 | + conditions: |
| 63 | + - lastTransitionTime: "2024-11-05T13:18:02Z" |
| 64 | + message: Handled by Istio controller |
| 65 | + observedGeneration: 1 |
| 66 | + reason: Accepted |
| 67 | + status: "True" |
| 68 | + type: Accepted |
| 69 | + |
| 70 | +# Service mesh operator and istio controller |
| 71 | +$ oc get deployment -n openshift-gateway-api |
| 72 | +NAME READY UP-TO-DATE AVAILABLE AGE |
| 73 | +istiod-openshift-gateway-api 1/1 1 1 26h |
| 74 | +servicemesh-operator3 1/1 1 1 26h |
| 75 | +``` |
| 76 | +There are also additional roles and role bindings, not shown here for brevity. |
| 77 | + |
| 78 | +## Configuring Gateways |
| 79 | +In order to use the feature we need an application that we want to expose through a gateway, a gateway, and some routes. |
| 80 | + |
| 81 | +First we create a sample application: |
| 82 | +```bash |
| 83 | +$ oc create -f test/assets/hello-microshift.yaml |
| 84 | +$ oc create -f test/assets/hello-microshift-service.yaml |
| 85 | +$ oc get pod,svc hello-microshift |
| 86 | +NAME READY STATUS RESTARTS AGE |
| 87 | +pod/hello-microshift 1/1 Running 0 48s |
| 88 | + |
| 89 | +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 90 | +service/hello-microshift ClusterIP 10.43.216.183 <none> 8080/TCP 13s |
| 91 | +``` |
| 92 | + |
| 93 | +Then we can create a gateway for it: |
| 94 | +```bash |
| 95 | +$ cat gatewayapi/gateway.yaml |
| 96 | +apiVersion: gateway.networking.k8s.io/v1beta1 |
| 97 | +kind: Gateway |
| 98 | +metadata: |
| 99 | + name: demo-gateway |
| 100 | + namespace: openshift-gateway-api |
| 101 | +spec: |
| 102 | + gatewayClassName: openshift-gateway-api |
| 103 | + listeners: |
| 104 | + - name: demo |
| 105 | + hostname: "*.microshift-9" |
| 106 | + port: 8080 |
| 107 | + protocol: HTTP |
| 108 | + allowedRoutes: |
| 109 | + namespaces: |
| 110 | + from: All |
| 111 | + |
| 112 | +$ oc create -f gatewayapi/gateway.yaml |
| 113 | +gateway.gateway.networking.k8s.io/demo-gateway created |
| 114 | + |
| 115 | +# Output truncated to show relevant parts for this doc. |
| 116 | +$ oc get gateway -n openshift-gateway-api demo-gateway -o yaml | yq '.status' |
| 117 | +addresses: |
| 118 | + - type: IPAddress |
| 119 | + value: 192.168.113.117 |
| 120 | +conditions: |
| 121 | + - ... |
| 122 | + - lastTransitionTime: "2024-11-06T16:03:20Z" |
| 123 | + message: Resource programmed, assigned to service(s) demo-gateway-openshift-gateway-api.openshift-gateway-api.svc.cluster.local:8080 |
| 124 | + observedGeneration: 1 |
| 125 | + reason: Programmed |
| 126 | + status: "True" |
| 127 | + type: Programmed |
| 128 | +listeners: |
| 129 | + - attachedRoutes: 0 |
| 130 | + conditions: |
| 131 | + ... |
| 132 | + name: demo |
| 133 | + supportedKinds: |
| 134 | + ... |
| 135 | +``` |
| 136 | +The gateway defined above is using the GatewayClass that MicroShift created, it includes a listener called `demo` listening in port 8080 for any request with hostname `*.microshift-9` and is able to accept routes from any namespace in the cluster. |
| 137 | +Note there are no attached routes to the gateway because we have not created any yet. |
| 138 | + |
| 139 | +The gateway definition will kickstart the creation of the resources needed to accept and route traffic. A deployment (using the gateway name with the gateway class as the resource name), and a service to expose it outside of the cluster: |
| 140 | +```bash |
| 141 | +$ oc get deployments.apps -n openshift-gateway-api demo-gateway-openshift-gateway-api |
| 142 | +NAME READY UP-TO-DATE AVAILABLE AGE |
| 143 | +demo-gateway-openshift-gateway-api 1/1 1 1 3m12s |
| 144 | + |
| 145 | +$ oc get svc -n openshift-gateway-api demo-gateway-openshift-gateway-api |
| 146 | +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 147 | +demo-gateway-openshift-gateway-api LoadBalancer 10.43.69.88 192.168.113.117 15021:32736/TCP,8080:30877/TCP 2m36s |
| 148 | +``` |
| 149 | + |
| 150 | +And to be able to use it, a route. Following is a simple route to redirect all traffic from a specific hostname into a service. Note how the status reveals information about whether the route was accepted by a gateway (and which one): |
| 151 | +```bash |
| 152 | +$ cat gatewayapi/httproute.yaml |
| 153 | +apiVersion: gateway.networking.k8s.io/v1beta1 |
| 154 | +kind: HTTPRoute |
| 155 | +metadata: |
| 156 | + name: http |
| 157 | + namespace: default |
| 158 | +spec: |
| 159 | + parentRefs: |
| 160 | + - name: demo-gateway |
| 161 | + namespace: openshift-gateway-api |
| 162 | + hostnames: ["test.microshift-9"] |
| 163 | + rules: |
| 164 | + - backendRefs: |
| 165 | + - name: hello-microshift |
| 166 | + namespace: default |
| 167 | + port: 8080 |
| 168 | + |
| 169 | +$ oc create -f gatewayapi/httproute.yaml |
| 170 | +httproute.gateway.networking.k8s.io/http created |
| 171 | + |
| 172 | +$ oc get httproutes.gateway.networking.k8s.io http -o yaml |
| 173 | +apiVersion: gateway.networking.k8s.io/v1 |
| 174 | +kind: HTTPRoute |
| 175 | +metadata: |
| 176 | + creationTimestamp: "2024-11-06T16:10:41Z" |
| 177 | + generation: 1 |
| 178 | + name: http |
| 179 | + namespace: default |
| 180 | + resourceVersion: "133629" |
| 181 | + uid: ab8deb11-458b-43a8-9ff3-b63e47b3d5c3 |
| 182 | +spec: |
| 183 | + hostnames: |
| 184 | + - test.microshift-9 |
| 185 | + parentRefs: |
| 186 | + - group: gateway.networking.k8s.io |
| 187 | + kind: Gateway |
| 188 | + name: demo-gateway |
| 189 | + namespace: openshift-gateway-api |
| 190 | + rules: |
| 191 | + - backendRefs: |
| 192 | + - group: "" |
| 193 | + kind: Service |
| 194 | + name: hello-microshift |
| 195 | + namespace: default |
| 196 | + port: 8080 |
| 197 | + weight: 1 |
| 198 | + matches: |
| 199 | + - path: |
| 200 | + type: PathPrefix |
| 201 | + value: / |
| 202 | +status: |
| 203 | + parents: |
| 204 | + - conditions: |
| 205 | + - lastTransitionTime: "2024-11-06T16:10:41Z" |
| 206 | + message: Route was valid |
| 207 | + observedGeneration: 1 |
| 208 | + reason: Accepted |
| 209 | + status: "True" |
| 210 | + type: Accepted |
| 211 | + - lastTransitionTime: "2024-11-06T16:10:41Z" |
| 212 | + message: All references resolved |
| 213 | + observedGeneration: 1 |
| 214 | + reason: ResolvedRefs |
| 215 | + status: "True" |
| 216 | + type: ResolvedRefs |
| 217 | + controllerName: openshift.io/gateway-controller |
| 218 | + parentRef: |
| 219 | + group: gateway.networking.k8s.io |
| 220 | + kind: Gateway |
| 221 | + name: demo-gateway |
| 222 | + namespace: openshift-gateway-api |
| 223 | +``` |
| 224 | + |
| 225 | +Note that the route is in a different namespace than the gateway but is still accepted due to its configuration. This is also noted in the gateway status: |
| 226 | +```bash |
| 227 | +$ oc get gateway -n openshift-gateway-api demo-gateway -o yaml | yq '.status.listeners' |
| 228 | +- attachedRoutes: 1 |
| 229 | + conditions: |
| 230 | + - lastTransitionTime: "2024-11-06T16:03:18Z" |
| 231 | + message: No errors found |
| 232 | + observedGeneration: 1 |
| 233 | + reason: Accepted |
| 234 | + status: "True" |
| 235 | + type: Accepted |
| 236 | + - lastTransitionTime: "2024-11-06T16:03:18Z" |
| 237 | + message: No errors found |
| 238 | + observedGeneration: 1 |
| 239 | + reason: NoConflicts |
| 240 | + status: "False" |
| 241 | + type: Conflicted |
| 242 | + - lastTransitionTime: "2024-11-06T16:03:18Z" |
| 243 | + message: No errors found |
| 244 | + observedGeneration: 1 |
| 245 | + reason: Programmed |
| 246 | + status: "True" |
| 247 | + type: Programmed |
| 248 | + - lastTransitionTime: "2024-11-06T16:03:18Z" |
| 249 | + message: No errors found |
| 250 | + observedGeneration: 1 |
| 251 | + reason: ResolvedRefs |
| 252 | + status: "True" |
| 253 | + type: ResolvedRefs |
| 254 | + name: demo |
| 255 | + supportedKinds: |
| 256 | + - group: gateway.networking.k8s.io |
| 257 | + kind: HTTPRoute |
| 258 | + - group: gateway.networking.k8s.io |
| 259 | + kind: GRPCRoute |
| 260 | +``` |
| 261 | +Which is now showing 1 attached route, as in the `parentRef` from the `HTTPRoute` above. |
| 262 | + |
| 263 | +We should now be able to query the service through the gateway: |
| 264 | +```bash |
| 265 | +$ curl http://test.microshift-9:8080 --connect-to test.microshift-9::192.168.113.117: -i |
| 266 | +HTTP/1.1 200 OK |
| 267 | +content-length: 16 |
| 268 | +x-envoy-upstream-service-time: 1 |
| 269 | +date: Wed, 06 Nov 2024 16:12:30 GMT |
| 270 | +server: istio-envoy |
| 271 | + |
| 272 | +Hello MicroShift |
| 273 | +``` |
| 274 | +Note the headers from the gateway (`server` and `x-envoy-upstream-service-time`), proving that the request went through it (a curl to the service IP does not yield those headers). If we were to delete the route we should get a 404: |
| 275 | +```bash |
| 276 | +$ oc delete -f gatewayapi/httproute.yaml |
| 277 | +httproute.gateway.networking.k8s.io "http" deleted |
| 278 | + |
| 279 | +$ curl http://test.microshift-9:8080 --connect-to test.microshift-9::192.168.113.117: -i |
| 280 | +HTTP/1.1 404 Not Found |
| 281 | +date: Wed, 06 Nov 2024 16:17:07 GMT |
| 282 | +server: istio-envoy |
| 283 | +content-length: 0 |
| 284 | +``` |
| 285 | + |
| 286 | +## Uninstall |
| 287 | +Gateway API is installed through RPM packages, therefore removing them will erase the files for all the new manifests. |
| 288 | +```bash |
| 289 | +$ sudo dnf remove -y microshift-gateway-api-release-info microshift-gateway-api |
| 290 | +``` |
| 291 | + |
| 292 | +However, this is not enough because the resources remain installed in etcd. To completely remove Gateway API resources we need to do the following: |
| 293 | +* Remove the user defined `Gateway`, `HTTPRoute` and `GRPCRoute` resources. These depend on your application. |
| 294 | +* Remove `openshift-gateway-api` namespace. This will remove all the namespaced resources. |
| 295 | + ```bash |
| 296 | + $ oc delete namespace openshift-gateway-api |
| 297 | + ``` |
| 298 | +* Remove `ClusterRole` and `ClusterRoleBindings`. |
| 299 | + ```bash |
| 300 | + $ oc get clusterrole | grep -E "openshift-gateway-api|servicemesh-operator" | awk '{print $1}' | xargs oc delete clusterrole |
| 301 | + $ oc delete clusterrolebinding | grep -E "openshift-gateway-api|servicemesh-operator" | awk '{print $1}' | xargs oc delete clusterrolebinding |
| 302 | + ``` |
| 303 | +* Remove CRD definitions. |
| 304 | + ```bash |
| 305 | + $ oc get crd | grep -E "gateway|istio" | awk '{print $1}' | xargs oc delete crd |
| 306 | + ``` |
| 307 | + |
0 commit comments