1. 部署es服务
1.1 创建configmap
vim elasticsearch-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: elasticsearch-config
namespace: test
data:
elasticsearch.yml: |-
cluster.name: dev-es-data #定义集群名
network.host: 0.0.0.0 #定义绑定 IP 地址,site 代表自动获取本地的内网 IP,如172.x.x.x
http.port: 9200 #定义 http服务的端口
transport.tcp.port: 9300 #定义 tcp 服务的端口
kubectl apply -f elasticsearch-configmap.yaml
1.2 部署es
vim elasticsearch.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: dev-elasticsearch
namespace: test
labels:
app: elasticsearch
spec:
serviceName: dev-elasticsearch
replicas: 1
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
containers:
- name: elasticsearch
lifecycle:
postStart:
exec:
command: ["chown","elasticsearch:elasticsearch","/usr/share/elasticsearch/data"]
image: elasticsearch:6.8.10
imagePullPolicy: Always
ports:
- containerPort: 9200
protocol: TCP
- containerPort: 9300
protocol: TCP
resources:
requests:
memory: 1.5Gi
cpu: 300m
limits:
memory: 2Gi
cpu: 500m
volumeMounts:
- mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
name: elasticsearch-config
subPath: elasticsearch.yml
- mountPath: /usr/share/elasticsearch/data
name: elasticsearch-storage-volume
volumes:
- name: elasticsearch-config
configMap:
name: elasticsearch-config
items:
- key: elasticsearch.yml
path: elasticsearch.yml
mode: 0644
- name: elasticsearch-storage-volume
persistentVolumeClaim:
claimName: elasticsearch-pvc
---
apiVersion: v1
kind: Service
metadata:
name: dev-elasticsearch
namespace: test
labels:
app: elasticsearch
spec:
ports:
- port: 9200
targetPort: 9200
protocol: TCP
name: es-1
- port: 9300
targetPort: 9300
protocol: TCP
name: es-2
selector:
app: elasticsearch
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: elasticsearch-pvc
namespace: test
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 25Gi
storageClassName: alicloud-disk-topology-xfs
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: alicloud-disk-topology-xfs
provisioner: diskplugin.csi.alibabacloud.com
parameters:
type: available
fstype: xfs
encrypted: "false"
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
allowVolumeExpansion: true
kubectl apply -f elasticsearch.yaml
2.部署Kibana
2.1查看Elasticsearch 和 Kibana 的 版本关系
https://www.elastic.co/cn/support/matrix#matrix_compatibility
2.2 部署kibana并配置域名访问
vim kibana.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: kibana
namespace: test
spec:
selector:
matchLabels:
app: kibana
replicas: 1
template:
metadata:
labels:
app: kibana
spec:
restartPolicy: Always
containers:
- name: kibana
image: kibana:6.8.10
imagePullPolicy: Always
ports:
- containerPort: 5601
env:
- name: ELASTICSEARCH_HOSTS
value: http://x.x.x.x:9200 #这里配置es地址
- name: I18N.LOCALE
value: zh-CN #汉化
resources:
requests:
memory: 1024Mi
cpu: 500m
limits:
memory: 1024Mi
cpu: 1000m
---
apiVersion: v1
kind: Service
metadata:
name: kibana
namespace: test
spec:
type: ClusterIP
ports:
- port: 80
protocol: TCP
targetPort: 5601
selector:
app: kibana
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: kibana
namespace: test
spec:
rules:
- host: kibana.test.cn
http:
paths:
- backend:
service:
name: kibana
port:
number: 80
path: /
pathType: ImplementationSpecific
kubectl apply -f kibana.yaml
网友评论