|
| 1 | +--- |
| 2 | +title: Exposing an AKS service over HTTP or HTTPS using Application Gateway |
| 3 | +description: This article provides information on how to expose an AKS service over HTTP or HTTPS using Application Gateway. |
| 4 | +services: application-gateway |
| 5 | +author: caya |
| 6 | +ms.service: application-gateway |
| 7 | +ms.topic: article |
| 8 | +ms.date: 10/22/2019 |
| 9 | +ms.author: caya |
| 10 | +--- |
| 11 | + |
| 12 | +# Tutorials |
| 13 | + |
| 14 | +These tutorials help illustrate the usage of [Kubernetes Ingress Resources](https://kubernetes.io/docs/concepts/services-networking/ingress/) to expose an example Kubernetes service through the [Azure Application Gateway](https://azure.microsoft.com/services/application-gateway/) over HTTP or HTTPS. |
| 15 | + |
| 16 | +## Table of Contents |
| 17 | + |
| 18 | +- [Prerequisites](#prerequisites) |
| 19 | +- [Deploy `guestbook` application](#deploy-guestbook-application) |
| 20 | +- [Expose services over HTTP](#expose-services-over-http) |
| 21 | +- [Expose services over HTTPS](#expose-services-over-https) |
| 22 | + - [Without specified hostname](#without-specified-hostname) |
| 23 | + - [With specified hostname](#with-specified-hostname) |
| 24 | +- [Integrate with other services](#integrate-with-other-services) |
| 25 | + |
| 26 | +## Prerequisites |
| 27 | + |
| 28 | +- Installed `ingress-azure` helm chart. |
| 29 | + - [**Greenfield Deployment**](application-gateway-ingress-controller-install-new.md): If you are starting from scratch, refer to these installation instructions which outlines steps to deploy an AKS cluster with Application Gateway and install application gateway ingress controller on the AKS cluster. |
| 30 | + - [**Brownfield Deployment**](application-gateway-ingress-controller-install-existing.md): If you have an existing AKS cluster and Application Gateway, refer to these instructions to install application gateway ingress controller on the AKS cluster. |
| 31 | +- If you want to use HTTPS on this application, you will need a x509 certificate and its private key. |
| 32 | + |
| 33 | +## Deploy `guestbook` application |
| 34 | + |
| 35 | +The guestbook application is a canonical Kubernetes application that composes of a Web UI frontend, a backend and a Redis database. By default, `guestbook` exposes its application through a service with name `frontend` on port `80`. Without a Kubernetes Ingress Resource the service is not accessible from outside the AKS cluster. We will use the application and setup Ingress Resources to access the application through HTTP and HTTPS. |
| 36 | + |
| 37 | +Follow the instructions below to deploy the guestbook application. |
| 38 | + |
| 39 | +1. Download `guestbook-all-in-one.yaml` from [here](https://raw.githubusercontent.com/kubernetes/examples/master/guestbook/all-in-one/guestbook-all-in-one.yaml) |
| 40 | +1. Deploy `guestbook-all-in-one.yaml` into your AKS cluster by running |
| 41 | + |
| 42 | + ```bash |
| 43 | + kubectl apply -f guestbook-all-in-one.yaml |
| 44 | + ``` |
| 45 | + |
| 46 | +Now, the `guestbook` application has been deployed. |
| 47 | + |
| 48 | +## Expose services over HTTP |
| 49 | + |
| 50 | +In order to expose the guestbook application we will using the following ingress resource: |
| 51 | + |
| 52 | +```yaml |
| 53 | +apiVersion: extensions/v1beta1 |
| 54 | +kind: Ingress |
| 55 | +metadata: |
| 56 | + name: guestbook |
| 57 | + annotations: |
| 58 | + kubernetes.io/ingress.class: azure/application-gateway |
| 59 | +spec: |
| 60 | + rules: |
| 61 | + - http: |
| 62 | + paths: |
| 63 | + - backend: |
| 64 | + serviceName: frontend |
| 65 | + servicePort: 80 |
| 66 | +``` |
| 67 | +
|
| 68 | +This ingress will expose the `frontend` service of the `guestbook-all-in-one` deployment |
| 69 | +as a default backend of the Application Gateway. |
| 70 | + |
| 71 | +Save the above ingress resource as `ing-guestbook.yaml`. |
| 72 | + |
| 73 | +1. Deploy `ing-guestbook.yaml` by running: |
| 74 | + |
| 75 | + ```bash |
| 76 | + kubectl apply -f ing-guestbook.yaml |
| 77 | + ``` |
| 78 | + |
| 79 | +1. Check the log of the ingress controller for deployment status. |
| 80 | + |
| 81 | +Now the `guestbook` application should be available. You can check this by visiting the |
| 82 | +public address of the Application Gateway. |
| 83 | + |
| 84 | +## Expose services over HTTPS |
| 85 | + |
| 86 | +### Without specified hostname |
| 87 | + |
| 88 | +Without specifying hostname, the guestbook service will be available on all the host-names pointing to the application gateway. |
| 89 | + |
| 90 | +1. Before deploying ingress, you need to create a kubernetes secret to host the certificate and private key. You can create a kubernetes secret by running |
| 91 | + |
| 92 | + ```bash |
| 93 | + kubectl create secret tls <guestbook-secret-name> --key <path-to-key> --cert <path-to-cert> |
| 94 | + ``` |
| 95 | + |
| 96 | +1. Define the following ingress. In the ingress, specify the name of the secret in the `secretName` section. |
| 97 | + |
| 98 | + ```yaml |
| 99 | + apiVersion: extensions/v1beta1 |
| 100 | + kind: Ingress |
| 101 | + metadata: |
| 102 | + name: guestbook |
| 103 | + annotations: |
| 104 | + kubernetes.io/ingress.class: azure/application-gateway |
| 105 | + spec: |
| 106 | + tls: |
| 107 | + - secretName: <guestbook-secret-name> |
| 108 | + rules: |
| 109 | + - http: |
| 110 | + paths: |
| 111 | + - backend: |
| 112 | + serviceName: frontend |
| 113 | + servicePort: 80 |
| 114 | + ``` |
| 115 | + |
| 116 | + *NOTE:* Replace `<guestbook-secret-name>` in the above Ingress Resource with the name of your secret. Store the above Ingress Resource in a file name `ing-guestbook-tls.yaml`. |
| 117 | + |
| 118 | +1. Deploy ing-guestbook-tls.yaml by running |
| 119 | + |
| 120 | + ```bash |
| 121 | + kubectl apply -f ing-guestbook-tls.yaml |
| 122 | + ``` |
| 123 | + |
| 124 | +1. Check the log of the ingress controller for deployment status. |
| 125 | + |
| 126 | +Now the `guestbook` application will be available on both HTTP and HTTPS. |
| 127 | + |
| 128 | +### With specified hostname |
| 129 | + |
| 130 | +You can also specify the hostname on the ingress in order to multiplex TLS configurations and services. |
| 131 | +By specifying hostname, the guestbook service will only be available on the specified host. |
| 132 | + |
| 133 | +1. Define the following ingress. |
| 134 | + In the ingress, specify the name of the secret in the `secretName` section and replace the hostname in the `hosts` section accordingly. |
| 135 | + |
| 136 | + ```yaml |
| 137 | + apiVersion: extensions/v1beta1 |
| 138 | + kind: Ingress |
| 139 | + metadata: |
| 140 | + name: guestbook |
| 141 | + annotations: |
| 142 | + kubernetes.io/ingress.class: azure/application-gateway |
| 143 | + spec: |
| 144 | + tls: |
| 145 | + - hosts: |
| 146 | + - <guestbook.contoso.com> |
| 147 | + secretName: <guestbook-secret-name> |
| 148 | + rules: |
| 149 | + - host: <guestbook.contoso.com> |
| 150 | + http: |
| 151 | + paths: |
| 152 | + - backend: |
| 153 | + serviceName: frontend |
| 154 | + servicePort: 80 |
| 155 | + ``` |
| 156 | + |
| 157 | +1. Deploy `ing-guestbook-tls-sni.yaml` by running |
| 158 | + |
| 159 | + ```bash |
| 160 | + kubectl apply -f ing-guestbook-tls-sni.yaml |
| 161 | + ``` |
| 162 | + |
| 163 | +1. Check the log of the ingress controller for deployment status. |
| 164 | + |
| 165 | +Now the `guestbook` application will be available on both HTTP and HTTPS only on the specified host (`<guestbook.contoso.com>` in this example). |
| 166 | + |
| 167 | +## Integrate with other services |
| 168 | + |
| 169 | +The following ingress will allow you to add additional paths into this ingress and redirect those paths to other services: |
| 170 | + |
| 171 | + ```yaml |
| 172 | + apiVersion: extensions/v1beta1 |
| 173 | + kind: Ingress |
| 174 | + metadata: |
| 175 | + name: guestbook |
| 176 | + annotations: |
| 177 | + kubernetes.io/ingress.class: azure/application-gateway |
| 178 | + spec: |
| 179 | + rules: |
| 180 | + - http: |
| 181 | + paths: |
| 182 | + - path: </other/*> |
| 183 | + backend: |
| 184 | + serviceName: <other-service> |
| 185 | + servicePort: 80 |
| 186 | + - backend: |
| 187 | + serviceName: frontend |
| 188 | + servicePort: 80 |
| 189 | + ``` |
0 commit comments