使用 Elastic 技术栈构建 K8S 全栈监控 -1:搭建 ElasticSearch 集群环境

文章转载自:https://www.qikqiak.com/post/k8s-monitor-use-elastic-stack-1/

操作步骤

kubectl create ns elastic

kubectl apply -f mongo.yml

kubectl get pods -n elastic -l app=mongo

kubectl apply -f spring-boot-simple.yml

kubectl get pods -n elastic -l app=spring-boot-simple

kubectl get svc -n elastic -l app=spring-boot-simple

curl -X POST http://192.168.2.163:31398/message -d 'hello world'

curl -X GET http://192.168.2.163:31398/message

kubectl apply  -f elasticsearch-master.configmap.yaml \
                 -f elasticsearch-master.service.yaml \
                 -f elasticsearch-master.deployment.yaml
                 

kubectl get pods -n elastic -l app=elasticsearch

kubectl apply -f elasticsearch-data.configmap.yaml \
                -f elasticsearch-data.service.yaml \
                -f elasticsearch-data.statefulset.yaml
                

kubectl get pods -n elastic -l app=elasticsearch

kubectl apply  -f elasticsearch-client.configmap.yaml \
                 -f elasticsearch-client.service.yaml \
                 -f elasticsearch-client.deployment.yaml
                 
kubectl get pods -n elastic -l app=elasticsearch

查看集群的状态变化
kubectl logs -f -n elastic $(kubectl get pods -n elastic | grep elasticsearch-master | sed -n 1p | awk '{print $1}') | grep "Cluster health status changed from"

生成默认的用户名和密码

kubectl exec $(kubectl get pods -n elastic | grep elasticsearch-client | sed -n 1p | awk '{print $1}') -n elastic -- bin/elasticsearch-setup-passwords auto -b

Changed password for user apm_system
PASSWORD apm_system = MKxeiSfI1v5E8Qf0p4Q4

Changed password for user kibana_system
PASSWORD kibana_system = B4cFUvYeW6w0PdJUZKUG

Changed password for user kibana
PASSWORD kibana = B4cFUvYeW6w0PdJUZKUG

Changed password for user logstash_system
PASSWORD logstash_system = 4u60YgcLHLRcYK1143l6

Changed password for user beats_system
PASSWORD beats_system = rFRUMRxrkyHxQ1amJDrZ

Changed password for user remote_monitoring_user
PASSWORD remote_monitoring_user = ErA8PdHcX0xC87PUfijD

Changed password for user elastic
PASSWORD elastic = 7xmKjryjpjJfAui2d90v

注意需要将 elastic 用户名和密码也添加到 Kubernetes 的 Secret 对象中

实际上使用 kibana_system 用户及其密码就行了

kubectl create secret generic kibana-elasticsearch-pw -n elastic --from-literal=username=kibana_system --from-literal=password=B4cFUvYeW6w0PdJUZKUG


kubectl apply  -f kibana.configmap.yaml \
                 -f kibana.service.yaml \
                 -f kibana.deployment.yaml
                 
了解 Kibana 的状态

kubectl logs -f -n elastic $(kubectl get pods -n elastic | grep kibana | sed -n 1p | awk '{print $1}') | grep "Status changed from yellow to green"

访问kibana
kubectl get svc kibana -n elastic

该步骤用到的yaml文件地址

https://files.cnblogs.com/files/sanduzxcvbnm/elastic-1_yaml.zip?t=1655438564

posted @ 2022-06-17 12:03  哈喽哈喽111111  阅读(239)  评论(0编辑  收藏  举报