Envoy示例

一、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: # 添加環(huán)境變量
    - ENVOY_UID=0 # 添加環(huán)境變量
# 啟動
docker-compose up 

# 驗(yàn)證
curl 172.31.1.2
image.png
  • http-ingress
cd servicemesh_in_practise/Envoy-Basics/http-ingress
# 修改docker-compose配置文件,如上所示,添加環(huán)境變量
# 啟動
docker-compose up

# 驗(yàn)證
curl 172.31.3.2
image.png
  • http-egress
cd servicemesh_in_practise/Envoy-Basics/http-egress
# 修改docker-compose配置文件,如上所示,添加環(huán)境變量
# 啟動
docker-compose up

# 進(jìn)入容器驗(yàn)證
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配置文件,如上所示,添加環(huán)境變量
# 啟動
docker-compose up

# 驗(yàn)證
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配置文件,如上所示,添加環(huán)境變量
# 啟動
docker-compose up

# 驗(yàn)證
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 # 查看監(jiān)聽端口
curl 172.31.5.2:9901/clusters # 查看集群
curl 172.31.5.2:9901/config_dump # 打印配置信息
curl 172.31.5.2:9901/stats # 統(tǒng)計(jì)數(shù)據(jù)信息接口
curl 172.31.5.2:9901/stats/prometheus # 查看prometheus數(shù)據(jù)兼容格式

prometheus四種數(shù)據(jù)類型:counter,guage,histogram,summary

image.png
  • layered-runtime
cd servicemesh_in_practise/Envoy-Basics/layered-runtime
# 修改docker-compose配置文件,如上所示,添加環(huán)境變量
# 啟動
docker-compose up

# 驗(yàn)證
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應(yīng)用

  • 修改鏡像,使用http-ingress代理方式起應(yīng)用
# 修改docker-compose配置文件
vim docker-compose.yaml
services:
  envoy:
    image: envoyproxy/envoy-alpine:v1.21-latest
    environment: # 添加環(huán)境變量
    - ENVOY_UID=0 # 添加環(huán)境變量
  ...
  webserver01:
    image: ikubernetes/spring-boot-helloworld:v0.9.6 # 修改應(yīng)用鏡像

# 修改envoy配置文件
vim envoy.yaml
static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address: { address: 0.0.0.0, port_value: 81 } # 修改envoy監(jiān)聽端口
  ...
        - endpoint:
            address:
              socket_address: { address: 127.0.0.1, port_value: 80 } # 修改應(yīng)用監(jiān)聽端口號,demo應(yīng)用監(jiān)聽端口號為80,需要保持一致
# 啟動
docker-compose up

# 驗(yàn)證

image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容