開發者能夠經過kuberneters annotation,很容易控制服務的流量,實現灰度發佈api
developer能夠經過kubernetes service 的annotations來定義ambassadorf服務,很容易集成到你的現有項目中。架構
developer能夠經過kuberneters annotation很容易控制到服務的流量,實現金絲雀發佈。app
利用k8s原生能力實現可靠性、可用性和可伸縮性。使用envoy實現路由和代理curl
由envoy提供的能力異步
和istio配合實現服務網格。ambassador做爲邊緣代理,實現外部流量到內部istio的橋樑。ide
ambassador支持請求認證。若是配置了,ambassador在路由以前會事先請求第三方認證服務微服務
ambassador支持限流。ambassador在路由以前會事先請求第三方速度限流服務測試
ambassador包含一個診斷服務,能夠快速定位問題ui
install deploythis
sv1 請求返回"Hello World, this is test service num 1!"
sv2 請求返回"Hello World, this is test service num 2!"
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: svc1 spec: replicas: 1 strategy: type: RollingUpdate template: metadata: labels: app: svc1 spec: containers: - name: svc1 image: ambassador-sv1:1.0 ports: - name: http-api containerPort: 5000 resources: limits: cpu: "0.1" memory: 100Mi --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: svc2 spec: replicas: 1 strategy: type: RollingUpdate template: metadata: labels: app: svc2 spec: containers: - name: svc2 image: ambassador-sv2:1.0 ports: - name: http-api containerPort: 5000 resources: limits: cpu: "0.1" memory: 100Mi
以80%的機率路由到svc1, 20%的機率路由到svc2
svc1 (不配置權重,默認100%)
--- apiVersion: v1 kind: Service metadata: name: svc1 namespace: 295-a222222 annotations: getambassador.io/config: | --- apiVersion: ambassador/v0 kind: Mapping name: svc1_mapping prefix: /svc/ service: svc1.295-a222222:8080 spec: selector: app: svc1 ports: - port: 8080 name: http-svc targetPort: http-api
svc2
--- apiVersion: v1 kind: Service metadata: name: svc2 namespace: 295-a222222 annotations: getambassador.io/config: | --- apiVersion: ambassador/v0 kind: Mapping name: svc2_mapping prefix: /svc/ service: svc2.295-a222222:8080 weight: 20 spec: selector: app: svc2 ports: - port: 8080 name: http-svc targetPort: http-api
結果:
[root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 2![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 2![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 2![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl
請求頭中包含Cookie: UM_distinctid=12345
的請求所有路由到svc2中
--- apiVersion: v1 kind: Service metadata: name: svc2 annotations: getambassador.io/config: | --- apiVersion: ambassador/v0 kind: Mapping name: svc2_mapping prefix: /svc/ service: svc2 headers: Cookie: UM_distinctid=12345 spec: selector: app: svc2 ports: - port: 80 name: http-svc2 targetPort: http-api
apiVersion: v1 kind: Service metadata: annotations: getambassador.io/config: | --- apiVersion: ambassador/v0 kind: Mapping name: create prefix: /svc/create/ service: create:8080 regex_headers: Cookie: "ddddd.*"
結果:
[root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# curl 10.104.75.142:80/svc/ Hello World, this is test service num 1![root@master01 ambassador]# [root@master01 ambassador]# [root@master01 ambassador]# curl -H "Cookie: UM_distinctid=12345" 10.104.75.142:80/svc/ Hello World, this is test service num 2![root@master01 ambassador]# curl -H "Cookie: UM_distinctid=12345" 10.104.75.142:80/svc/ Hello World, this is test service num 2![root@master01 ambassador]# curl -H "Cookie: UM_distinctid=12345" 10.104.75.142:80/svc/ Hello World, this is test service num 2![root@master01 ambassador]# curl -H "Cookie: UM_distinctid=12345" 10.104.75.142:80/svc/ Hello World, this is test service num 2![root@master01 ambassador]# curl -H "Cookie: UM_distinctid=12345" 10.104.75.142:80/svc/ Hello World, this is test service num 2![root@master01 ambassador]# curl -H "Cookie: UM_distinctid=12345" 10.104.75.142:80/svc/ Hello World, this is test service num 2![root@master01 ambassador]#
即須要更新的業務,此時業務流向全走向svc1
kubectl apply -f svc1.yaml
apiVersion: v1 kind: Service metadata: name: svc1 annotations: getambassador.io/config: | --- apiVersion: ambassador/v0 kind: Mapping name: svc1_mapping prefix: /svc/ service: svc1 spec: ····
查看ambassador的流量代理
url | service | weight |
---|---|---|
http://172.31.133.26:31327/svc/ | svc1 | 100.0% |
部署svc2.yaml,此時帶header: Cookie: UM_distinctid=12345
流量走向svc2,不帶header流量依舊走svc1。
kubectl apply -f svc2.yaml
--- apiVersion: v1 kind: Service metadata: name: svc2 annotations: getambassador.io/config: | --- apiVersion: ambassador/v0 kind: Mapping name: svc2_mapping prefix: /svc/ service: svc2 headers: Cookie: UM_distinctid=12345 spec: ···
查看ambassador的流量代理
url | service | weight |
---|---|---|
http://172.31.133.26:31327/svc/ | svc1 | 100.0% |
http://172.31.133.26:31327/svc/ Cookie: UM_distinctid=12345 |
svc2 | 100.0% |
更新header(去掉header),此時一半流量到svc1,一半到svc2
kubectl apply -f svc2.yaml
--- apiVersion: v1 kind: Service metadata: name: svc2 annotations: getambassador.io/config: | --- apiVersion: ambassador/v0 kind: Mapping name: svc2_mapping prefix: /svc/ service: svc2 # headers: # Cookie: UM_distinctid=12345 spec: ···
查看ambassador的流量代理
url | service | weight |
---|---|---|
http://172.31.133.26:31327/svc/ | svc1 svc2 |
50.0% 100.0% |
下線老的服務svc1,流量所有走到svc2
kubectl delete -f svc1.yaml
查看ambassador的流量代理
url | service | weight |
---|---|---|
http://172.31.133.26:31327/svc/ | svc2 | 100.0% |