增加日志应用收集,未完成
parent
d74ecd14b2
commit
ca31654fe4
|
@ -0,0 +1,95 @@
|
|||
# 应用日志收集
|
||||
|
||||
## 方案选择
|
||||
|
||||
Kubernetes官方提供了EFK的日志收集解决方案,但是这种方案并不适合所有的业务场景,它本身就有一些局限性,例如:
|
||||
|
||||
- 所有日志都必须是out前台输出,真实业务场景中无法保证所有日志都在前台输出
|
||||
- 只能有一个日志输出文件,而真实业务场景中往往有多个日志输出文件
|
||||
- Fluentd并不是常用的日志收集工具,我们更习惯用logstash
|
||||
- 我们已经有自己的ELK集群且有专人维护,没有必要再在kubernetes上做一个日志收集服务
|
||||
|
||||
基于以上几个原因,我们决定使用自己的ELK集群。
|
||||
|
||||
**Kubernetes集群中的日志收集解决方案**
|
||||
|
||||
| **编号** | **方案** | **优点** | **缺点** |
|
||||
| ------ | ------------------------------------ | ---------------------------------------- | ------------------------------- |
|
||||
| **1** | 每个app的镜像中都集成日志收集组件 | 部署方便,kubernetes的yaml文件无须特别配置,可以为每个app自定义日志收集配置 | 强耦合,不方便应用和日志收集组件升级和维护 |
|
||||
| **2** | 单独创建一个日志收集组件跟app的容器一起运行在同一个pod中 | 低耦合,扩展性强,方便维护和升级 | 需要对kubernetes的yaml文件进行单独配置,略显繁琐 |
|
||||
| **3** | 将所有的Pod的日志都挂载到宿主机上,每台主机上单独起一个日志收集Pod | 完全解耦,性能最高,管理起来最方便 | 需要统一日志收集规则,目录和输出方式 |
|
||||
|
||||
综合以上优缺点,我们选择使用方案二。
|
||||
|
||||
该方案在扩展性、个性化、部署和后期维护方面都能做到均衡,因此选择该方案。
|
||||
|
||||
![logstash日志收集架构图](images/logstash-log-collector.jpg)
|
||||
|
||||
我们创建了自己的logstash镜像。见https://github.com/rootsongjc/docker-images
|
||||
|
||||
镜像地址:`index.tenxcloud.com/jimmy/logstash:5.3.0`
|
||||
|
||||
## 测试
|
||||
|
||||
我们部署一个应用对logstash的日志收集功能进行测试。
|
||||
|
||||
创建应用yaml文件`logstash-test.yaml`。
|
||||
|
||||
```yaml
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: logstash-test
|
||||
namespace: default
|
||||
labels:
|
||||
k8s-app: logstash-test
|
||||
spec:
|
||||
selector:
|
||||
k8s-app: logstash-test
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
k8s-app: logstash-test
|
||||
spec:
|
||||
containers:
|
||||
- image: sz-pg-oam-docker-hub-001.tendcloud.com/library/logstash:5.3.0
|
||||
name: logstash
|
||||
resources:
|
||||
limits:
|
||||
cpu: 1000m
|
||||
memory: 50M
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 50M
|
||||
volumeMounts:
|
||||
- name: log-volume
|
||||
mountPath: /log
|
||||
env:
|
||||
- name: LogFile
|
||||
value: /log
|
||||
- name: ES_SERVER
|
||||
value: 172.21.14.5:9200
|
||||
- name: INDICES
|
||||
value: xg-docker
|
||||
- name: CODEC
|
||||
value: plain
|
||||
- image: sz-pg-oam-docker-hub-001.tendcloud.com/library/app:latest
|
||||
name : app
|
||||
volumeMounts:
|
||||
- name: app-logs
|
||||
mountPath: /var/log/
|
||||
volumes:
|
||||
- name: app-logs
|
||||
emptyDir: {}
|
||||
```
|
||||
|
||||
注意:该文件可以在`manifests/test/logstash-test.yaml`找到。 我使用了自己的私有镜像仓库。
|
||||
|
||||
**创建应用**
|
||||
|
||||
部署Deployment
|
||||
|
||||
```
|
||||
kubectl create -f logstash-test.yaml
|
||||
```
|
||||
|
|
@ -39,6 +39,7 @@ GitHub地址:https://github.com/rootsongjc/kubernetes-handbook
|
|||
- [7.1 使用glusterfs做持久化存储](17-使用glusterfs做持久化存储.md)
|
||||
- 8.0 集群运维管理
|
||||
- [8.1 服务滚动升级](19-服务滚动升级.md)
|
||||
- [8.2 应用日志收集](21-应用日志收集.md)
|
||||
- 9.0 Kubernetes领域应用
|
||||
- 9.1 Spark on Kubernetes TODO
|
||||
- [10.0 问题记录](issues.md)
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
* [7.1 使用glusterfs做持久化存储](17-使用glusterfs做持久化存储.md)
|
||||
- [8.0 集群运维管理]()
|
||||
- [8.1 服务滚动升级](19-服务滚动升级.md)
|
||||
- [8.2 应用日志收集](21-应用日志收集.md)
|
||||
- [9.0 Kubernetes领域应用]()
|
||||
- [10.0 问题记录](issues.md)
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 144 KiB |
|
@ -0,0 +1,45 @@
|
|||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: logstash-test
|
||||
namespace: default
|
||||
labels:
|
||||
k8s-app: logstash-test
|
||||
spec:
|
||||
selector:
|
||||
k8s-app: logstash-test
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
k8s-app: logstash-test
|
||||
spec:
|
||||
containers:
|
||||
- image: sz-pg-oam-docker-hub-001.tendcloud.com/library/logstash:5.3.0
|
||||
name: logstash
|
||||
resources:
|
||||
limits:
|
||||
cpu: 1000m
|
||||
memory: 50M
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 50M
|
||||
volumeMounts:
|
||||
- name: log-volume
|
||||
mountPath: /log
|
||||
env:
|
||||
- name: LogFile
|
||||
value: /log
|
||||
- name: ES_SERVER
|
||||
value: 172.21.14.5:9200
|
||||
- name: INDICES
|
||||
value: xg-docker
|
||||
- name: CODEC
|
||||
value: plain
|
||||
- image: sz-pg-oam-docker-hub-001.tendcloud.com/library/app:latest
|
||||
name : app
|
||||
volumeMounts:
|
||||
- name: app-logs
|
||||
mountPath: /var/log/
|
||||
volumes:
|
||||
- name: app-logs
|
||||
emptyDir: {}
|
Loading…
Reference in New Issue