一、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)境變量
# 啟動(dòng)
docker-compose up
# 驗(yàn)證
curl 172.31.1.2
- http-ingress
cd servicemesh_in_practise/Envoy-Basics/http-ingress
# 修改docker-compose配置文件渗勘,如上所示嗓袱,添加環(huán)境變量
# 啟動(dòng)
docker-compose up
# 驗(yàn)證
curl 172.31.3.2
- http-egress
cd servicemesh_in_practise/Envoy-Basics/http-egress
# 修改docker-compose配置文件醒第,如上所示,添加環(huán)境變量
# 啟動(dòng)
docker-compose up
# 進(jìn)入容器驗(yàn)證
docker exec -it httpegress_client_1 bash
curl 127.0.0.1
- http-front-proxy
cd servicemesh_in_practise/Envoy-Basics/http-front-proxy
# 修改docker-compose配置文件叹俏,如上所示芦鳍,添加環(huán)境變量
# 啟動(dòng)
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
- admin-interface
cd servicemesh_in_practise/Envoy-Basics/admin-interface
# 修改docker-compose配置文件嚷往,如上所示,添加環(huán)境變量
# 啟動(dòng)
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
- layered-runtime
cd servicemesh_in_practise/Envoy-Basics/layered-runtime
# 修改docker-compose配置文件,如上所示贷祈,添加環(huán)境變量
# 啟動(dòng)
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"
二付燥、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键科,需要保持一致
# 啟動(dòng)
docker-compose up
# 驗(yàn)證