Skip to content

Commit 67b0b50

Browse files
committed
first commit
0 parents  commit 67b0b50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+17837
-0
lines changed

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
6+
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
10+
11+
# Misc
12+
.DS_Store
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*

Makefile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SHELL := /bin/bash
2+
3+
start:
4+
npm run start
5+
install:
6+
npm install
7+
outdated:
8+
npm outdated
9+
init: install
10+
git clone --depth=1 [email protected]:imroc/kubernetes-guide.git build
11+
gen:
12+
npx docusaurus build --out-dir=./build/out
13+
push:
14+
cd build && git add -A && git commit -m update && git push
15+
update: install gen push
16+

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# istio 实践指南
2+
3+
## 关于本书
4+
5+
本书为电子书形式,内容为本人多年的云原生与 istio 实战经验进行系统性整理的结果,不废话,纯干货。
6+
7+
## 在线阅读
8+
9+
地址:https://imroc.cc/istio
10+
11+
## 评论与互动
12+
13+
本书已集成 [giscus](https://giscus.app/zh-CN) 评论系统,欢迎对感兴趣的文章进行评论与交流。
14+
15+
## 贡献
16+
17+
本书使用 [docusaurus](https://docusaurus.io/) 构建,已集成自动构建和发布,欢迎 Fork 并 PR 来贡献干货内容 (点击左下角 `编辑此页` 按钮可快速修改文章)。
18+
19+
## 许可证
20+
21+
您可以使用 [署名 - 非商业性使用 - 相同方式共享 4.0 (CC BY-NC-SA 4.0)](https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh) 协议共享。
22+

babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "start_time": "%START_TIME%", "route_name": "%ROUTE_NAME%", "method": "%REQ(:METHOD)%", "path": "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%", "protocol": "%PROTOCOL%", "response_code": "%RESPONSE_CODE%", "response_flags": "%RESPONSE_FLAGS%", "response_code_details": "%RESPONSE_CODE_DETAILS%", "connection_termination_details": "%CONNECTION_TERMINATION_DETAILS%", "bytes_received": "%BYTES_RECEIVED%", "bytes_sent": "%BYTES_SENT%", "duration": "%DURATION%", "upstream_service_time": "%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%", "x_forwarded_for": "%REQ(X-FORWARDED-FOR)%", "user_agent": "%REQ(USER-AGENT)%", "request_id": "%REQ(X-REQUEST-ID)%", "authority": "%REQ(:AUTHORITY)%", "upstream_host": "%UPSTREAM_HOST%", "upstream_cluster": "%UPSTREAM_CLUSTER%", "upstream_local_address": "%UPSTREAM_LOCAL_ADDRESS%", "downstream_local_address": "%DOWNSTREAM_LOCAL_ADDRESS%", "downstream_remote_address": "%DOWNSTREAM_REMOTE_ADDRESS%", "requested_server_name": "%REQUESTED_SERVER_NAME%", "upstream_transport_failure_reason": "%UPSTREAM_TRANSPORT_FAILURE_REASON%" }

codeblock/accesslog/json-format.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"start_time": "%START_TIME%",
3+
"route_name": "%ROUTE_NAME%",
4+
"method": "%REQ(:METHOD)%",
5+
"path": "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%",
6+
"protocol": "%PROTOCOL%",
7+
"response_code": "%RESPONSE_CODE%",
8+
"response_flags": "%RESPONSE_FLAGS%",
9+
"response_code_details": "%RESPONSE_CODE_DETAILS%",
10+
"connection_termination_details": "%CONNECTION_TERMINATION_DETAILS%",
11+
"bytes_received": "%BYTES_RECEIVED%",
12+
"bytes_sent": "%BYTES_SENT%",
13+
"duration": "%DURATION%",
14+
"upstream_service_time": "%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%",
15+
"x_forwarded_for": "%REQ(X-FORWARDED-FOR)%",
16+
"user_agent": "%REQ(USER-AGENT)%",
17+
"request_id": "%REQ(X-REQUEST-ID)%",
18+
"authority": "%REQ(:AUTHORITY)%",
19+
"upstream_host": "%UPSTREAM_HOST%",
20+
"upstream_cluster": "%UPSTREAM_CLUSTER%",
21+
"upstream_local_address": "%UPSTREAM_LOCAL_ADDRESS%",
22+
"downstream_local_address": "%DOWNSTREAM_LOCAL_ADDRESS%",
23+
"downstream_remote_address": "%DOWNSTREAM_REMOTE_ADDRESS%",
24+
"requested_server_name": "%REQUESTED_SERVER_NAME%",
25+
"upstream_transport_failure_reason": "%UPSTREAM_TRANSPORT_FAILURE_REASON%"
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: istio
5+
namespace: istio-system
6+
data:
7+
mesh: |
8+
# highlight-start
9+
accessLogFile: /dev/stdout
10+
accessLogFormat: |
11+
{ "start_time": "%START_TIME%", "route_name": "%ROUTE_NAME%", "method": "%REQ(:METHOD)%", "path": "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%", "protocol": "%PROTOCOL%", "response_code": "%RESPONSE_CODE%", "response_flags": "%RESPONSE_FLAGS%", "response_code_details": "%RESPONSE_CODE_DETAILS%", "connection_termination_details": "%CONNECTION_TERMINATION_DETAILS%", "bytes_received": "%BYTES_RECEIVED%", "bytes_sent": "%BYTES_SENT%", "duration": "%DURATION%", "upstream_service_time": "%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%", "x_forwarded_for": "%REQ(X-FORWARDED-FOR)%", "user_agent": "%REQ(USER-AGENT)%", "request_id": "%REQ(X-REQUEST-ID)%", "authority": "%REQ(:AUTHORITY)%", "upstream_host": "%UPSTREAM_HOST%", "upstream_cluster": "%UPSTREAM_CLUSTER%", "upstream_local_address": "%UPSTREAM_LOCAL_ADDRESS%", "downstream_local_address": "%DOWNSTREAM_LOCAL_ADDRESS%", "downstream_remote_address": "%DOWNSTREAM_REMOTE_ADDRESS%", "requested_server_name": "%REQUESTED_SERVER_NAME%", "upstream_transport_failure_reason": "%UPSTREAM_TRANSPORT_FAILURE_REASON%" }
12+
# highlight-end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: istio
5+
namespace: istio-system
6+
data:
7+
mesh: |
8+
# highlight-start
9+
accessLogFile: /dev/stdout
10+
accessLogFormat: |
11+
[%START_TIME%] "%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%" %RESPONSE_CODE% %RESPONSE_FLAGS% %RESPONSE_CODE_DETAILS% %CONNECTION_TERMINATION_DETAILS% "%UPSTREAM_TRANSPORT_FAILURE_REASON%" %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% "%REQ(X-FORWARDED-FOR)%" "%REQ(USER-AGENT)%" "%REQ(X-REQUEST-ID)%" "%REQ(:AUTHORITY)%" "%UPSTREAM_HOST%" %UPSTREAM_CLUSTER% %UPSTREAM_LOCAL_ADDRESS% %DOWNSTREAM_LOCAL_ADDRESS% %DOWNSTREAM_REMOTE_ADDRESS% %REQUESTED_SERVER_NAME% %ROUTE_NAME%
12+
# highlight-end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: istio
5+
namespace: istio-system
6+
data:
7+
mesh: |
8+
# highlight-start
9+
accessLogEncoding: JSON
10+
accessLogFile: /dev/stdout
11+
# highlight-end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: istio
5+
namespace: istio-system
6+
data:
7+
mesh: |
8+
# highlight-start
9+
accessLogEncoding: TEXT
10+
accessLogFile: /dev/stdout
11+
# highlight-end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"authority": "nginx.test.svc.cluster.local",
3+
"response_code": 404,
4+
"method": "GET",
5+
"upstream_service_time": "1",
6+
"user_agent": "curl/7.85.0",
7+
"bytes_received": 0,
8+
"start_time": "2023-10-08T06:19:16.705Z",
9+
"downstream_local_address": "172.16.244.170:80",
10+
"route_name": "default",
11+
"duration": 1,
12+
"response_code_details": "via_upstream",
13+
"upstream_host": "172.16.0.236:80",
14+
"upstream_cluster": "outbound|80||nignx.test.svc.cluster.local",
15+
"upstream_transport_failure_reason": null,
16+
"x_forwarded_for": null,
17+
"request_id": "19c42034-0f03-4195-ab33-d4a558ca1de4",
18+
"upstream_local_address": "172.16.0.237:35624",
19+
"requested_server_name": null,
20+
// highlight-next-line
21+
"request_body": "hello",
22+
"protocol": "HTTP/1.1",
23+
// highlight-next-line
24+
"response_body": "world",
25+
"connection_termination_details": null,
26+
"bytes_sent": 10480,
27+
"path": "/test",
28+
"downstream_remote_address": "172.16.0.237:44838",
29+
"response_flags": "-"
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
apiVersion: networking.istio.io/v1alpha3
2+
kind: EnvoyFilter
3+
metadata:
4+
name: accesslog-print-body
5+
# highlight-next-line
6+
namespace: test # 只为 test 命名空间开启 accesslog,若改为 istio-system 表示作用于所有命名空间
7+
spec:
8+
# highlight-start
9+
workloadSelector: # 通常打印 body 用于调试,可指定改配置只作用于指定 workload,避免影响其它不需要调试的 workload 的性能
10+
labels:
11+
app: nginx
12+
# highlight-end
13+
configPatches:
14+
- applyTo: NETWORK_FILTER
15+
match:
16+
listener:
17+
filterChain:
18+
filter:
19+
name: "envoy.filters.network.http_connection_manager"
20+
patch:
21+
operation: MERGE
22+
value:
23+
typed_config:
24+
"@type": "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"
25+
access_log:
26+
- name: envoy.access_loggers.file
27+
typed_config:
28+
"@type": "type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog"
29+
path: /dev/stdout
30+
log_format:
31+
json_format:
32+
start_time: "%START_TIME%"
33+
route_name: "%ROUTE_NAME%"
34+
method: "%REQ(:METHOD)%"
35+
path: "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%"
36+
protocol: "%PROTOCOL%"
37+
response_code: "%RESPONSE_CODE%"
38+
response_flags: "%RESPONSE_FLAGS%"
39+
response_code_details: "%RESPONSE_CODE_DETAILS%"
40+
connection_termination_details: "%CONNECTION_TERMINATION_DETAILS%"
41+
bytes_received: "%BYTES_RECEIVED%"
42+
bytes_sent: "%BYTES_SENT%"
43+
duration: "%DURATION%"
44+
upstream_service_time: "%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%"
45+
x_forwarded_for: "%REQ(X-FORWARDED-FOR)%"
46+
user_agent: "%REQ(USER-AGENT)%"
47+
request_id: "%REQ(X-REQUEST-ID)%"
48+
authority: "%REQ(:AUTHORITY)%"
49+
upstream_host: "%UPSTREAM_HOST%"
50+
upstream_cluster: "%UPSTREAM_CLUSTER%"
51+
upstream_local_address: "%UPSTREAM_LOCAL_ADDRESS%"
52+
downstream_local_address: "%DOWNSTREAM_LOCAL_ADDRESS%"
53+
downstream_remote_address: "%DOWNSTREAM_REMOTE_ADDRESS%"
54+
requested_server_name: "%REQUESTED_SERVER_NAME%"
55+
upstream_transport_failure_reason: "%UPSTREAM_TRANSPORT_FAILURE_REASON%"
56+
# highlight-start
57+
request_body: "%DYNAMIC_METADATA(envoy.lua:request_body)%"
58+
response_body: "%DYNAMIC_METADATA(envoy.lua:response_body)%"
59+
# highlight-end
60+
- applyTo: HTTP_FILTER
61+
match:
62+
context: ANY
63+
listener:
64+
filterChain:
65+
filter:
66+
name: "envoy.filters.network.http_connection_manager"
67+
subFilter:
68+
name: "envoy.filters.http.router"
69+
patch:
70+
operation: INSERT_BEFORE
71+
value:
72+
name: envoy.lua
73+
typed_config:
74+
"@type": "type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua"
75+
# highlight-start
76+
inlineCode: |
77+
function envoy_on_request(request_handle)
78+
local request_body_buffer = request_handle:body()
79+
if(request_body_buffer == nil)
80+
then
81+
request_handle:streamInfo():dynamicMetadata():set("envoy.lua", "request_body", "-")
82+
else
83+
local request_body_data = request_body_buffer:getBytes(0, request_body_buffer:length())
84+
request_handle:streamInfo():dynamicMetadata():set("envoy.lua", "request_body", request_body_data)
85+
end
86+
end
87+
function envoy_on_response(response_handle)
88+
local response_body_buffer = response_handle:body()
89+
if(response_body_buffer == nil)
90+
then
91+
response_handle:streamInfo():dynamicMetadata():set("envoy.lua", "response_body", "-")
92+
else
93+
local response_body_data = response_body_buffer:getBytes(0, response_body_buffer:length())
94+
response_handle:streamInfo():dynamicMetadata():set("envoy.lua", "response_body", response_body_data)
95+
end
96+
end
97+
# highlight-end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"authority": "nginx.test.svc.cluster.local",
3+
"response_code": 404,
4+
"method": "GET",
5+
"upstream_service_time": "1",
6+
"user_agent": "curl/7.85.0",
7+
"bytes_received": 0,
8+
"start_time": "2023-10-08T06:19:16.705Z",
9+
"downstream_local_address": "172.16.244.170:80",
10+
"route_name": "default",
11+
"duration": 1,
12+
"response_code_details": "via_upstream",
13+
"upstream_host": "172.16.0.236:80",
14+
"upstream_cluster": "outbound|80||nignx.test.svc.cluster.local",
15+
"upstream_transport_failure_reason": null,
16+
"x_forwarded_for": null,
17+
"request_id": "19c42034-0f03-4195-ab33-d4a558ca1de4",
18+
// highlight-start
19+
"response_headers": {
20+
"date": "Sun, 08 Oct 2023 06:19:16 GMT",
21+
"server": "nginx/1.23.4",
22+
"content-length": "10480",
23+
"x-envoy-upstream-service-time": "1",
24+
":status": "404",
25+
"content-type": "text/html",
26+
"etag": "\"65224347-28f0\"",
27+
"connection": "keep-alive"
28+
},
29+
// highlight-end
30+
"upstream_local_address": "172.16.0.237:35624",
31+
"requested_server_name": null,
32+
// highlight-next-line
33+
"request_body": "hello",
34+
"protocol": "HTTP/1.1",
35+
// highlight-next-line
36+
"response_body": "world",
37+
"connection_termination_details": null,
38+
"bytes_sent": 10480,
39+
"path": "/test",
40+
"downstream_remote_address": "172.16.0.237:44838",
41+
// highlight-start
42+
"request_headers": {
43+
"x-envoy-peer-metadata": "ChsKDkFQUF9DT05UQUlORVJTEgkaB3Rvb2xib3gKGgoKQ0xVU1RFUl9JRBIMGgpLdWJlcm5ldGVzCh4KDElOU1RBTkNFX0lQUxIOGgwxNzIuMTYuMC4yMzcKGQoNSVNUSU9fVkVSU0lPThIIGgYxLjE4LjMKywEKBkxBQkVMUxLAASq9AQoQCgNhcHASCRoHdG9vbGJveAokChpuZXR3b3JraW5nLmlzdGlvLmlvL3R1bm5lbBIGGgRodHRwCiQKGXNlY3VyaXR5LmlzdGlvLmlvL3Rsc01vZGUSBxoFaXN0aW8KLAofc2VydmljZS5pc3Rpby5pby9jYW5vbmljYWwtbmFtZRIJGgd0b29sYm94Ci8KI3NlcnZpY2UuaXN0aW8uaW8vY2Fub25pY2FsLXJldmlzaW9uEggaBmxhdGVzdAoaCgdNRVNIX0lEEg8aDWNsdXN0ZXIubG9jYWwKIgoETkFNRRIaGhh0b29sYm94LTY5ODk1OWY1YzctdGJoZmcKGAoJTkFNRVNQQUNFEgsaCW1lc2gtdGVzdApNCgVPV05FUhJEGkJrdWJlcm5ldGVzOi8vYXBpcy9hcHBzL3YxL25hbWVzcGFjZXMvbWVzaC10ZXN0L2RlcGxveW1lbnRzL3Rvb2xib3gKFwoRUExBVEZPUk1fTUVUQURBVEESAioAChoKDVdPUktMT0FEX05BTUUSCRoHdG9vbGJveA==",
44+
"x-envoy-decorator-operation": "nginx.test.svc.cluster.local:80/*",
45+
":scheme": "http",
46+
"user-agent": "curl/7.85.0",
47+
"x-request-id": "19c42034-0f03-4195-ab33-d4a558ca1de4",
48+
":method": "GET",
49+
"x-envoy-peer-metadata-id": "sidecar~172.16.0.237~toolbox-698959f5c7-tbhfg.test~test.svc.cluster.local",
50+
"accept": "*/*",
51+
":authority": "nginx.test.svc.cluster.local",
52+
"x-forwarded-proto": "http",
53+
":path": "/test"
54+
},
55+
// highlight-end
56+
"response_flags": "-"
57+
}

0 commit comments

Comments
 (0)