kubernetes集群搭建ES

---
apiVersion: v1
kind: Service
metadata:
  name: elasticsearch
  namespace: ${K8S_NAMESPACE}
  labels:
    k8s-app: elasticsearch
    kubernetes.io/cluster-service: "true"
    addonmanager.kubernetes.io/mode: Reconcile
    kubernetes.io/name: "Elasticsearch"
spec:
  type: NodePort
  ports:
    - name: db
      port: 9200
      protocol: TCP
      targetPort: 9200
      nodePort: 39200
    - name: transport
      port: 9300
      protocol: TCP
      targetPort: 9300
  publishNotReadyAddresses: true
  selector:
    k8s-app: elasticsearch
  sessionAffinity: None
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: elasticsearch
  namespace: ${K8S_NAMESPACE}
  labels:
    k8s-app: elasticsearch
    addonmanager.kubernetes.io/mode: Reconcile
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: elasticsearch
  labels:
    k8s-app: elasticsearch
    addonmanager.kubernetes.io/mode: Reconcile
rules:
  - apiGroups:
      - ""
    resources:
      - "services"
      - "namespaces"
      - "endpoints"
    verbs:
      - "get"
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: ${K8S_NAMESPACE}
  name: elasticsearch
  labels:
    k8s-app: elasticsearch
    addonmanager.kubernetes.io/mode: Reconcile
subjects:
  - kind: ServiceAccount
    name: elasticsearch
    namespace: ${K8S_NAMESPACE}
    apiGroup: ""
roleRef:
  kind: ClusterRole
  name: elasticsearch
  apiGroup: ""
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: elasticsearch
  namespace: ${K8S_NAMESPACE}
  labels:
    k8s-app: elasticsearch
    version: v7.17.15
    addonmanager.kubernetes.io/mode: Reconcile
spec:
  serviceName: elasticsearch
  replicas: 3
  selector:
    matchLabels:
      k8s-app: elasticsearch
      version: v7.17.15
  template:
    metadata:
      labels:
        k8s-app: elasticsearch
        version: v7.17.15
    spec:
      serviceAccountName: elasticsearch
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: kubernetes.io/hostname
                    operator: In
                    values:
                      - ${K8S_ES_NODE1}
                      - ${K8S_ES_NODE2}
                      - ${K8S_ES_NODE3}
      containers:
        - image: docker.elastic.co/elasticsearch/elasticsearch:${ES_IMAGE}
          name: elasticsearch
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              cpu: 1000m
              memory: 2Gi
            requests:
              cpu: 100m
              memory: 2Gi
          ports:
            - containerPort: 9200
              name: db
              protocol: TCP
            - containerPort: 9300
              name: transport
              protocol: TCP
          volumeMounts:
            - name: elasticsearch
              mountPath: /usr/share/elasticsearch/data/
          env:
            - name: cluster.initial_master_nodes
              value: "elasticsearch-0,elasticsearch-1,elasticsearch-2"
            - name: discovery.seed_hosts
              value: "elasticsearch"
      volumes:
        - name: elasticsearch
          hostPath:
            path: /tmp/elasticsearch
            type: DirectoryOrCreate
      initContainers:
        - image: alpine:3.6
          command: [ "/sbin/sysctl", "-w", "vm.max_map_count=262144" ]
          name: elasticsearch-init
          securityContext:
            privileged: true
        - image: alpine:3.6
          command: [ "/bin/sh", "-c", "chown -R 1000:1000 /usr/share/elasticsearch/data" ]
          name: elasticsearch-permissions
          volumeMounts:
            - name: elasticsearch
              mountPath: /usr/share/elasticsearch/data/
          securityContext:
            privileged: true
            runAsUser: 0

你可能感兴趣的:(elasticsearch,jenkins,大数据)