开发者能够经过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% |