1、ambassador是datawire开源的服务网关,很好的支持kubernetes。具体详细介绍参考官网:https://www.getambassador.io/about/why-ambassador

本节主要讲述整个部署过程和简单实用,具体详细的资料抢参考官网。

2、部署

本次主要介绍将ambassador部署到自己的kubernetes集群里面,根据官网介绍部署方式有几种:

1)yaml部署,即定义yaml文件,使用kubectl 直接部署

2) helm部署,如果用helm部署则需要在kubernetes中现安装tiller(helm的server端)

yaml部署:

新版本的k8s集群都开启了rbac认证,所以需要提前创建rbac文件,进行授权:

wget   https://getambassador.io/yaml/ambassador/ambassador-rbac.yaml
---
apiVersion: v1
kind: Service
metadata:
labels:
service: ambassador-admin
name: ambassador-admin
namespace: tiller-world
spec:
type: NodePort
ports:
- name: ambassador-admin
port:
targetPort:
selector:
service: ambassador---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: ambassador
rules:
- apiGroups: [""]
resources:
- services
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources:
- configmaps
verbs: ["create", "update", "patch", "get", "list", "watch"]
- apiGroups: [""]
resources:
- secrets
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources:
- namespaces
verbs: ["get", "list", "watch"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: ambassador
namespace: tiller-world
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: ambassador
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: ambassador
subjects:
- kind: ServiceAccount
name: ambassador
namespace: tiller-world
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: ambassador
namespace: tiller-world
spec:
replicas:
template:
metadata:
annotations:
sidecar.istio.io/inject: "false"
"consul.hashicorp.com/connect-inject": "false"
labels:
service: ambassador
spec:
serviceAccountName: ambassador
containers:
- name: ambassador
image: quay.io/datawire/ambassador:0.50.-rc5
resources:
limits:
cpu: 200m
memory: 200Mi
requests:
cpu: 100m
memory: 100Mi
env:
- name: AMBASSADOR_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
ports:
- name: http
containerPort:
- name: https
containerPort:
- name: admin
containerPort:
livenessProbe:
httpGet:
path: /ambassador/v0/check_alive
port:
initialDelaySeconds:
periodSeconds:
readinessProbe:
httpGet:
path: /ambassador/v0/check_ready
port:
initialDelaySeconds:
periodSeconds:
restartPolicy: Always

我只修改了部署的namespace,tiller-world这个namespace是创建用helm部署程序用的。

创建角色及权限

kubectl  apply -f  ambassador-rbac.yaml

接下来创建ambassador的service:

暴漏服务有多种方式:LoadBalancer、NodePort、Ingress

这里我们使用NodePort暴漏服务,k8s默认的服务暴漏端口范围是30000~32767,当然这个端口的范围可以在启动apiserver的时候进行修改,指定--service-node-port-range=1-65535,修改为需要的端口范围,最好是不要将常见服务的端口包含在内,否则容易冲突。

# cat ambassador-svc.yaml
---
apiVersion: v1
kind: Service
metadata:
labels:
service: ambassador
name: ambssador
namespace: tiller-world
spec:
type: NodePort
ports:
- port:
targetPort:
nodePort:
selector:
service: ambassador

这里采用NodePort方式暴漏到服务器的30009端口。可以根据需要自己制定。

创建一个测试route:

# cat httpbin.yaml
---
apiVersion: v1
kind: Service
metadata:
name: httpbin
annotations:
getambassador.io/config: |
---
apiVersion: ambassador/v0
kind: Mapping
name: httpbin_mapping
prefix: /httpbin/
service: httpbin.org:
host_rewrite: httpbin.org
spec:
ports:
- name: httpbin
port:
# kubectl apply -f httpbin.yaml

查看部署:

# kubectl get pods -n tiller-world
NAME READY STATUS RESTARTS AGE
ambassador-5f66f5fd89-b2tqh / Running 138m
ambassador-5f66f5fd89-nbrgj / Running 138m
ambassador-5f66f5fd89-qxz55 / Running 138m
# kubectl get  svc -n tiller-world
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ambassador-admin NodePort 10.108.245.217 <none> :/TCP 138m
ambssador NodePort 10.105.112.156 <none> :/TCP 104m
httpbin ClusterIP 10.103.94.31 <none> /TCP 104m

测试访问:

访问的url:http://ip:30009/httpbin/,ip为kubernetes服务器的ip

部署一个service测试,部署qotm服务:

# cat qotm.yaml
---
apiVersion: v1
kind: Service
metadata:
name: qotm
annotations:
getambassador.io/config: |
---
apiVersion: ambassador/v0
kind: Mapping
name: qot_mapping
prefix: /qotm/
service: qotm
spec:
selector:
app: qotm
ports:
- port:
name: http-qotm
targetPort: http-api
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: qotm
spec:
replicas:
strategy:
type: RollingUpdate
template:
metadata:
labels:
app: qotm
spec:
containers:
- name: qotm
image: datawire/qotm:1.1
ports:
- name: http-api
containerPort:
resources:
limits:
cpu: "0.1"
memory: 100Mi
kubectl  apply  -f  qotm.yaml

service使用ambassador,只需要在service的定义里面添加注解就可以自动识别:

 annotations:
getambassador.io/config: |
---
apiVersion: ambassador/v0
kind: Mapping
name: qot_mapping
prefix: /qotm/
service: qotm

这里使用的是Mapping,uri前缀是/qotm/。详细的配置参考官网:https://www.getambassador.io/reference/mappings

先查看一下部署的服务:

# kubectl get svc  -n tiller-world
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ambassador-admin NodePort 10.108.245.217 <none> :/TCP 147m
ambssador NodePort 10.105.112.156 <none> :/TCP 113m
httpbin ClusterIP 10.103.94.31 <none> /TCP 113m
qotm ClusterIP 10.108.253.202 <none> /TCP 72m
tiller-deploy ClusterIP 10.102.176.214 <none> /TCP 4h47m 访问地址:http://ip:30009/qotm/

helm部署:

helm repo add datawire https://www.getambassador.io

helm upgrade --install --wait ambassador datawire/ambassador

当然也可以直接将chart  fetch到本地,自己根据需求进行定制:

helm  fetch --name ambassador datawire/ambassador

k8s服务网关ambassador部署的更多相关文章

  1. Bumblebee微服务网关的部署和扩展

    Bumblebee是.netcore下开源基于BeetleX.FastHttpApi扩展的HTTP微服务网关组件,它的主要作用是针对WebAPI集群服务作一个集中的转发和管理:作为应用网关它提供了应用 ...

  2. Blazor+Dapr+K8s微服务之基于WSL安装K8s集群并部署微服务

         前面文章已经演示过,将我们的示例微服务程序DaprTest1部署到k8s上并运行.当时用的k8s是Docker for desktop 自带的k8s,只要在Docker for deskto ...

  3. 微服务架构学习与思考(10):微服务网关和开源 API 网关01-以 Nginx 为基础的 API 网关详细介绍

    微服务架构学习与思考(10):微服务网关和开源 API 网关01-以 Nginx 为基础的 API 网关详细介绍 一.为什么会有 API Gateway 网关 随着微服务架构的流行,很多公司把原有的单 ...

  4. api-gateway实践(02)新服务网关 - 运行环境

    一.服务网关的运行环境 1.服务配置中心 1.1.服务配置中心前台 前台 http://10.110.17.20/#/login:无源码,德奎部署在10.110.17.20的DockerStatck环 ...

  5. .net core Ocelot实现API网关并部署在docker中

    基于Ocelot(http://ocelot.readthedocs.io)搭建的API网关demo 软件以及系统版本:  Asp.Net Core 2.2 Ocelot 13.5.0 CentOS ...

  6. 微服务-网关-node.js by 大雄daysn

    目录 序言 一.node.js入门1.1 下载并安装1.2 从helloworld到一个web应用1.3 Express框架二.node.js搭建网关 三.node.js集群搭建   序言 首先一个问 ...

  7. 使用 Node.js 搭建微服务网关

    目录 Node.js 是什么 安装 node.js Node.js 入门 Node.js 应用场景 npm 镜像 使用 Node.js 搭建微服务网关 什么是微服务架构 使用 Node.js 实现反向 ...

  8. .NET Core 微服务架构-Docker部署

    本文主要介绍通过Docker来部署通过.NET Core开发的微服务架构,部署的微服务主要包括统一网关(使用Ocelot开发).统一认证(IdentityServer4).应用服务(ASP.NET C ...

  9. ambassador 学习九 多ambassador部署说明

    目前官方稳文档没有写,但是demo 里面有,所以就整理出来,其实目前demo里面的 多实例部署用了多个服务的service(使用nodeport 暴露地址,具体使用就是制定ambassador 实例的 ...

随机推荐

  1. POJ3176 Cow Bowling 2017-06-29 14:33 23人阅读 评论(0) 收藏

    Cow Bowling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19173   Accepted: 12734 Des ...

  2. Codeforces816A Karen and Morning 2017-06-27 15:11 43人阅读 评论(0) 收藏

    A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...

  3. 第85讲:Scala中For表达式的强大表现力实战

    今天来学一下scala中的For表达式的用法. package scala.learn case class Persons(name:String,isMale:Boolean,children:P ...

  4. PL/SQL客户端连Oracle很快就断开问题的解决

    PL/SQL登录很短时间session就自动断开 1.首先查看你这个用户的profile文件 select profile from dba_users where username='USERNAM ...

  5. min cost max flow算法示例

    问题描述 给定g个group,n个id,n<=g.我们将为每个group分配一个id(各个group的id不同).但是每个group分配id需要付出不同的代价cost,需要求解最优的id分配方案 ...

  6. 关于ubuntu软件卸载的问题

    ...... 起因很菜....就是手贱把/usr/lib/下的R的目录给rm -rf掉了, 然后在R的软件包里用./configure也生不成, R RHOME还在, 然而因为lib下的R删掉了所以R ...

  7. 【BZOJ2589】 Spoj 10707 Count on a tree II

    BZOJ2589 Spoj 10707 Count on a tree II Solution 吐槽:这道题目简直...丧心病狂 如果没有强制在线不就是树上莫队入门题? 如果加了强制在线怎么做? 考虑 ...

  8. 【文文殿下】NOIp2018游记

    Day-1 本段更新于 2018年11月8日23:26:44 今天还在机房里面,无所事事吧.上午睡了一上午,出去理了一下发,花了20块钱 QAQ. 下午来到机房,复习了一下exgcd的东西. 发现自己 ...

  9. Python资源 --Python库

    环境管理 管理 Python 版本和环境的工具 pyenv – 简单的 Python 版本管理工具. Vex – 可以在虚拟环境中执行命令. virtualenv – 创建独立 Python 环境的工 ...

  10. vscode 学习笔记 —— 重构

    一.vscode 自带 1.提取变量 2.提取方法 上面都是通过选中文本后出现的小灯泡操作的: 3.全局替换(多个文件中的)某个变量 选中变量按 F2,输入完成后按回车 二.vscode 插件 js- ...