Envoy示例

作者: Walker_7797 | 来源:发表于2022-04-19 09:29 被阅读0次

一、envoy示例

  • 克隆envoy示例仓库
git clone https://github.com/iKubernetes/servicemesh_in_practise.git
git checkout develop # 切换到develop分支
  • tcp-proxy
cd servicemesh_in_practise/Envoy-Basics/tcp-front-proxy/
# 修改docker-compose配置文件
vim docker-compose.yaml
services:
  envoy:
    image: envoyproxy/envoy-alpine:v1.21-latest
    environment: # 添加环境变量
    - ENVOY_UID=0 # 添加环境变量
# 启动
docker-compose up 

# 验证
curl 172.31.1.2
image.png
  • http-ingress
cd servicemesh_in_practise/Envoy-Basics/http-ingress
# 修改docker-compose配置文件,如上所示,添加环境变量
# 启动
docker-compose up

# 验证
curl 172.31.3.2
image.png
  • http-egress
cd servicemesh_in_practise/Envoy-Basics/http-egress
# 修改docker-compose配置文件,如上所示,添加环境变量
# 启动
docker-compose up

# 进入容器验证
docker exec -it httpegress_client_1 bash
curl 127.0.0.1
image.png
  • http-front-proxy
cd servicemesh_in_practise/Envoy-Basics/http-front-proxy
# 修改docker-compose配置文件,如上所示,添加环境变量
# 启动
docker-compose up

# 验证
curl -H "Host: www.ik8s.io" 172.31.2.2
curl -I -H "Host: www.magedu.com" 172.31.2.2
image.png
  • admin-interface
cd servicemesh_in_practise/Envoy-Basics/admin-interface
# 修改docker-compose配置文件,如上所示,添加环境变量
# 启动
docker-compose up

# 验证
curl -H "Host: www.ik8s.io" 172.31.2.2
curl -I -H "Host: www.magedu.com" 172.31.2.2
curl 172.31.5.2:9901 # 访问管理页面
curl 172.31.5.2:9901/help # 以文本形式展示管理页面
admin commands are:
  /: Admin home page
  /certs: print certs on machine
  /clusters: upstream cluster status
  /config_dump: dump current Envoy configs (experimental)
  /contention: dump current Envoy mutex contention stats (if enabled)
  /cpuprofiler: enable/disable the CPU profiler
  /drain_listeners: drain listeners
  /healthcheck/fail: cause the server to fail health checks
  /healthcheck/ok: cause the server to pass health checks
  /heapprofiler: enable/disable the heap profiler
  /help: print out list of admin commands
  /hot_restart_version: print the hot restart compatibility version
  /init_dump: dump current Envoy init manager information (experimental)
  /listeners: print listener info
  /logging: query/change logging levels
  /memory: print current allocation/heap usage
  /quitquitquit: exit the server
  /ready: print server state, return 200 if LIVE, otherwise return 503
  /reopen_logs: reopen access logs
  /reset_counters: reset all counters to zero
  /runtime: print runtime values
  /runtime_modify: modify runtime values
  /server_info: print server version/status information
  /stats: print server stats
  /stats/prometheus: print server stats in prometheus format
  /stats/recentlookups: Show recent stat-name lookups
  /stats/recentlookups/clear: clear list of stat-name lookups and counter
  /stats/recentlookups/disable: disable recording of reset stat-name lookup names
  /stats/recentlookups/enable: enable recording of reset stat-name lookup names
curl 172.31.5.2:9901/listeners # 查看监听端口
curl 172.31.5.2:9901/clusters # 查看集群
curl 172.31.5.2:9901/config_dump # 打印配置信息
curl 172.31.5.2:9901/stats # 统计数据信息接口
curl 172.31.5.2:9901/stats/prometheus # 查看prometheus数据兼容格式

prometheus四种数据类型:counter,guage,histogram,summary

image.png
  • layered-runtime
cd servicemesh_in_practise/Envoy-Basics/layered-runtime
# 修改docker-compose配置文件,如上所示,添加环境变量
# 启动
docker-compose up

# 验证
curl 172.31.14.2:9901/runtime # 查看runtime配置
curl -XPOST 172.31.14.2:9901/runtime_modify?hi=true # 修改runtime配置,添加hi=true值,添加成功返回"ok"
image.png
image.png

二、envoy springboot应用

  • 修改镜像,使用http-ingress代理方式起应用
# 修改docker-compose配置文件
vim docker-compose.yaml
services:
  envoy:
    image: envoyproxy/envoy-alpine:v1.21-latest
    environment: # 添加环境变量
    - ENVOY_UID=0 # 添加环境变量
  ...
  webserver01:
    image: ikubernetes/spring-boot-helloworld:v0.9.6 # 修改应用镜像

# 修改envoy配置文件
vim envoy.yaml
static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address: { address: 0.0.0.0, port_value: 81 } # 修改envoy监听端口
  ...
        - endpoint:
            address:
              socket_address: { address: 127.0.0.1, port_value: 80 } # 修改应用监听端口号,demo应用监听端口号为80,需要保持一致
# 启动
docker-compose up

# 验证

image.png

相关文章

网友评论

    本文标题:Envoy示例

    本文链接:https://www.haomeiwen.com/subject/kyzrertx.html