1.软件版本说明
1.1软件版本说明
软件 | 版本 |
---|---|
kubernetes | 1.23.17 |
elasticsearch | 7.17.3 |
kibana | 7.17.3 |
1.2硬件环境说明
宿主机使用windows10安装vmware17.5.0,虚拟机安装linux系统(centos7.9)
说明:
elasticserch和kibana的版本尽量保持一致,避免由于版本不一致出现问题。
2.elastic部署
2.1使用xshell连接到虚拟机(已搭建好k8s基础环境)进入到root目录
2.2部署准备
创建elastic挂载目录并授权
mkdir -p /es/esData/{config,data,plugins,logs}
设置elastic任意ip都可访问,生产环境建议使用具体ip
echo "http.host: 0.0.0.0" >> /es/esData/config/elasticsearch.yml
挂在目录授权
chmod -R 777 /es/esData
2.3创建es-deployment.yaml
vim es-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: elasticsearch
name: elasticsearch
# namespace: sg-bs
spec:
replicas: 1
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
nodeSelector:
kubernetes.io/hostname: k8s-master01
containers:
- image: elasticsearch:7.17.3
imagePullPolicy: IfNotPresent
name: elasticsearch
ports:
- containerPort: 9200
name: elasticsearch
protocol: TCP
env:
- name: ES_JAVA_OPTS
value: "-Xms128m -Xmx256m"
- name: discovery.type
value: "single-node"
#- name: network.host
# value: "0.0.0.0"
volumeMounts:
- mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
name: config
- mountPath: /usr/share/elasticsearch/data
name: data
- mountPath: /usr/share/elasticsearch/plugins
name: plugins
- mountPath: /usr/share/elasticsearch/logs
name: logs
volumes:
- hostPath:
path: /es/esData/config/elasticsearch.yml
type: FileOrCreate
name: config
- hostPath:
path: /es/esData/data
type: DirectoryOrCreate
name: data
- hostPath:
path: /es/esData/plugins
type: DirectoryOrCreate
name: plugins
- hostPath:
path: /es/esData/logs
type: DirectoryOrCreate
name: logs
2.4执行部署
kubectl apply -f es-deployment.yaml
执行完成上面部署命令后,等3-5分钟查看部署情况
kubectl get po
如果elastic的STATUS变为Running,说明容器启动成功,此时可以通过如下命令查询运行pod的ip
kubectl get po -owide
通过ip和端口查看服务是否能够正常启动
curl 172.25.244.240:9200 #ip修改为自己查询到的es服务ip
出现如上图所示内容说明服务启动完成并且可以正常访问
说明:kubectl get po
kubectl get po 用于查看默认命名空间下的pod的运行情况
kubectl get ns 查看k8s所有存在的命名空间
kubectl get po -n 命名空间名称 查看指定命名空间下的pod运行情况
特殊说明:pod启动或者运行异常问题排查步骤
1.使用kubectl describe查看异常情况
kubectl describe pod pod名称 -n 命名空间
2.通过运行日志查看
kubectl logs pod名称 -n 命名空间
2.5elastic服务暴露,允许外部网络访问
创建es-service.yaml
vim es-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: elasticsearch
name: elasticsearch
# namespace: sg-bs
spec:
type: NodePort
ports:
- name: elasticsearch
port: 9200
nodePort: 32000
protocol: TCP
targetPort: elasticsearch
selector:
app: elasticsearch
部署service
kubectl apply -f es-service.yaml
查看service
kubectl get svc
访问
浏览器输入虚拟机ip:32000访问
至此 es服务部署完成
3.kibana部署
3.1配置文件准备
在/es/esData/config 目录下创建 kibana.yaml文件
vim kibana.yaml
server.host: "0.0.0.0"
server.shutdownTimeout: "5s"
elasticsearch.hosts: [ "http://192.168.2.111:32000" ] # 配置elastic访问路径
elasticsearch.username: "elastic" # es用户名
elasticsearch.password: "elastic" # es密码
monitoring.ui.container.elasticsearch.enabled: true
i18n.locale: "zh-CN" # 可是化界面中文
3.2 部署kibana
创建kibana-deploy.yml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: kibana
name: kibana
# namespace: sg-bs
spec:
replicas: 1
selector:
matchLabels:
app: kibana
template:
metadata:
labels:
app: kibana
spec:
nodeSelector:
kubernetes.io/hostname: k8s-master01
containers:
- image: kibana:7.17.3
imagePullPolicy: IfNotPresent
name: kibana
ports:
- containerPort: 5601
name: kibana
protocol: TCP
volumeMounts:
- mountPath: /usr/share/kibana/config/kibana.yml
name: config
volumes:
- hostPath:
path: /es/esData/config/kibana.yml
type: FileOrCreate
name: config
部署
kubectl apply -f kibana-deploy.yml
等待3-5分钟查看pod运行情况
3.3暴露kibana服务
vim kibana-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: kibana
name: kibana
# namespace: sg-bs
spec:
type: NodePort
ports:
- name: kibana
port: 5601
nodePort: 31921
protocol: TCP
targetPort: kibana
selector:
app: kibana
部署service
kubectl apply -f kibana-service.yaml
访问