简介
Ambassador是一个开源的基于Envoy构建的 Kubernetes + 7 层负载均衡器的网关,也叫Emissary-Ingress。相对于Envoy,Ambassador的部署和使用更加方便。
本节以最新版本为例,讲述整个部署过程和简单使用,具体详细的资料请参考官网
部署Ambassador
Ambassador 可以通过四种方式部署,选择其中一种方式即可
1、Helm 3
# Add the Repo:
helm repo add datawire https://www.getambassador.io
# Create Namespace and Install:
kubectl create namespace ambassador && \
helm install ambassador --namespace ambassador datawire/ambassador && \
kubectl -n ambassador wait --for condition=available --timeout=90s deploy -lproduct=aes
2、Helm 2
# Add the Repo:
helm repo add datawire https://www.getambassador.io
# Create Namespace and Install:
kubectl create namespace ambassador && \
helm install --name ambassador --namespace ambassador datawire/ambassador && \
kubectl -n ambassador wait --for condition=available --timeout=90s deploy -lproduct=aes
3、kubernetes YAML
kubectl apply -f https://www.getambassador.io/yaml/aes-crds.yaml && \
kubectl wait --for condition=established --timeout=90s crd -lproduct=aes && \
kubectl apply -f https://www.getambassador.io/yaml/aes.yaml && \
kubectl -n ambassador wait --for condition=available --timeout=90s deploy -lproduct=aes
4、Quick CLI Install
# macOS:
sudo curl -fL https://metriton.datawire.io/downloads/darwin/edgectl \
-o /usr/local/bin/edgectl &&
sudo chmod a+x /usr/local/bin/edgectl &&
edgectl install
# Linux:
sudo curl -fL https://metriton.datawire.io/downloads/linux/edgectl \
-o /usr/local/bin/edgectl &&
sudo chmod a+x /usr/local/bin/edgectl &&
edgectl install
# Windows:
# Download here - https://metriton.datawire.io/downloads/windows/edgectl.exe
部署后,通过命令 kubectl get all -n ambassador查看完成情况,当命名空间ambassador内的所有pod为Running时,则为部署成功(如下)。
将service/ambassador和service/ambassador-admin的TYPE修改为NodePort,便于后续测试
[root@master-1 ~]# kubectl get all -n ambassador
NAME READY STATUS RESTARTS AGE
pod/ambassador-96bd85767-pjzkf 1/1 Running 93 48d
pod/ambassador-96bd85767-tp5sj 1/1 Running 91 48d
pod/ambassador-agent-68d647d7cf-9wqsq 1/1 Running 12 48d
pod/ambassador-agent-68d647d7cf-bghdb 1/1 Running 12 48d
pod/ambassador-redis-584cd89b45-g99tr 1/1 Running 12 48d
pod/ambassador-redis-584cd89b45-wrrs8 1/1 Running 12 48d
pod/quote-856df6d5b7-phgkt 1/1 Running 12 48d
pod/tomcat-deployment-7db86c59b7-d9txn 1/1 Running 13 48d
pod/tomcat-deployment-7db86c59b7-lhqqn 1/1 Running 13 48d
pod/tomcat-deployment-7db86c59b7-w4vm8 1/1 Running 12 48d
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/ambassador NodePort 10.110.95.198 <none> 80:30067/TCP,443:31058/TCP 48d
service/ambassador-admin NodePort 10.108.4.84 <none> 8877:31523/TCP,8005:30654/TCP 48d
service/ambassador-redis ClusterIP 10.109.47.222 <none> 6379/TCP 48d
service/quote ClusterIP 10.107.83.40 <none> 80/TCP 48d
service/tomcat-service ClusterIP 10.108.198.15 <none> 8080/TCP 47d
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/ambassador 2/2 2 2 48d
deployment.apps/ambassador-agent 2/2 2 2 48d
deployment.apps/ambassador-redis 2/2 2 2 48d
deployment.apps/quote 1/1 1 1 48d
deployment.apps/tomcat-deployment 3/3 3 3 48d
NAME DESIRED CURRENT READY AGE
replicaset.apps/ambassador-96bd85767 2 2 2 48d
replicaset.apps/ambassador-agent-68d647d7cf 2 2 2 48d
replicaset.apps/ambassador-redis-584cd89b45 2 2 2 48d
replicaset.apps/quote-856df6d5b7 1 1 1 48d
replicaset.apps/tomcat-deployment-7db86c59b7 3 3 3 48d
通过hostIP+service/ambassador-admin的port在浏览器中访问,可以看到ambassador的管理页面,例如本次测试的hostIP+port为http://192.168.163.104:31523/,浏览器中输入,看到如下页面,可以看到Ambassador 的版本、ID等相关信息,以及已经部署的路由URL。
部署Route
Ambassador部署Route很灵活,可以通过服务名称,IP、域名三种方式,特别方便。
1、通过服务名称部署Route
我已经在k8s部署了名为tomcat-service的服务,下面来部署路由,YAML文件如下:
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
name: tomcat
spec:
prefix: /tomcat/
service: tomcat-service:8080
通过kubectl apply -f 部署后,在浏览器中可以通过hostIP+service/ambassador的port+prefix访问,如本测试为https://192.168.163.104:31058/tomcat/,可以看到已经路由到了tomcat
2、通过IP部署Route
我已经启动了nginx,其IP为192.168.211.92,下面来部署路由,YAML文件如下:
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
name: nginx
spec:
prefix: /nginx/
service: 192.168.211.92
host_rewrite: 192.168.211.92
通过kubectl apply -f 部署后,在浏览器中可以通过hostIP+service/ambassador的port+prefix访问,如本测试为https://192.168.163.104:31058/nginx/
3、通过域名部署Route
下面来部署一个baidu.com的路由,YAML文件如下:
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
name: baidu
spec:
prefix: /baidu/
service: https://www.baidu.com
host_rewrite: www.baidu.com
通过kubectl apply -f 部署后,在浏览器中可以通过hostIP+service/ambassador的port+prefix访问,如本测试为https://192.168.163.104:31058/baidu/
可以看出已经顺利访问到百度。