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. codeforces877c

    C. Slava and tanks time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. 区间DP POJ1160村庄邮局问题

    POJ1160 题目大意:一系列村庄在一维坐标系上有序的排列,建设p个邮局,问各个村庄到邮局的最短距离和. 线性区间DP问题 dp数组的值为最短/最优距离 村庄和邮局为限制 dp[i][j]表示前i个 ...

  3. java基础知识-比较运算符

    演示比较运算符 == : 判断两个值是否相等 != : 判断两个数是否不相等(不能写成<>) > :判断左边值是否大于右边值 < :判断左边值是否小于右边值 >= : 判 ...

  4. shell 命令 mkdir -p

    开发中我们会遇到嵌套创建文件目录的需要,这时需要用到 mkdir -p 比如我要在本地嵌套创建 /Users/dairui/Downloads/zookeeper/dataLogDir目录 直接使用 ...

  5. 在CentOS上安装GITLAB

    为什么要用gitlab? 方便地管理项目,设置用户权限. 参考 https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md 步 ...

  6. centos下网口vlan设置

    如果要使vlan之间进行通信,我们通常会使用三层交换机或者路由器子接口模式来做.Linux上关于VLAN与Cisco交换机中继连接,也是可以实现其互相之间的通信的. 环境:RHEL 5.2 最小化安装 ...

  7. glob

    主要是用来在匹配文件,相当shell中用通配符匹配. 用法: glob.glob(pathname) # 返回匹配的文件作为一个列表返回 glob.iglob(pathname) # 匹配到的文件名, ...

  8. Linux下可视化空间分析工具ncdu

    场景:磁盘空间占满后快速查找某个目录(子目录)占用空间大. ncdu /var (分析后按左右键查看即可)

  9. .NET MVC 学习笔记(二)— Bootstrap框架

    二..NET MVC 学习笔记(一)—— Bootstrap框架 在实际开发过程中,页面的样式问题是让人很头疼的问题,良好的用户界面可以大大提高用户体检,而在你没有前端开发人员的火力支援情况下,并不是 ...

  10. linux 如何开通新的端口

    第一种方式:(以nginx为列,端口是) 1.   开放端口命令: /sbin/iptables -I INPUT -p tcp --dport -j ACCEPT   2.   保存:/etc/rc ...