1、yml文件
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: abc
namespace: abc-q
labels:
app: abc
env: q
product-line: a
spec:
replicas: 3
serviceName: abc
selector:
matchLabels:
app: abc
template:
metadata:
labels:
app: abc
spec:
containers:
- name: abc
image: registry.cn-shanghai.aliyuncs.com/abc-q/abc:v1.0
imagePullPolicy: Always
env:
- name: run_env
value: "q"
resources:
requests:
memory: "2000Mi"
cpu: "2"
limits:
memory: "4000Mi"
cpu: "4"
volumeMounts:
- mountPath: /opt/a/abc/log-q/
name: log-volume
- mountPath: /app/application-q.properties
# name: abc-q-config
# readOnly: true
# subPath: application-s.properties
# - name: filebeat
image: registry.cn-shanghai.aliyuncs.com/filebeat:7.1.1
imagePullPolicy: Always
volumeMounts:
- mountPath: /app/logs/
name: log-volume
- mountPath: /usr/local/filebeat/filebeat.yml
name: filebeat-config
subPath: path/to/filebeat.yml
volumes:
- name: "filebeat-config"
configMap:
name: filebeat.yml
items:
- key: filebeat.yml
path: path/to/filebeat.yml
# - name: "abc-q-config"
# configMap:
# name: abc-q-config
volumeClaimTemplates:
- metadata:
name: log-volume
spec:
accessModes: [ "ReadWriteMany" ]
storageClassName: "log-nas-q"
resources:
requests:
storage: 50Gi
2、filebeat.yml
kind: ConfigMap
apiVersion: v1
metadata:
name: filebeat.yml
namespace: abc-q
data:
filebeat.yml: |
filebeat.inputs:
- type: log #Giorules
enabled: true
paths:
- /app/logs/*.log #根据项目实际路径修改目录
fields:
log_topic: abc_q #根据项目实际名称修改topic名,并告知运维
encoding: utf-8
#exclude_lines: ['^#','HEAD /favicon.ico'] #过滤不需要日志,不需要就删除此行
multiline.pattern: '^2' #以multiline开头的为多行合并设置,用于报错日志堆栈,不需要就删除此行
multiline.negate: true #以multiline开头的为多行合并设置,用于报错日志堆栈,不需要就删除此行
multiline.match: after #以multiline开头的为多行合并设置,用于报错日志堆栈,不需要就删除此行
ignore_older: 5m
close_inactive: 1m
output.kafka:
enabled: true
hosts: ["172.16.212.128:9092","172.16.212.129:9092"]
topic: '%{[fields][log_topic]}'
partition.round_robin:
reachable_only: true
worker: 2
required_acks: 1
compression: gzip
max_message_bytes: 10000000
filebeat.config.modules:
enabled: true
path: ${path.config}/modules.s/*.yml
reload.enabled: true
processors:
- add_cloud_metadata: ~
logging.files:
path: /var/log/filebeat
name: filebeat
keepfiles: 7
permissions: 0644
3、常用命令
#pods查看
kubectl --kubeconfig=accrual.kubeconfig get pods -n abc-q
#后端日志查看
kubectl --kubeconfig=accrual.kubeconfig logs -f abc-0 abc -n abc --tail=1000
#删除
kubectl --kubeconfig=accrual.kubeconfig delete -f abc.yml
#删除configmap
kubectl --kubeconfig=accrual.kubeconfig delete configmap abc-q-config -n abc-q
// 查看日志
kubectl --kubeconfig=accrual.kubeconfig logs -f abc-0 abc -n abc-q --tail=1000
// 查看挂载目录
kubectl --kubeconfig=accrual.kubeconfig get pvc -n abc-q
// 删除挂载目录
kubectl --kubeconfig=accrual.kubeconfig delete pvc -n abc-q