kubernetes部署高空用elasticsearch集群(一)部署

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_39316848/article/details/83866656
前言:第一篇是纯部署 第二篇进行详细的参数介绍

1.部署Elasticsearch集群

1.1 基础环境

  kubernetes 1.11.0、docker.elastic.co/elasticsearch/elasticsearch:5.6.4
  [镜像下载地址](https://www.docker.elastic.co/) 访问需要翻墙

1.2 配置文件

1.2.1 elasticsearch.yaml

   apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: elasticsearch-logging
      namespace: kube-system
      labels:
        k8s-app: elasticsearch-logging
        kubernetes.io/cluster-service: "true"
        addonmanager.kubernetes.io/mode: Reconcile
    ---
    kind: ClusterRole
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      name: elasticsearch-logging
      labels:
        k8s-app: elasticsearch-logging
        kubernetes.io/cluster-service: "true"
        addonmanager.kubernetes.io/mode: Reconcile
    rules:
    - apiGroups:
      - ""
      resources:
      - "services"
      - "namespaces"
      - "endpoints"
      verbs:
      - "get"
    ---
    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      namespace: kube-system
      name: elasticsearch-logging
      labels:
        k8s-app: elasticsearch-logging
        kubernetes.io/cluster-service: "true"
        addonmanager.kubernetes.io/mode: Reconcile
    subjects:
    - kind: ServiceAccount
      name: elasticsearch-logging
      namespace: kube-system
      apiGroup: ""
    roleRef:
      kind: ClusterRole
      name: elasticsearch-logging
      apiGroup: ""
    ---
    apiVersion: apps/v1beta1
    kind: StatefulSet
    metadata:
      name: elasticsearch-master
      namespace: kube-system
      labels:
        k8s-app: elasticsearch-logging
        version: v5.6.4
        kubernetes.io/cluster-service: "true"
        addonmanager.kubernetes.io/mode: Reconcile
    spec:
      serviceName: elasticsearch-logging
      replicas: 3
      selector:
        matchLabels:
          k8s-app: elasticsearch-logging
          version: v5.6.4
      template:
        metadata:
          labels:
            k8s-app: elasticsearch-logging
            version: v5.6.4
            kubernetes.io/cluster-service: "true"
        spec:
          serviceAccountName: elasticsearch-logging
          containers:
          - image: elasticsearch:5.6.4
            name: elasticsearch-master
            resources:
              limits:
                cpu: 1000m
              requests:
                cpu: 100m
            ports:
            - containerPort: 9200
              name: db
              protocol: TCP
            - containerPort: 9300
              name: transport
              protocol: TCP
            env:
              - name: "cluster.name"
                value: "elasticsearch-cluster"
              - name: "node.name"
                value: "${HOSTNAME}"
              - name: "bootstrap.memory_lock"
                value: "false"
              - name: "discovery.zen.ping.unicast.hosts"
                value: "elasticsearch-discovery"
              - name: "discovery.zen.minimum_master_nodes"
                value: "2"
              - name: "discovery.zen.ping_timeout"
                value: "5s"
              - name: "node.master"
                value: "true"
              - name: "node.data"
                value: "false"
              - name: "node.ingest"
                value: "false"
              - name: "ES_JAVA_OPTS"
                value: "-Xms256m -Xmx256m"
              - name: kube-system
                valueFrom:
                  fieldRef:
                    fieldPath: metadata.namespace
          initContainers:
          - image: alpine:3.6
            command: ["/sbin/sysctl", "-w", "vm.max_map_count=262144"]
            name: elasticsearch-logging-init
            securityContext:
              privileged: true
    ---
    apiVersion: apps/v1beta1
    kind: StatefulSet
    metadata:
      name: elasticsearch-data
      namespace: kube-system
      labels:
        k8s-app: elasticsearch-logging
        version: v5.6.4
        kubernetes.io/cluster-service: "true"
        addonmanager.kubernetes.io/mode: Reconcile
    spec:
      serviceName: elasticsearch-logging
      replicas: 1
      selector:
        matchLabels:
          k8s-app: elasticsearch-logging
          version: v5.6.4
      template:
        metadata:
          labels:
            k8s-app: elasticsearch-logging
            version: v5.6.4
            kubernetes.io/cluster-service: "true"
        spec:
          serviceAccountName: elasticsearch-logging
          containers:
          - image: elasticsearch:5.6.4
            name: elasticsearch-data
            resources:
              limits:
                cpu: 1000m
              requests:
                cpu: 100m
            ports:
            - containerPort: 9200
              name: db
              protocol: TCP
            - containerPort: 9300
              name: transport
              protocol: TCP
            volumeMounts:
            - name: elasticsearch-data
              mountPath: /usr/share/elasticsearch/data
            env:
              - name: "cluster.name"
                value: "elasticsearch-cluster"
              - name: "node.name"
                value: "${HOSTNAME}"
              - name: "bootstrap.memory_lock"
                value: "false"
              - name: "discovery.zen.ping.unicast.hosts"
                value: "elasticsearch-discovery"
              - name: "node.master"
                value: "false"
              - name: "node.data"
                value: "true"
              - name: "ES_JAVA_OPTS"
                value: "-Xms256m -Xmx256m"
              - name: kube-system
                valueFrom:
                  fieldRef:
                    fieldPath: metadata.namespace
          initContainers:
          - image: alpine:3.6
            command: ["/sbin/sysctl", "-w", "vm.max_map_count=262144"]
            name: elasticsearch-logging-init
            securityContext:
              privileged: true  
          volumes:
           - name: elasticsearch-data
             emptyDir: {}
    #        - hostPath:
    #           path: /usr/share/elasticsearch/nodedata
    #        name: elasticsearch-data
    #  volumeClaimTemplates:
    #    - metadata:
    #        name: elasticsearch-data
    #      spec:
    #        accessModes: ["ReadWriteOnce"]
    #        storageClassName: "ceph-sc-ext4"
    #        resources:
    #          requests:
    #            storage: 100Mi

1.2.2 discovery-es.yaml

   apiVersion: v1
   kind: Service
   metadata:
     name: elasticsearch-discovery
     namespace: kube-system
     labels:
       k8s-app: elasticsearch-logging
       kubernetes.io/cluster-service: "true"
       addonmanager.kubernetes.io/mode: Reconcile
       kubernetes.io/name: "Elasticsearch"
   spec:
     ports:
       - port: 9300
         protocol: TCP
         targetPort: transport
     selector:
       k8s-app: elasticsearch-logging

1.2.3 service-es.yaml

 apiVersion: v1
    kind: Service
    metadata:
      name: elasticsearch-logging
      namespace: kube-system
      labels:
        k8s-app: elasticsearch-logging
        kubernetes.io/cluster-service: "true"
        addonmanager.kubernetes.io/mode: Reconcile
        kubernetes.io/name: "Elasticsearch"
    spec:
      type: NodePort
      ports:
      - port: 9200
        protocol: TCP
        targetPort: db
        nodePort: 30011
      selector:
        k8s-app: elasticsearch-logging

1.2.4 部署应用

把以上yaml文件。放在一个目录下

    kubectl apply -f   elasticsearch/

或者进入该目录下

    kubectl apply -f elasticsearch.yaml
    kubectl apply -f discovery-es.yaml
    kubectl apply -f service-es.yaml 
展开阅读全文

没有更多推荐了,返回首页