配置清单
- es.yaml
```yaml
apiVersion: v1
kind: Service
metadata:
name: elasticsearch-logging
namespace: kube-system
labels:
k8s-app: elasticsearch-logging
kubernetes.io/cluster-service: “true”
addonmanager.kubernetes.io/mode: Reconcile
kubernetes.io/name: “Elasticsearch” spec:
ports:- port: 9200
protocol: TCP
targetPort: db
selector:
k8s-app: elasticsearch-logging
- port: 9200
RBAC authn and authz
apiVersion: v1 kind: ServiceAccount metadata: name: elasticsearch-logging namespace: kube-system labels: k8s-app: elasticsearch-logging kubernetes.io/cluster-service: “true”
addonmanager.kubernetes.io/mode: Reconcile
kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: name: elasticsearch-logging labels: k8s-app: elasticsearch-logging kubernetes.io/cluster-service: “true” addonmanager.kubernetes.io/mode: Reconcile rules:
- apiGroups:
- “” resources:
- “services”
- “namespaces”
- “endpoints” verbs:
- “get”
kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: namespace: kube-system name: elasticsearch-logging labels: k8s-app: elasticsearch-logging kubernetes.io/cluster-service: “true” addonmanager.kubernetes.io/mode: Reconcile subjects:
- kind: ServiceAccount name: elasticsearch-logging namespace: kube-system apiGroup: “” roleRef: kind: ClusterRole name: elasticsearch-logging apiGroup: “”
Elasticsearch deployment itself
apiVersion: apps/v1 kind: StatefulSet metadata: name: elasticsearch-logging namespace: kube-system labels: k8s-app: elasticsearch-logging version: v6.2.5 kubernetes.io/cluster-service: “true” addonmanager.kubernetes.io/mode: Reconcile spec: serviceName: elasticsearch-logging replicas: 1 selector: matchLabels: k8s-app: elasticsearch-logging version: v6.2.5 template: metadata: labels: k8s-app: elasticsearch-logging version: v6.2.5 kubernetes.io/cluster-service: “true” spec: serviceAccountName: elasticsearch-logging containers:
- image: harbor.querycap.com/rk-infra/elasticsearch:6.8.8-v0.4
name: elasticsearch-logging
resources:
# need more cpu upon initialization, therefore burstable class
limits:
cpu: 1000m
requests:
cpu: 100m
ports:
- containerPort: 9200
name: db
protocol: TCP
- containerPort: 9300
name: transport
protocol: TCP
volumeMounts:
- name: elasticsearch-logging
mountPath: /usr/share/elasticsearch/data/
- mountPath: /usr/share/elasticsearch/config/elastic-certificates.p12
name: keystore
readOnly: true
subPath: elastic-certificates.p12
env:
- name: "NAMESPACE"
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: "xpack.security.enabled"
value: "true"
- name: "xpack.security.transport.ssl.enabled"
value: "true"
- name: xpack.security.transport.ssl.verification_mode
value: "certificate"
- name: xpack.security.transport.ssl.keystore.path
value: "/usr/share/elasticsearch/config/elastic-certificates.p12"
- name: xpack.security.transport.ssl.truststore.path
value: "/usr/share/elasticsearch/config/elastic-certificates.p12"
- name: "xpack.ml.enabled"
value: "false"
- name: "xpack.monitoring.collection.enabled"
value: "true"
- name: "xpack.license.self_generated.type"
value: "basic"
volumes:
- name: elasticsearch-logging
hostPath:
path: /data/es/
- name: keystore
secret:
secretName: es-keystore
defaultMode: 0444
nodeSelector:
es: data
tolerations:
- key: “dedicated”
operator: “Equal”
value: “es”
effect: “NoExecute”
# Elasticsearch requires vm.max_map_count to be at least 262144.
# If your OS already sets up this number to a higher value, feel free
# to remove this init container.
initContainers:
- name: elasticsearch-logging-init
image: alpine:3.6
command: ["/sbin/sysctl", "-w", "vm.max_map_count=262144"]
securityContext:
privileged: true
- name: elasticsearch-volume-init
image: alpine:3.6
command:
- chmod
- -R
- "777"
- /usr/share/elasticsearch/data/
volumeMounts:
- name: elasticsearch-logging
mountPath: /usr/share/elasticsearch/data/
- es-secret.yaml
```yaml
apiVersion: v1
kind: Secret
metadata:
name: es-keystore
namespace: kube-system
data:
elastic-certificates.p12: MIINdwIBAzCCDTAGCSqGSIb3DQEHAaCCDSEEgg0dMIINGTCCBW0GCSqGSIb3DQEHAaCCBV4EggVaMIIFVjCCBVIGCyqGSIb3DQEMCgECoIIE+zCCBPcwKQYKKoZIhvcNAQwBAzAbBBQs3hsugdvGL7FWl+IJ6pxClg251AIDAMNQBIIEyF81+gP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50U/g67pnl4PYbdtG/yrjCNnXCaRZRapDVD/MD4wITAJBgUrDgMCGgUABBR9QitEdRrOhirFpeeXYxRCiDXobgQUgdxm0RxqdfUMrM7V9NYJh5DmvWsCAwGGoA==
---
# Source: filebeat/templates/filebeat-configmap.yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: filebeat-config
namespace: kube-system
labels:
k8s-app: filebeat
data:
filebeat.yml: |-
filebeat.config:
max_procs: 1
queue.mem.events: 16
queue.mem.flush.min_events: 8
inputs:
# Mounted `filebeat-inputs` configmap:
path: ${path.config}/inputs.d/*.yml
# Reload inputs configs as they change:
reload.enabled: true
enabled: true
modules:
path: ${path.config}/modules.d/*.yml
# Reload module configs as they change:
reload.enabled: true
#output.kafka:
# hosts: ["kafka-log-01:9092", "kafka-log-02:9092", "kafka-log-03:9092"]
# topic: 'topic-test-log'
# version: 2.0.0
output.logstash:
hosts: ["logstash:5044"]
enabled: true
---
apiVersion: v1
kind: ConfigMap
metadata:
name: filebeat-inputs
namespace: kube-system
labels:
k8s-app: filebeat
data:
kubernetes.yml: |-
- type: docker
#harvester_buffer_size: 4096000
close_inactive: 15m
scan_frequency: 30s
containers.ids:
- "*"
enabled: true
processors:
- add_kubernetes_metadata:
in_cluster: true
---
# Source: filebeat/templates/filebeat-service-account.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: filebeat
namespace: kube-system
labels:
k8s-app: filebeat
---
# Source: filebeat/templates/filebeat-role.yaml
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: filebeat
labels:
k8s-app: filebeat
rules:
- apiGroups: [""] # "" indicates the core API group
resources:
- namespaces
- pods
verbs:
- get
- watch
- list
---
# Source: filebeat/templates/filebeat-role-binding.yaml
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: filebeat
subjects:
- kind: ServiceAccount
name: filebeat
namespace: kube-system
roleRef:
kind: ClusterRole
name: filebeat
apiGroup: rbac.authorization.k8s.io
---
# Source: filebeat/templates/filebeat-daemonset.yaml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: filebeat
namespace: kube-system
labels:
k8s-app: filebeat
spec:
template:
metadata:
labels:
k8s-app: filebeat
spec:
serviceAccountName: filebeat
terminationGracePeriodSeconds: 30
nodeSelector:
beta.kubernetes.io/filebeat-ds-ready: "true"
containers:
- name: filebeat
image: "harbor.querycap.com/rk-infra/filebeat:6.6.2"
args: [
"-c", "/etc/filebeat.yml",
"-e","-httpprof","0.0.0.0:6060"
]
#ports:
# - containerPort: 6060
# hostPort: 6068
securityContext:
runAsUser: 0
# If using Red Hat OpenShift uncomment this:
#privileged: true
resources:
limits:
memory: 1000Mi
cpu: 1000m
requests:
memory: 100Mi
cpu: 100m
volumeMounts:
- name: config
mountPath: /etc/filebeat.yml
readOnly: true
subPath: filebeat.yml
- name: inputs
mountPath: /usr/share/filebeat/inputs.d
readOnly: true
- name: data
mountPath: /usr/share/filebeat/data
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
- name: timezone
mountPath: /etc/localtime
imagePullSecrets:
- name: qingcloud-registry
volumes:
- name: config
configMap:
defaultMode: 0600
name: filebeat-config
- name: varlibdockercontainers
hostPath:
path: /data/var/lib/docker/containers
- name: inputs
configMap:
defaultMode: 0600
name: filebeat-inputs
# data folder stores a registry of read status for all files, so we don't send everything again on a Filebeat pod restart
- name: data
hostPath:
path: /data/filebeat-data
type: DirectoryOrCreate
- name: timezone
hostPath:
path: /etc/localtime
tolerations:
- effect: NoExecute
key: dedicated
operator: Equal
value: gpu
- effect: NoSchedule
operator: Exists
- kibana.yaml
```yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: kibana
namespace: kube-system
annotations:
kubernetes.io/ingress.class: “nginx”
spec: rules:- host: a.kibana.rockontrol.com
http:
paths:
- backend: serviceName: kibana servicePort: 5601
- host: a.kibana.rockontrol.com
http:
paths:
apiVersion: v1 kind: Service metadata: name: kibana namespace: kube-system labels: k8s-app: kibana kubernetes.io/cluster-service: “true” addonmanager.kubernetes.io/mode: Reconcile kubernetes.io/name: “Kibana” spec: type: ClusterIP ports:
- port: 5601 protocol: TCP targetPort: ui selector: k8s-app: kibana
apiVersion: apps/v1 kind: Deployment metadata: name: kibana namespace: kube-system labels: k8s-app: kibana kubernetes.io/cluster-service: “true” addonmanager.kubernetes.io/mode: Reconcile spec: replicas: 1 selector: matchLabels: k8s-app: kibana template: metadata: labels: k8s-app: kibana annotations: seccomp.security.alpha.kubernetes.io/pod: ‘docker/default’ spec: imagePullSecrets:
- name: qingcloud-registry
containers:
- name: kibana
image: harbor.querycap.com/rk-infra/kibana:6.8.8
resources:
# need more cpu upon initialization, therefore burstable class
limits:
cpu: 1000m
requests:
cpu: 100m
env:
- name: ELASTICSEARCH_URL
value: http://elasticsearch-logging:9200
- name: XPACK_SECURITY_ENABLED
value: "true"
- name: ELASTICSEARCH_PASSWORD
value: M50zLpCI0EeDcOh7
- name: ELASTICSEARCH_USERNAME
value: kibana
- name: XPACK_ML_ENABLED
value: "false"
ports:
- containerPort: 5601
name: ui
protocol: TCP
- [**logstash.yaml**](https://git.querycap.com/infra/k8s-elk/-/blob/master/logstash.yaml)
```yaml
apiVersion: v1
kind: Service
metadata:
name: logstash
namespace: kube-system
spec:
ports:
- port: 5044
targetPort: beats
selector:
type: logstash
clusterIP: None
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: logstash
namespace: kube-system
spec:
template:
metadata:
labels:
type: logstash
spec:
containers:
- image: harbor.querycap.com/rk-infra/logstash:v6.6.2
name: logstash
ports:
- containerPort: 5044
name: beats
command:
- logstash
- '-f'
- '/etc/logstash_c/logstash.conf'
env:
- name: "XPACK_MONITORING_ELASTICSEARCH_HOSTS"
value: "http://elasticsearch-logging:9200"
volumeMounts:
- name: config-volume
mountPath: /etc/logstash_c/
- name: config-yml-volume
mountPath: /usr/share/logstash/config/
- name: timezone
mountPath: /etc/localtime
resources:
limits:
cpu: 1000m
memory: 2048Mi
# requests:
# cpu: 512m
# memory: 512Mi
imagePullSecrets:
- name: qingcloud-registry
volumes:
- name: config-volume
configMap:
name: logstash-conf
items:
- key: logstash.conf
path: logstash.conf
- name: timezone
hostPath:
path: /etc/localtime
- name: config-yml-volume
configMap:
name: logstash-yml
items:
- key: logstash.yml
path: logstash.yml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: logstash-conf
namespace: kube-system
labels:
type: logstash
data:
logstash.conf: |-
input {
beats {
port => 5044
}
}
filter{
if [kubernetes][container][name] == "nginx-ingress-controller" {
json {
source => "message"
target => "ingress_log"
}
if [ingress_log][requesttime] {
mutate {
convert => ["[ingress_log][requesttime]", "float"]
}
}
if [ingress_log][upstremtime] {
mutate {
convert => ["[ingress_log][upstremtime]", "float"]
}
}
if [ingress_log][status] {
mutate {
convert => ["[ingress_log][status]", "float"]
}
}
if [ingress_log][httphost] and [ingress_log][uri] {
mutate {
add_field => {"[ingress_log][entry]" => "%{[ingress_log][httphost]}%{[ingress_log][uri]}"}
}
mutate{
split => ["[ingress_log][entry]","/"]
}
if [ingress_log][entry][1] {
mutate{
add_field => {"[ingress_log][entrypoint]" => "%{[ingress_log][entry][0]}/%{[ingress_log][entry][1]}"}
remove_field => "[ingress_log][entry]"
}
}
else{
mutate{
add_field => {"[ingress_log][entrypoint]" => "%{[ingress_log][entry][0]}/"}
remove_field => "[ingress_log][entry]"
}
}
}
}
if [kubernetes][container][name] =~ /^srv*/ {
json {
source => "message"
target => "tmp"
}
if [kubernetes][namespace] == "kube-system" {
drop{}
}
if [tmp][level] {
mutate{
add_field => {"[applog][level]" => "%{[tmp][level]}"}
}
if [applog][level] == "debug"{
drop{}
}
}
if [tmp][msg]{
mutate{
add_field => {"[applog][msg]" => "%{[tmp][msg]}"}
}
}
if [tmp][func]{
mutate{
add_field => {"[applog][func]" => "%{[tmp][func]}"}
}
}
if [tmp][cost]{
if "ms" in [tmp][cost]{
mutate{
split => ["[tmp][cost]","m"]
add_field => {"[applog][cost]" => "%{[tmp][cost][0]}"}
convert => ["[applog][cost]", "float"]
}
}
else{
mutate{
add_field => {"[applog][cost]" => "%{[tmp][cost]}"}
}
}
}
if [tmp][method]{
mutate{
add_field => {"[applog][method]" => "%{[tmp][method]}"}
}
}
if [tmp][request_url]{
mutate{
add_field => {"[applog][request_url]" => "%{[tmp][request_url]}"}
}
}
if [tmp][meta._id]{
mutate{
add_field => {"[applog][traceId]" => "%{[tmp][meta._id]}"}
}
}
if [tmp][project] {
mutate{
add_field => {"[applog][project]" => "%{[tmp][project]}"}
}
}
if [tmp][time] {
mutate{
add_field => {"[applog][time]" => "%{[tmp][time]}"}
}
}
if [tmp][status] {
mutate{
add_field => {"[applog][status]" => "%{[tmp][status]}"}
convert => ["[applog][status]", "float"]
}
}
}
mutate{
rename => ["kubernetes", "k8s"]
remove_field => "beat"
remove_field => "tmp"
remove_field => "[k8s][labels][app]"
}
}
output{
elasticsearch {
hosts => ["http://elasticsearch-logging:9200"]
codec => json
index => "logstash-%{+YYYY.MM.dd}"
user => 'elastic'
password => 'P9IKmhwuYEEej52U'
}
}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: logstash-yml
namespace: kube-system
labels:
type: logstash
data:
logstash.yml: |-
http.host: "0.0.0.0"
xpack.monitoring.enabled: true
xpack.monitoring.elasticsearch.username: logstash_system
xpack.monitoring.elasticsearch.password: hOsocygbtFEs1qty
xpack.monitoring.elasticsearch.url: http://elasticsearch-logging:9200
- 还有一个elastic-certificates.p12,可以自己用二进制生成
/usr/share/elasticsearch/bin/elasticsearch-certutil ca
/usr/share/elasticsearch/bin/elasticsearch-certutil cert --ca elastic-certificates.p12
#两条命令均一路回车即可,不需要给秘钥再添加密码。
#证书创建完成之后,默认在es的数据目录,这里统一放到etc下:
ls elastic-*
elastic-certificates.p12 elastic-certificates-ca.p12
部署步骤
给部署es的节点加上标签
kubectl label node <node> es=data
部署
kubectl apply -f .
创建用户
kubectl -n kube-system exec -it elasticsearch-logging-0 ./init-user.sh
这里的脚本是自己提前打包到镜像中的,没有使用官方镜像
cat init-user.sh
#!/usr/bin/expect
set timeout -1
spawn bin/elasticsearch-setup-passwords interactive
expect "\[y/N\]"
send "y\r"
expect "\[elastic\]"
send "P9IKmhwuYEEej52U\r"
expect "\[elastic\]"
send "P9IKmhwuYEEej52U\r"
expect "\[apm_system\]"
send "1UmdUStBiKYqR0IJ\r"
expect "\[apm_system\]"
send "1UmdUStBiKYqR0IJ\r"
expect "\[kibana\]"
send "M50zLpCI0EeDcOh7\r"
expect "\[kibana\]"
send "M50zLpCI0EeDcOh7\r"
expect "\[logstash_system\]"
send "hOsocygbtFEs1qty\r"
expect "\[logstash_system\]"
send "hOsocygbtFEs1qty\r"
expect "\[beats_system\]"
send "xy28upiAPDNGfmgw\r"
expect "\[beats_system\]"
send "xy28upiAPDNGfmgw\r"
expect "\[remote_monitoring_user\]"
send "jooKJoYHlMiZwTXX\r"
expect "\[remote_monitoring_user\]"
send "jooKJoYHlMiZwTXX\r"
用户
# 普通用户
username: kibana
password: M50zLpCI0EeDcOh7
# 只读用户
username: viewer
password: WBQ3p4ZZ7WappBfEb
viewer 用的的权限配置
- 创建 viewer role 角色, 权限如下。
- 创建 viewer 账户, 授权 viewer 角色。