Simple demo to show routing based on headers via OSSM
This uses a ServiceEntry called product-api-entry in the frontend-ns namespace.
The VirtualService named product-api-routing evaluates headers when the ServiceEntry is called and routes to an internal service in another namespace based on the header.
This is for illustrative purposes, but you could use headers to route to dev, test, prod namespaces, for example.
See: (OSSM3 Demo SetUp)[https://github.com/bugbiteme/ossm-3-demo]
Apply istio.yaml to update it to handle DNS allocation
oc apply -f istio.yamlAdded config:
values:
meshConfig:
defaultConfig:
proxyMetadata:
ISTIO_META_DNS_AUTO_ALLOCATE: "true"
ISTIO_META_DNS_CAPTURE: "true"If using GitOps/ArgoCD, deploy front and back-end resources by applying the following
oc apply -f gitops/header-routing.yaml Example output:
application.argoproj.io/header-routing createdIf you are not using GitOps, manually deploy the following
Dev
oc apply -k backend/overlays/devProd
oc apply -k backend/overlays/prodQA
oc apply -k backend/overlays/qaoc apply -k frontend Sample output:
namespace/frontend-ns created
service/flask-front-end created
deployment.apps/flask-front-end created
serviceentry.networking.istio.io/product-api-entry created
virtualservice.networking.istio.io/product-api-routing created
route.route.openshift.io/flask-front-end created
pod/curl-test createdThis uses a test pod named curl-test to ensure header-based routing works
header dev
oc exec -n frontend-ns curl-test -- \
curl -s -H "x-env-target: dev" \
http://product-api.internal/helloOutput:
{"message":"Hello World from dev"}header prod
oc exec -n frontend-ns curl-test -- \
curl -s -H "x-env-target: prod" \
http://product-api.internal/helloOutput:
{"message":"Hello World from prod"}header qa
oc exec -n frontend-ns curl-test -- \
curl -s -H "x-env-target: qa" \
http://product-api.internal/helloOutput:
{"message":"Hello World from qa"}The deployed application in the frontend-ns namespace is a Python/Flask app
It is currently exposed as a route, but feel free to create an ingress gateway if required
oc get routes
NAME HOST/PORT
flask-front-end flask-front-end-frontend-ns.app.<domain>This is a browser based app that allows you to test responses based on headers from a drop-down list
Source code found at ./code/flask
@app.route("/call-api")
def call_api():
...
headers = {"x-env-target": env}
...
response = requests.get("http://product-api.internal/hello", headers=headers)
return Response(response.content, status=response.status_code, mimetype="text/plain")
...
