前置要求

依赖配置

  1. 二进制部署任意版本docker

域名配置

address=/elasticsearch1.basic.tanqidi.com/172.31.0.100
address=/kibana.dev.tanqidi.com/172.31.0.100

1. docker 部署

1.1 单机部署

https://hub.docker.com/_/elasticsearch

mkdir -p /data/elasticsearch/ && chown -R 1000:1000 /data/elasticsearch/

docker run -d --name elasticsearch \
  --restart=always \
  -p 9200:9200 -p 9300:9300 \
  -v /data/elasticsearch/:/usr/share/elasticsearch/data \
  -e "discovery.type=single-node" \
  docker.elastic.co/elasticsearch/elasticsearch:7.10.1

1.2 kibana

# 使用 kibana.dev.tanqidi.com 来访问
docker run -d --name kibana \
  -e ELASTICSEARCH_HOSTS=http://elasticsearch1.basic.tanqidi.com:9200 \
  -e I18N_LOCALE=zh-CN \
  -p 5601:5601 \
  --restart=always \
  kibana:7.10.1

2. kubernetes 部署

2.1 单机部署

2.1.1 deployment

kind: Deployment
apiVersion: apps/v1
metadata:
  name: elasticsearch
  namespace: basic
  labels:
    app: elasticsearch
  annotations:
    deployment.kubernetes.io/revision: '1'
    kubesphere.io/creator: admin
spec:
  replicas: 1
  selector:
    matchLabels:
      app: elasticsearch
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: elasticsearch
      annotations:
        kubesphere.io/creator: admin
        kubesphere.io/imagepullsecrets: '{}'
        logging.kubesphere.io/logsidecar-config: '{}'
    spec:
      volumes:
        - name: host-time
          hostPath:
            path: /etc/localtime
            type: ''
        - name: elasticsearch-data
          persistentVolumeClaim:
            claimName: elasticsearch-data
      containers:
        - name: elasticsearch
          image: 'docker.elastic.co/elasticsearch/elasticsearch:7.10.1'
          ports:
            - name: tcp-9200
              containerPort: 9200
              protocol: TCP
            - name: tcp-9300
              containerPort: 9300
              protocol: TCP
          env:
            - name: discovery.type
              value: single-node
          resources: {}
          volumeMounts:
            - name: host-time
              readOnly: true
              mountPath: /etc/localtime
            - name: elasticsearch-data
              mountPath: /usr/share/elasticsearch/data
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      serviceAccountName: default
      serviceAccount: default
      securityContext: {}
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600

2.1.2 service

使用了NodePort来测试访问

kind: Service
apiVersion: v1
metadata:
  name: elasticsearch
  namespace: basic
  labels:
    app: elasticsearch
  annotations:
    kubesphere.io/creator: admin
spec:
  ports:
    - name: http-9200
      protocol: TCP
      port: 9200
      targetPort: 9200
      nodePort: 31165
    - name: http-9300
      protocol: TCP
      port: 9300
      targetPort: 9300
      nodePort: 31472
  selector:
    app: elasticsearch
  type: NodePort
  sessionAffinity: None
  externalTrafficPolicy: Cluster
  ipFamilies:
    - IPv4
  ipFamilyPolicy: SingleStack
  internalTrafficPolicy: Cluster

2.1.3 coredns(可选)

为了兼容开发环境的写法,可以将相关配置集成到 CoreDNS 中,这样能够提升灵活性和可维护性。

# 目前只有一个实例,后面会拓展成为集群写法
rewrite name elasticsearch1.basic.tanqidi.com elasticsearch.basic.svc.cluster.local

2.2 kibana

2.2.1 deployment

kind: Deployment
apiVersion: apps/v1
metadata:
  name: kibana
  namespace: basic
  labels:
    app: kibana
  annotations:
    deployment.kubernetes.io/revision: '1'
    kubesphere.io/creator: admin
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kibana
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: kibana
      annotations:
        kubesphere.io/creator: admin
        kubesphere.io/imagepullsecrets: '{}'
        kubesphere.io/restartedAt: '2024-10-30T06:17:25.020Z'
    spec:
      containers:
        - name: kibana
          image: 'kibana:7.10.1'
          ports:
            - name: http-5601
              containerPort: 5601
              protocol: TCP
          env:
            - name: I18N_LOCALE
              value: zh-CN
            - name: ELASTICSEARCH_HOSTS
              value: 'http://elasticsearch.basic.svc.cluster.local:9200'
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      serviceAccountName: default
      serviceAccount: default
      securityContext: {}
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600

2.2.2 service

使用了NodePort来测试访问

kind: Service
apiVersion: v1
metadata:
  name: kibana
  namespace: basic
  labels:
    app: kibana
  annotations:
    kubesphere.io/creator: admin
spec:
  ports:
    - name: http-5601
      protocol: TCP
      port: 5601
      targetPort: 5601
      nodePort: 30920
  selector:
    app: kibana
  type: NodePort
  sessionAffinity: None
  externalTrafficPolicy: Cluster
  ipFamilies:
    - IPv4
  ipFamilyPolicy: SingleStack
  internalTrafficPolicy: Cluster

图片-szsp.png