istio.io/istio@v0.0.0-20240520182934-d79c90f27776/samples/helloworld/gateway-api/README.md (about)

     1  # Configure helloworld using the Kubernetes Gateway API
     2  
     3  Istio intends to make the Kubernetes [Gateway API](https://gateway-api.sigs.k8s.io/) the default API for traffic management [in the future](https://istio.io/latest/blog/2022/gateway-api-beta/).
     4  You can use the following instructions to configure the ingress gateway and routing for the helloworld sample.
     5  
     6  ## Before you begin
     7  
     8  The Gateway API CRDs do not come installed by default on most Kubernetes clusters, so install them if not present:
     9  
    10  ```bash
    11  kubectl get crd gateways.gateway.networking.k8s.io || \
    12    { kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd?ref=v0.5.0" | kubectl apply -f -; }
    13  ```
    14  
    15  Also make sure you are running two versions (v1 and v2) of the helloworld service:
    16  
    17  ```bash
    18  kubectl apply -f ../helloworld.yaml
    19  ```
    20  
    21  ## Configure the helloworld gateway
    22  
    23  Apply the helloworld gateway configuration:
    24  
    25  ```bash
    26  kubectl apply -f ./helloworld-gateway.yaml
    27  ```
    28  
    29  Note that unlike an Istio `Gateway`, creating a Kubernetes `Gateway` resource will, by default, also [deploy an associated controller](https://istio.io/latest/docs/tasks/traffic-management/ingress/gateway-api/#automated-deployment).
    30  
    31  Set the INGRESS_HOST environment variables to the address of the helloworld gateway:
    32  
    33  ```bash
    34  kubectl wait --for=condition=ready gtw helloworld-gateway
    35  export INGRESS_HOST=$(kubectl get gtw helloworld-gateway -o jsonpath='{.status.addresses[*].value}')
    36  ```
    37  
    38  Confirm the sample is running using curl:
    39  
    40  ```bash
    41  for run in {1..10}; do curl http://$INGRESS_HOST/hello; done
    42  ```
    43  
    44  Since no version routing has been configured, you should see an equal split of traffic, about half handled by helloworld-v1 and the other half handled by helloworld-v2.
    45  
    46  ## Configure weight-based routing
    47  
    48  Declare the helloworld versions (Gateway API requires backend service definitions, unlike the Istio API which uses DestinationRule subsets for this):
    49  
    50  ```bash
    51  kubectl apply -f ./helloworld-versions.yaml
    52  ```
    53  
    54  Apply the following route rule to distribute the helloworld traffic 90% to v1, 10% to v2:
    55  
    56  ```bash
    57  kubectl apply -f ./helloworld-route.yaml
    58  ```
    59  
    60  Run the previous curl commands again:
    61  
    62  ```bash
    63  for run in {1..10}; do curl http://$INGRESS_HOST/hello; done
    64  ```
    65  
    66  Now you should see about 9 out of 10 requests handled by helloworld-v1 and only about 1 in 10 handled by helloworld-v2.
    67  
    68  ## Cleanup
    69  
    70  ```bash
    71  kubectl delete -f ./helloworld-gateway.yaml
    72  kubectl delete -f ./helloworld-versions.yaml
    73  kubectl delete -f ../helloworld.yaml
    74  ```