非k8s环境安装
with consul
可以参考官方文档:https://docs.solo.io/gloo-edge/latest/installation/gateway/development/docker-compose-consul/
- 下载官方仓库
git clone https://github.com/solo-io/gloo.git
2.安装并准备好docker环境
3.docker-compose 启动gloo及相关软件
cd path/to/gloo/source/install/docker-compose-consul
运行prepare-directories.sh
cd data/gloo-system
default.yaml 添加开启fds的配置如下
discovery:
#set to either WHITELIST, BLACKLIST, or DISABLED WHITELIST is the default value
fdsMode: BLACKLIST
docker-compose up &
http://xxxx:8500 查看consul
http://xxxx:19000 查看控制台
4.基本配置和使用
-
添加网关
curl --request PUT --data-binary @./install/docker-compose-consul/data/gateways/gloo-system/gw-proxy.yaml http://127.0.0.1:8500/v1/kv/gloo/gateway.solo.io/v1/Gateway/gloo-system -
配置visualservice
获取ip并生成文件
PETSTORE_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' docker-compose-consul_petstore_1)
cat > petstore-service.json <<EOF
{
"ID": "petstore1",
"Name": "petstore",
"Address": "${PETSTORE_IP}",
"Port": 8080
}
EOF
将生成的文件注册到consul
curl -v -XPUT --data @petstore-service.json "http://127.0.0.1:8500/v1/agent/service/register"
观察consul的service,此时多了petstore为刚才注册上来的服务
image.png
添加路由
glooctl add route \
--path-exact /all-pets \
--dest-name petstore \
--prefix-rewrite /api/pets \
--use-consul
输出:
+-----------------+--------------+---------+------+---------+-----------------+--------------------------------+
| VIRTUAL SERVICE | DISPLAY NAME | DOMAINS | SSL | STATUS | LISTENERPLUGINS | ROUTES |
+-----------------+--------------+---------+------+---------+-----------------+--------------------------------+
| default | | * | none | Pending | | /all-pets -> |
| | | | | | | gloo-system.petstore |
| | | | | | | (upstream) |
+-----------------+--------------+---------+------+---------+-----------------+--------------------------------+
验证路由添加的结果
curl http://localhost:8080/all-pets
结果:
[{"id":1,"name":"Dog","status":"available"},{"id":2,"name":"Cat","status":"pending"}]
-
如果添加完毕后路由无法访问到,请按照下图修改配置
image.png -
开启函数发现功能(gloo/install/docker-compose-consul/data/gloo-system/default.yaml)
gloo:
xdsBindAddr: 0.0.0.0:9977
consul:
address: consul:8500
serviceDiscovery: {}
consulKvSource: {}
consulKvArtifactSource: {}
discoveryNamespace: gloo-system
#开启函数发现功能 (gloo/install/docker-compose-consul/data/gloo-system/default.yaml)
discovery:
# set to either WHITELIST, BLACKLIST, or DISABLED .
# WHITELIST is the default value
fdsMode: BLACKLIST
metadata:
name: default
namespace: gloo-system
refreshRate: 15s
vaultSecretSource:
address: http://vault:8200
token: root
- multi destination
routes:
- matchers:
- prefix: /myservice
routeAction:
multi:
destinations:
- weight: 9
destination:
upstream:
name: default-myservice-v1-8080
namespace: gloo-system
- weight: 1
destination:
upstream:
name: default-myservice-v2-8080
namespace: gloo-system
with local
请见官方文档:https://docs.solo.io/gloo-edge/latest/installation/gateway/development/docker-compose-file/
网友评论