kubernetes 고공용elasticsearch 집단 배치 (一) 배치

32013 단어 Elasticsearch

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 

좋은 웹페이지 즐겨찾기