Ingress Traffic

- By: Thomas Jungbauer ( Lastmod: 2021-08-14 )

Part 3 of tutorial series OpenShift 4 and Service Mesh will show you how to create a Gateway and a VirtualService, so external traffic actually reaches your Mesh. It also provides an example script to run some curl in a loop.

Configure Gateway and VirtualService Example

With the microservices deployed during Issue #2, it makes sense to test the access somehow. In order to bring traffic into the application a Gateway object and a VirtualService object must be created.

The Gateway will be the entry point which forward the traffic to the istio ingressgateway

kind: Gateway
  name: ingress-gateway-exampleapp
    istio: ingressgateway # use istio default controller
  - port:
      number: 80
      name: http
      protocol: HTTP
    - "*"

As 2nd object a VirtualService must be created:

kind: VirtualService
  name: ingress-gateway-exampleapp
  - "*"
  - ingress-gateway-exampleapp
  - match:
    - uri:
        exact: /
    - destination:
        host: customer
          number: 8080

Get all istio-io related objects of your project. These objects represent the network objects of Service Mesh, like Gateway, VirtualService and DestinationRule (explained later)

oc get istio-io -n tutorial
NAME                                                 HOST             AGE   recommendation   3d21h

NAME                                          AGE   4d15h

NAME                                                 GATEWAYS            HOSTS              AGE   [ingress-gateway]   [*]        4d15h

Create some example traffic

Before we start, lets fetch the default route of our Service Mesh:

export GATEWAY_URL=$(oc -n istio-system get route istio-ingressgateway -o jsonpath='{}')

This should return: istio-ingressgateway-istio-system.apps.<clustername>

Now, let’s create a shell script to run some curl commands in a loop and can be easily reused for other scenarios:



if [ $# -eq 0 ]; then
    echo "better define: <script> #ofrequests hostname2check"
    echo "Example: 100"
	let "numberOfRequests=100"
	let "i = 0"
	while [ $i -lt $numberOfRequests ]; do
	  echo -n "# $i: "; curl $2
	  let "i=$((i + 1))"

Run the script and check the output:

sh 1000 $GATEWAY_URL

This will send 1000 requests to our application:

# 0: customer => preference => recommendation v1 from 'f11b097f1dd0': 3622
# 1: customer => preference => recommendation v1 from 'f11b097f1dd0': 3623
# 2: customer => preference => recommendation v1 from 'f11b097f1dd0': 3624
# 3: customer => preference => recommendation v1 from 'f11b097f1dd0': 3625
# 4: customer => preference => recommendation v1 from 'f11b097f1dd0': 3626
# 5: customer => preference => recommendation v1 from 'f11b097f1dd0': 3627

Verify in Kiali

To verify in Kiali our application, open the URL in your browser and login using your OpenShift credentials.

If you do not know the URL for Kiali, execute the following command
oc get route kiali -n istio-system

Switch the the Graph view and you should see the following picture:

Kiali Example 1
Figure 1. Kiali Graph