Kubernetes上安装ELK监控
安装elk operator自定义的resource里面包含了es,kibana,filebeat等资源的定义,以及RBACkubectl apply -f https://download.elastic.co/downloads/eck/1.3.1/all-in-one.yaml安装escat <<EOF | kubectl apply -f -apiVersion: elasti
·
安装elk operator自定义的resource
里面包含了es,kibana,filebeat等资源的定义,以及RBAC
kubectl apply -f https://download.elastic.co/downloads/eck/1.3.1/all-in-one.yaml
安装elasticsearch
cat <<EOF | kubectl apply -f -
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: quickstart
spec:
version: 7.10.2
nodeSets:
- name: default
count: 1
config:
node.store.allow_mmap: false
EOF
开放端口
kubectl port-forward service/quickstart-es-http 9200
默认用户名:elastic,密码:
PASSWORD=$(kubectl get secret quickstart-es-elastic-user -o go-template='{{.data.elastic | base64decode}}')
echo $PASSWORD
测试访问
curl -u "elastic:$PASSWORD" -k "https://localhost:9200"
部署Kibana
创建kibana
cat <<EOF | kubectl apply -f -
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
name: quickstart
spec:
version: 7.10.2
count: 1
elasticsearchRef:
name: quickstart
EOF
开放端口
kubectl port-forward service/quickstart-kb-http 5601
默认用户名:elastic,获取密码(同es密码)
kubectl get secret quickstart-es-elastic-user -o=jsonpath='{.data.elastic}' | base64 --decode; echo
访问kibana,注意是https
https://localhost:5601
kibana已经可以访问了,要收集containers日志还要创建filebeat。
filebeat 测试
k create -f https://raw.githubusercontent.com/chenjiangtao/spring-boot-on-kubernetes/main/kubernetes/elk/all-in-one/filebeat.yaml
在kibana中创建filebeat索引,已经可以看到k8s的日志了
使用busybox模拟应用打印日志
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: counter
spec:
containers:
- name: count
image: busybox
# 输出hello world
args: [/bin/sh, -c,
'i=0; while true; do echo "hello world: $i: $(date)"; i=$((i+1)); sleep 3; done']
EOF
可以看到filebeat已经收集到了
参考:
quickstart https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-quickstart.html
演示代码位置:https://github.com/chenjiangtao/spring-boot-on-kubernetes/tree/main/kubernetes/elk/all-in-one
更多推荐
已为社区贡献16条内容
所有评论(0)