k8s efk mysql慢日誌例子

2021-08-20 20:51:03 字數 4417 閱讀 7020

課程內容:各種k8s部署方式。包括minikube部署,kubeadm部署,kubeasz部署,rancher部署,k3s部署。包括開發測試環境部署k8s,和生產環境部署k8s。

介紹主要的k8s資源的使用配置和命令。包括configmap,pod,service,replicaset,namespace,deployment,daemonset,ingress,pv,pvc,sc,role,rolebinding,clusterrole,clusterrolebinding,secret,serviceaccount,statefulset,job,cronjob,poddisruptionbudget,podsecuritypolicy,networkpolicy,resourcequota,limitrange,endpoint,event,conponentstatus,node,apiservice,controllerrevision等。

詳細介紹helm命令,學習helm chart語法,編寫helm chart。深入分析各專案原始碼,學習編寫helm外掛程式

————————————————

應用部署檔案

apiversion: extensions/v1beta1

kind: deployment

metadata:

name: alpaca

labels:

spec:

replicas: 1

template:

metadata:

labels:

spec:

terminationgraceperiodseconds: 60

nodeselector:

containers:

- name: alpaca

image: 192.168.1.225:5000/mysql:5.7-youben

imagepullpolicy: always

readinessprobe:

tcpsocket:

port: 3306

initialdelayseconds: 60

timeoutseconds: 5

livenessprobe:

tcpsocket:

port: 3306

initialdelayseconds: 60

timeoutseconds: 5

env:

- name: mysql_root_password

value: root

ports:

- containerport: 3306

name: tcp

volumemounts:

- name: alpaca

mountpath: /var/lib/mysql

- name: fluentd-es

image: 192.168.1.225:5000/fluentd-elasticsearch:v2.0.4-youben

imagepullpolicy: always

command: ["/bin/sh"]

args: ["-c", "/run.sh $fluentd_args"]

env:

- name: fluentd_args

value: --no-supervisor -q

volumemounts:

- name: config-volume

mountpath: /etc/fluent/config.d

- name: alpaca

mountpath: /var/lib/mysql

volumes:

- name: alpaca

persistentvolumeclaim:

claimname: pvc-alpaca-withlog

- name: config-volume

configmap:

name: fluentd-es-config-mysql-alpaca

---apiversion: v1

kind: service

metadata:

name: alpaca

labels:

spec:

ports:

- port: 3306

targetport: 3306

selector:

配置檔案:

kind: configmap

apiversion: v1

metadata:

name: fluentd-es-config-mysql-alpaca

labels:

addonmanager.kubernetes.io/mode: reconcile

data:

system.conf: |-

root_dir /tmp/fluentd-buffers/

input.conf: |-

@type mysql_slow_query

path /var/lib/mysql/slow_query.log

pos_file /root/mysql.log.slow.pos

tag mysql.alpaca.slow.query

@type none

@id mysql.error.log

@type tail

path /var/log/mysql/error.log

format multiline

format_firstline /^\d \d\d:\d\d:\d\d/

format1 /(?\d \d\d:\d\d:\d\d) (?.*)/

time_format %y%m%d %h:%m:%s

pos_file /root/mysql.log.error.pos

tag mysql.alpaca.error

output.conf: |-

@id elasticsearch.slow

@type elasticsearch

@log_level info

include_tag_key true

host elasticsearch-logging.kube-system.svc.cluster.local

port 9200

logstash_format true

logstash_prefix docker.mysql.slow

logstash_dateformat %y-%m-%d

type_name docker_mysql_alpaca_log_slow

@type file

path /var/log/fluentd-buffers/kubernetes.system.buffer.slow

flush_mode interval

retry_type exponential_backoff

flush_thread_count 2

flush_interval 5s

retry_forever

retry_max_interval 30

chunk_limit_size 2m

queue_limit_length 8

overflow_action block

@id elasticsearch.error

@type elasticsearch

@log_level info

include_tag_key true

host elasticsearch-logging.kube-system.svc.cluster.local

port 9200

logstash_format true

logstash_prefix docker.mysql.error

logstash_dateformat %y-%m-%d

type_name docker_mysql_alpaca_log_error

@type file

path /var/log/fluentd-buffers/kubernetes.system.buffer.error

flush_mode interval

retry_type exponential_backoff

flush_thread_count 2

flush_interval 5s

retry_forever

retry_max_interval 30

chunk_limit_size 2m

queue_limit_length 8

overflow_action block

記得裝上mysql慢日誌外掛程式

已經打包好外掛程式:

k8s集群日誌

硬體環境 三颱虛擬機器,10.10.20.203 部署docker etcd flannel kube apiserver kube controller manager kube scheduler elsticsearch kibana 10.10.20.206 部署docker flannel...

k8s解決tomcat日期慢8個小時問題

在配置的yaml檔案中加上如下配置 我自己解決 1 首先我在yaml檔案中使用共享環境時間 volumemounts name config mountpath etc localtime readonly true volumes name config hostpath path etc loc...

K8S之EFK日誌收集

1.1 部署es 2 共6個檔案 root k8s master01 efk ls es service.yaml es statefulset.yaml fluentd es configmap.yaml fluentd es ds.yaml kibana deployment.yaml kiba...