|
| 1 | +--- |
| 2 | +title: "Using Ambassador Ingress Controller" |
| 3 | +linkTitle: "Using Ambassador Ingress Controller" |
| 4 | +weight: 1 |
| 5 | +date: 2020-05-14 |
| 6 | +description: > |
| 7 | + Using Ambassador Ingress Controller with Minikube |
| 8 | +--- |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +[Ambassador](https://getambassador.io/) allows access to Kubernetes services running inside Minikube. Ambassador can be |
| 13 | +configured via both, [Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/) resources and |
| 14 | +[Mapping](https://www.getambassador.io/docs/latest/topics/using/intro-mappings/) resources. |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | + |
| 18 | +- Minikube version higher than v1.10.1 |
| 19 | +- kubectl |
| 20 | + |
| 21 | +## Configuring Ambassador |
| 22 | + |
| 23 | +### Installing Ambassador |
| 24 | + |
| 25 | +Ambassador is available as a Minikube |
| 26 | +[addon]((https://github.com/kubernetes/minikube/tree/master/deploy/addons/ambassdor)). Install it by running - |
| 27 | + |
| 28 | +```shell script |
| 29 | +minikube addons enable ambassador |
| 30 | +``` |
| 31 | + |
| 32 | +This will install Ambassador in the namespace `ambassador`. |
| 33 | + |
| 34 | +### Accessing Ambassador via `minikube tunnel` |
| 35 | + |
| 36 | +The service `ambassador` is of type `LoadBalancer`. To access this service, run a |
| 37 | +[Minikube tunnel](https://minikube.sigs.k8s.io/docs/handbook/accessing/#using-minikube-tunnel) in a separate terminal. |
| 38 | + |
| 39 | +```shell script |
| 40 | +minikube tunnel |
| 41 | +``` |
| 42 | + |
| 43 | +You can now access Ambassador at the external IP allotted to the `ambassador` service. |
| 44 | +Get the external IP with the following command: |
| 45 | +```shell script |
| 46 | +kubectl get service ambassador -n ambassador |
| 47 | +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 48 | +ambassador LoadBalancer 10.104.86.124 10.104.86.124 80:31287/TCP,443:31934/TCP 77m |
| 49 | +``` |
| 50 | + |
| 51 | +### Configuring via Ingress resource |
| 52 | + |
| 53 | +In this tutorial, we'll configure Ambassador via an Ingress resource. To configure via `IngressClass` resource, read |
| 54 | +this [post](https://blog.getambassador.io/new-kubernetes-1-18-extends-ingress-c34abdc2f064). |
| 55 | + |
| 56 | +First, let's create a Kubernetes deployment and service which we will talk to via Ambassador. |
| 57 | + |
| 58 | +```shell script |
| 59 | +kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4 |
| 60 | +kubectl expose deployment hello-minikube --port=8080 |
| 61 | +``` |
| 62 | + |
| 63 | +This service `hello-minikube` is of type `ClusterIP` and is not accessible from outside the cluster. |
| 64 | + |
| 65 | +Now, create an Ingress resource which exposes this service at the path `/hello/` |
| 66 | + |
| 67 | +**Note:** The Ingress resource must have the annotation `kubernetes.io/ingress.class: ambassador` for Ambassador to |
| 68 | +pick it up. |
| 69 | + |
| 70 | +`hello-ingress.yaml` |
| 71 | +```yaml |
| 72 | +apiVersion: extensions/v1beta1 |
| 73 | +kind: Ingress |
| 74 | +metadata: |
| 75 | + annotations: |
| 76 | + kubernetes.io/ingress.class: ambassador |
| 77 | + name: test-ingress |
| 78 | +spec: |
| 79 | + rules: |
| 80 | + - http: |
| 81 | + paths: |
| 82 | + - path: /hello/ |
| 83 | + backend: |
| 84 | + serviceName: hello-minikube |
| 85 | + servicePort: 8080 |
| 86 | +``` |
| 87 | +Run the command: `kubectl apply -f hello-ingress.yaml` |
| 88 | + |
| 89 | +That's it! You can now access your service via Ambassador: |
| 90 | +```shell script |
| 91 | +curl http://<Ambassdor's External IP'/hello/> |
| 92 | +``` |
| 93 | + |
| 94 | +**Note:** For more advanced Ingress configurations with Ambassador, like TLS termination and name-based virtual hosting, |
| 95 | +see Ambassador's [documentation](https://www.getambassador.io/docs/latest/topics/running/ingress-controller/). |
| 96 | + |
| 97 | +### Configuring via Mapping resource |
| 98 | + |
| 99 | +While Ambassador understands the Ingress spec, the Ingress spec does not leverage all of Ambassador's features. The |
| 100 | +[Mapping](https://www.getambassador.io/docs/latest/topics/using/intro-mappings/) resource is Ambassador's core resource |
| 101 | +that maps a target backend service to a given host or prefix. |
| 102 | + |
| 103 | +Let's create another Kubernetes deployment and service that we will expose via Ambassador - |
| 104 | +```shell script |
| 105 | +kubectl create deployment mapping-minikube --image=k8s.gcr.io/echoserver:1.4 |
| 106 | +kubectl expose deployment mapping-minikube --port=8080 |
| 107 | +``` |
| 108 | + |
| 109 | +This service `mapping-minikube` is of type `ClusterIP` and is not accessible from outside the cluster. |
| 110 | + |
| 111 | +Now, let's create a mapping that exposes this service via Ambassador at the path `/hello-mapping/` |
| 112 | + |
| 113 | +`hello-mapping.yaml` |
| 114 | +```yaml |
| 115 | +apiVersion: getambassador.io/v2 |
| 116 | +kind: Mapping |
| 117 | +metadata: |
| 118 | + name: mapping-minikube |
| 119 | +spec: |
| 120 | + prefix: /hello-mapping/ |
| 121 | + service: mapping-minikube.default:8080 |
| 122 | +``` |
| 123 | +Run the command: `kubectl apply -f hello-mapping.yaml` |
| 124 | + |
| 125 | +That's it! You can now access your service via Ambassador: |
| 126 | +```shell script |
| 127 | +curl http://<Ambassdor's External IP'/hello-mapping/> |
| 128 | +``` |
| 129 | + |
| 130 | +**Note:** Read more about mappings in Ambassador's |
| 131 | +[documentation](https://www.getambassador.io/docs/latest/topics/using/mappings/). |
0 commit comments