写在最前

1. docker 部署

2. kubernetes 部署

2.1 configmap

kind: ConfigMap
apiVersion: v1
metadata:
  name: elasticsearch-config
  namespace: bx
  annotations:
    kubesphere.io/creator: admin
data:
  elasticsearch.yml: |-
    cluster.name: my-es
    node.name: ${HOSTNAME}
    network.host: 0.0.0.0
    discovery.type: single-node

    # 开启安全认证
    xpack.security.enabled: true
    xpack.license.self_generated.type: basic
    xpack.security.transport.ssl.enabled: true

2.2 service

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

2.3 deployment

kind: Deployment
apiVersion: apps/v1
metadata:
  name: elasticsearch
  namespace: bx
  labels:
    app: elasticsearch
  annotations:
    deployment.kubernetes.io/revision: '5'
    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: '{}'
        kubesphere.io/restartedAt: '2025-08-20T08:32:02.614Z'
        logging.kubesphere.io/logsidecar-config: '{}'
    spec:
      volumes:
        - name: host-time
          hostPath:
            path: /etc/localtime
            type: ''
        - name: elasticsearch-data
          persistentVolumeClaim:
            claimName: elasticsearch-data
        - name: volume-ltof3c
          configMap:
            name: elasticsearch-config
            items:
              - key: elasticsearch.yml
                path: elasticsearch.yml
            defaultMode: 420
      containers:
        - name: elasticsearch
          image: 'elasticsearch/elasticsearch:7.17.28'
          ports:
            - name: tcp-9200
              containerPort: 9200
              protocol: TCP
            - name: tcp-9300
              containerPort: 9300
              protocol: TCP
          env:
            - name: discovery.type
              value: single-node
            - name: ES_JAVA_OPTS
              value: '-Xms4g -Xmx4g'
          resources: {}
          volumeMounts:
            - name: host-time
              readOnly: true
              mountPath: /etc/localtime
            - name: elasticsearch-data
              mountPath: /usr/share/elasticsearch/data
            - name: volume-ltof3c
              readOnly: true
              mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
              subPath: elasticsearch.yml
          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.4 生成秘钥

进入容器执行它,输入y

bin/elasticsearch-setup-passwords auto

2.5 部署 kibana

2.5.1 configmap

kind: ConfigMap
apiVersion: v1
metadata:
  name: kibana-config
  namespace: bx
  annotations:
    kubesphere.io/creator: admin
data:
  kibana.yml: |
    server.name: kibana
    server.host: "0.0.0.0"
    elasticsearch.hosts: ["http://elasticsearch.bx.svc.cluster.local:9200"]
    elasticsearch.username: "kibana_system"
    elasticsearch.password: "xxxxxxxxxxxxxxxxxxxxxxxxx"

2.5.2 service

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

2.5.3 deployment

kind: Deployment
apiVersion: apps/v1
metadata:
  name: kibana
  namespace: bx
  labels:
    app: kibana
  annotations:
    deployment.kubernetes.io/revision: '13'
    kubesphere.io/creator: admin
    kubesphere.io/description: 'kibana:7.17.28'
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: '2025-08-20T09:13:30.070Z'
        logging.kubesphere.io/logsidecar-config: '{}'
    spec:
      volumes:
        - name: volume-evl8sg
          configMap:
            name: kibana-config
            items:
              - key: kibana.yml
                path: kibana.yml
            defaultMode: 420
      containers:
        - name: kibana
          image: 'kibana:7.17.28'
          ports:
            - name: http-5601
              containerPort: 5601
              protocol: TCP
          env:
            - name: I18N_LOCALE
              value: zh-CN
            - name: ELASTICSEARCH_HOSTS
              value: 'http://elasticsearch.bx.svc.cluster.local:9200'
          resources: {}
          volumeMounts:
            - name: volume-evl8sg
              readOnly: true
              mountPath: /usr/share/kibana/config/kibana.yml
              subPath: kibana.yml
          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