diff --git a/Istio/istio-classic/traffic_management/03-HTTPRewrite/README.md b/Istio/istio-classic/traffic_management/03-HTTPRewrite/README.md index 0967ca4..0204f98 100644 --- a/Istio/istio-classic/traffic_management/03-HTTPRewrite/README.md +++ b/Istio/istio-classic/traffic_management/03-HTTPRewrite/README.md @@ -13,6 +13,8 @@ Through rewriting the URI we can point to the root directory from nginx. uri: "/" ``` +## The idea is that this rewrite is handled "internally" by Istio, not by the Client that started the request + ## Practical usages: diff --git a/Istio/istio-classic/traffic_management/04-HTTPRedirect/README.md b/Istio/istio-classic/traffic_management/04-HTTPRedirect/README.md new file mode 100644 index 0000000..c28e398 --- /dev/null +++ b/Istio/istio-classic/traffic_management/04-HTTPRedirect/README.md @@ -0,0 +1,61 @@ + + +# Continues from + +- 01-hello_world_1_service_1_deployment + + + +https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRedirect + +## The idea is that this rewrite is handled "externally" by the client, not by Istio. + + + +## Practical examples + + +### HTTP to HTTPS redirect. + +The following Virtual Service configuration will redirect all the incoming traffic from the gateway `my-gateway` that uses the http protocol, to the https protocol. + +In this example, it would forward all the `http` traffic without taking into account which port is used. + +``` +apiVersion: networking.istio.io/v1alpha3 +kind: VirtualService +metadata: + name: to-https-vs +spec: + hosts: + - "*" + gateways: + - my-gateway + http: + - match: + - name: to_https + match: + scheme: http + redirect: + scheme: https +``` + +### Migrated from a domain + +The following will update the requests coming "to" the domain `old.domain.com` and rewrite the URL to use the "new" `new.domain.com` + +```yaml +apiVersion: networking.istio.io/v1alpha3 +kind: VirtualService +metadata: + name: update-domain-vs +spec: + hosts: + - "old.domain.com" + gateways: + - helloworld-gateway + http: + - name: forward-to-new-domain + redirect: + authority: "new.domain.com" +``` \ No newline at end of file diff --git a/Istio/istio-classic/traffic_management/04-HTTPRedirect/deployment.yaml b/Istio/istio-classic/traffic_management/04-HTTPRedirect/deployment.yaml new file mode 100644 index 0000000..01dd2b0 --- /dev/null +++ b/Istio/istio-classic/traffic_management/04-HTTPRedirect/deployment.yaml @@ -0,0 +1,40 @@ +# https://github.com/istio/istio/blob/master/samples/helloworld/helloworld.yaml +apiVersion: v1 +kind: Service +metadata: + name: helloworld + labels: + app: helloworld + service: helloworld +spec: + ports: + - port: 80 + name: http + selector: + app: helloworld +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: helloworld-nginx + labels: + app: helloworld +spec: + replicas: 1 + selector: + matchLabels: + app: helloworld + template: + metadata: + labels: + app: helloworld + spec: + containers: + - name: helloworld + image: nginx + resources: + requests: + cpu: "100m" + imagePullPolicy: IfNotPresent #Always + ports: + - containerPort: 80 diff --git a/Istio/istio-classic/traffic_management/04-HTTPRedirect/gateway.yaml b/Istio/istio-classic/traffic_management/04-HTTPRedirect/gateway.yaml new file mode 100644 index 0000000..c1f16c5 --- /dev/null +++ b/Istio/istio-classic/traffic_management/04-HTTPRedirect/gateway.yaml @@ -0,0 +1,58 @@ +# https://github.com/istio/istio/blob/master/samples/helloworld/helloworld-gateway.yaml +apiVersion: networking.istio.io/v1alpha3 +kind: Gateway +metadata: + name: helloworld-gateway +spec: + selector: + istio: ingressgateway # use istio default controller + servers: + - port: + number: 80 + name: http + protocol: HTTP + hosts: + - "*" +--- +apiVersion: networking.istio.io/v1alpha3 +kind: VirtualService +metadata: + name: helloworld-vs +spec: + hosts: + - "*" + gateways: + - helloworld-gateway + http: + - match: + - uri: + exact: /helloworld + route: + - destination: + host: helloworld.default.svc.cluster.local + port: + number: 80 + rewrite: + uri: "/" + - name: to_https + match: + - uri: + exact: /https + scheme: http + redirect: + scheme: "https" + - name: wikipedia + match: + - uri: + exact: "/wiki" + redirect: + uri: "/" + scheme: "https" + authority: "en.wikipedia.org" + - name: wikipedia_search + match: + - uri: + prefix: "/wiki/" + redirect: + scheme: "https" + authority: "en.wikipedia.org" \ No newline at end of file