新增learn-kubernetes(https://github.com/yyong-brs/learn-kubernetes)相关文件
This commit is contained in:
71
learn/learn-kubernetes-master/kiamol/ch13/lab/README.md
Normal file
71
learn/learn-kubernetes-master/kiamol/ch13/lab/README.md
Normal file
@@ -0,0 +1,71 @@
|
||||
# Ch13 lab
|
||||
|
||||
## Setup
|
||||
|
||||
Deploy the logging subsystem:
|
||||
|
||||
```
|
||||
kubectl apply -f lab/logging/
|
||||
```
|
||||
|
||||
## Sample Solution
|
||||
|
||||
### Part 1
|
||||
|
||||
Fluent Bit is [configured](./logging/fluentbit-config.yaml) to store entries from Pods in the namespace `kiamol-ch13-lab`.
|
||||
|
||||
Create that namespace and deploy the vweb app:
|
||||
|
||||
```
|
||||
kubectl create ns kiamol-ch13-lab
|
||||
|
||||
kubectl apply -f lab/vweb/ -n kiamol-ch13-lab
|
||||
```
|
||||
|
||||
> Browse to the app which will trigger Nginx logs in the container.
|
||||
|
||||
> Browse to Kibana and create an index pattern for the index called `lab` - verify that logs are coming through.
|
||||
|
||||

|
||||
|
||||
## Part 2
|
||||
|
||||
The logs are there, but not parsed so they're just text.
|
||||
|
||||
Deploy an update to the [vweb Deployment](./solution/vweb-with-parser.yaml) which adds an annotation to use the Nginx parser:
|
||||
|
||||
```
|
||||
kubectl apply -f lab/solution/vweb-with-parser.yaml -n kiamol-ch13-lab
|
||||
```
|
||||
|
||||
> Browse to the app again and refresh Kibana - the logs should have fields for HTTP path, response code etc.
|
||||
|
||||

|
||||
|
||||
|
||||
### Part 3
|
||||
|
||||
Now to filter out 304s, add a [grep filter](./solution/fluentbit-config-grep.yaml) to the Fluent Bit config and update the Pod:
|
||||
|
||||
```
|
||||
kubectl apply -f lab/solution/fluentbit-config-grep.yaml
|
||||
|
||||
kubectl rollout restart ds/fluent-bit -n kiamol-ch13-lab-logging
|
||||
|
||||
kubectl wait --for=condition=ContainersReady pod -l app=fluent-bit -n kiamol-ch13-lab-logging
|
||||
|
||||
```
|
||||
|
||||
> Browse to the app again and refresh Kibana - no 304s are shown for recent requests
|
||||
|
||||

|
||||
|
||||
## Teardown
|
||||
|
||||
Remove the namespaces and that removes everything:
|
||||
|
||||
```
|
||||
kubectl delete ns kiamol-ch13-lab
|
||||
|
||||
kubectl delete ns kiamol-ch13-lab-logging
|
||||
```
|
||||
BIN
learn/learn-kubernetes-master/kiamol/ch13/lab/docs/part1.png
Normal file
BIN
learn/learn-kubernetes-master/kiamol/ch13/lab/docs/part1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 170 KiB |
BIN
learn/learn-kubernetes-master/kiamol/ch13/lab/docs/part2.png
Normal file
BIN
learn/learn-kubernetes-master/kiamol/ch13/lab/docs/part2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
BIN
learn/learn-kubernetes-master/kiamol/ch13/lab/docs/part3.png
Normal file
BIN
learn/learn-kubernetes-master/kiamol/ch13/lab/docs/part3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
@@ -0,0 +1,6 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: kiamol-ch13-lab-logging
|
||||
labels:
|
||||
kiamol: ch13-lab
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: elasticsearch
|
||||
namespace: kiamol-ch13-lab-logging
|
||||
spec:
|
||||
selector:
|
||||
app: elasticsearch
|
||||
ports:
|
||||
- name: elasticsearch
|
||||
port: 9200
|
||||
targetPort: 9200
|
||||
type: ClusterIP
|
||||
@@ -0,0 +1,20 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: elasticsearch
|
||||
namespace: kiamol-ch13-lab-logging
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: elasticsearch
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: elasticsearch
|
||||
spec:
|
||||
containers:
|
||||
- image: kiamol/ch13-elasticsearch
|
||||
name: elasticsearch
|
||||
ports:
|
||||
- containerPort: 9200
|
||||
name: elasticsearch
|
||||
@@ -0,0 +1,62 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: fluent-bit-config
|
||||
namespace: kiamol-ch13-lab-logging
|
||||
data:
|
||||
fluent-bit.conf: |
|
||||
[SERVICE]
|
||||
Flush 5
|
||||
Log_Level warn
|
||||
Daemon off
|
||||
Parsers_File parsers.conf
|
||||
|
||||
@INCLUDE input.conf
|
||||
@INCLUDE filter.conf
|
||||
@INCLUDE output.conf
|
||||
|
||||
input.conf: |
|
||||
[INPUT]
|
||||
Name tail
|
||||
Tag kube.<namespace_name>.<container_name>.<pod_name>.<docker_id>-
|
||||
Tag_Regex (?<pod_name>[a-z0-9](?:[-a-z0-9]*[a-z0-9])?(?:\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)_(?<namespace_name>[^_]+)_(?<container_name>.+)-(?<docker_id>[a-z0-9]{64})\.log$
|
||||
Path /var/log/containers/*.log
|
||||
Parser docker
|
||||
Refresh_Interval 10
|
||||
|
||||
filter.conf: |
|
||||
[FILTER]
|
||||
Name kubernetes
|
||||
Match kube.*
|
||||
Kube_Tag_Prefix kube.
|
||||
Regex_Parser kube-tag
|
||||
Merge_Log On
|
||||
K8S-Logging.Parser On
|
||||
|
||||
output.conf: |
|
||||
[OUTPUT]
|
||||
Name es
|
||||
Match kube.kiamol-ch13-lab.*
|
||||
Host elasticsearch
|
||||
Index lab
|
||||
Generate_ID On
|
||||
|
||||
parsers.conf: |
|
||||
[PARSER]
|
||||
Name docker
|
||||
Format json
|
||||
Time_Key time
|
||||
Time_Format %Y-%m-%dT%H:%M:%S.%L
|
||||
Time_Keep On
|
||||
|
||||
[PARSER]
|
||||
Name kube-tag
|
||||
Format regex
|
||||
Regex ^(?<namespace_name>[^_]+)\.(?<container_name>.+)\.(?<pod_name>[a-z0-9](?:[-a-z0-9]*[a-z0-9])?(?:\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)\.(?<docker_id>[a-z0-9]{64})-$
|
||||
|
||||
[PARSER]
|
||||
Name nginx
|
||||
Format regex
|
||||
Regex ^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?
|
||||
Time_Key time
|
||||
Time_Format %d/%b/%Y:%H:%M:%S %z
|
||||
@@ -0,0 +1,35 @@
|
||||
apiVersion: apps/v1
|
||||
kind: DaemonSet
|
||||
metadata:
|
||||
name: fluent-bit
|
||||
namespace: kiamol-ch13-lab-logging
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: fluent-bit
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: fluent-bit
|
||||
spec:
|
||||
containers:
|
||||
- name: fluent-bit
|
||||
image: fluent/fluent-bit:1.4.6
|
||||
volumeMounts:
|
||||
- name: fluent-bit-config
|
||||
mountPath: /fluent-bit/etc/
|
||||
- name: varlog
|
||||
mountPath: /var/log
|
||||
- name: varlibdockercontainers
|
||||
mountPath: /var/lib/docker/containers
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: fluent-bit-config
|
||||
configMap:
|
||||
name: fluent-bit-config
|
||||
- name: varlog
|
||||
hostPath:
|
||||
path: /var/log
|
||||
- name: varlibdockercontainers
|
||||
hostPath:
|
||||
path: /var/lib/docker/containers
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: kibana
|
||||
namespace: kiamol-ch13-lab-logging
|
||||
spec:
|
||||
selector:
|
||||
app: kibana
|
||||
ports:
|
||||
- name: kibana
|
||||
port: 5601
|
||||
targetPort: 5601
|
||||
type: LoadBalancer
|
||||
@@ -0,0 +1,20 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: kibana
|
||||
namespace: kiamol-ch13-lab-logging
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: kibana
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: kibana
|
||||
spec:
|
||||
containers:
|
||||
- image: kiamol/ch13-kibana
|
||||
name: kibana
|
||||
ports:
|
||||
- containerPort: 5601
|
||||
name: kibana
|
||||
@@ -0,0 +1,68 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: fluent-bit-config
|
||||
namespace: kiamol-ch13-lab-logging
|
||||
data:
|
||||
fluent-bit.conf: |
|
||||
[SERVICE]
|
||||
Flush 5
|
||||
Log_Level error
|
||||
Daemon off
|
||||
Parsers_File parsers.conf
|
||||
|
||||
@INCLUDE input.conf
|
||||
@INCLUDE filter.conf
|
||||
@INCLUDE output.conf
|
||||
|
||||
input.conf: |
|
||||
[INPUT]
|
||||
Name tail
|
||||
Tag kube.<namespace_name>.<container_name>.<pod_name>.<docker_id>-
|
||||
Tag_Regex (?<pod_name>[a-z0-9](?:[-a-z0-9]*[a-z0-9])?(?:\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)_(?<namespace_name>[^_]+)_(?<container_name>.+)-(?<docker_id>[a-z0-9]{64})\.log$
|
||||
Path /var/log/containers/*.log
|
||||
Parser docker
|
||||
Refresh_Interval 10
|
||||
|
||||
filter.conf: |
|
||||
[FILTER]
|
||||
Name kubernetes
|
||||
Match kube.*
|
||||
Kube_Tag_Prefix kube.
|
||||
Regex_Parser kube-tag
|
||||
Annotations Off
|
||||
Merge_Log On
|
||||
K8S-Logging.Parser On
|
||||
|
||||
[FILTER]
|
||||
Name grep
|
||||
Match kube.kiamol-ch13-lab.web.vweb*
|
||||
Exclude code 304
|
||||
|
||||
output.conf: |
|
||||
[OUTPUT]
|
||||
Name es
|
||||
Match kube.kiamol-ch13-lab.*
|
||||
Host elasticsearch
|
||||
Index lab
|
||||
Generate_ID On
|
||||
|
||||
parsers.conf: |
|
||||
[PARSER]
|
||||
Name docker
|
||||
Format json
|
||||
Time_Key time
|
||||
Time_Format %Y-%m-%dT%H:%M:%S.%L
|
||||
Time_Keep On
|
||||
|
||||
[PARSER]
|
||||
Name kube-tag
|
||||
Format regex
|
||||
Regex ^(?<namespace_name>[^_]+)\.(?<container_name>.+)\.(?<pod_name>[a-z0-9](?:[-a-z0-9]*[a-z0-9])?(?:\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)\.(?<docker_id>[a-z0-9]{64})-$
|
||||
|
||||
[PARSER]
|
||||
Name nginx
|
||||
Format regex
|
||||
Regex ^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?
|
||||
Time_Key time
|
||||
Time_Format %d/%b/%Y:%H:%M:%S %z
|
||||
@@ -0,0 +1,22 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
annotations:
|
||||
fluentbit.io/parser: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v1
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v1
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: vweb
|
||||
spec:
|
||||
ports:
|
||||
- port: 8013
|
||||
targetPort: http
|
||||
selector:
|
||||
app: vweb
|
||||
type: LoadBalancer
|
||||
Reference in New Issue
Block a user