{"id":7283,"date":"2022-12-24T12:16:05","date_gmt":"2022-12-24T03:16:05","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=7283"},"modified":"2022-12-25T12:49:41","modified_gmt":"2022-12-25T03:49:41","slug":"kubernetes-elasticsearch-%ed%81%b4%eb%9f%ac%ec%8a%a4%ed%84%b0-%ea%b5%ac%ec%84%b1%ed%95%98%ea%b8%b0","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=7283","title":{"rendered":"Kubernetes \u2013 Elasticsearch \ud074\ub7ec\uc2a4\ud130 \uad6c\uc131\ud558\uae30"},"content":{"rendered":"<h1>Kubernetes \u2013 Elasticsearch \ud074\ub7ec\uc2a4\ud130 \uad6c\uc131\ud558\uae30<\/h1>\n<p>. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .<\/p>\n<h2>namespace \uc0dd\uc131<\/h2>\n<pre><code class=\"language-bash\">vi elasticsearch-namespace.yaml\n---------------------------\napiVersion: v1\nkind: Namespace\nmetadata:\n  name: elasticsearch\n---------------------------<\/code><\/pre>\n<h2>service \uc0dd\uc131<\/h2>\n<pre><code class=\"language-bash\">vi elasticsearch-service-discovery.yaml\n---------------------------\napiVersion: v1\nkind: Service\nmetadata:\n  namespace: elasticsearch\n  name: elasticsearch-discovery\n  labels:\n    component: elasticsearch\n    role: master\nspec:\n  selector:\n    component: elasticsearch\n    role: master\n  ports:\n    - name: transport\n      port: 9300\n      protocol: TCP\n  clusterIP: None\n---------------------------<\/code><\/pre>\n<pre><code class=\"language-bash\">vi elasticsearch-service-ingest.yaml\n---------------------------\napiVersion: v1\nkind: Service\nmetadata:\n  namespace: elasticsearch\n  name: elasticsearch-ingest\n  labels:\n    component: elasticsearch\n    role: ingest\nspec:\n  selector:\n    component: elasticsearch\n    role: ingest\n  ports:\n    - name: http\n      port: 9200\n#type: LoadBalancer\n---------------------------<\/code><\/pre>\n<pre><code class=\"language-bash\">vi elasticsearch-service-data.yaml\n---------------------------\napiVersion: v1\nkind: Service\nmetadata:\n  namespace: elasticsearch\n  name: elasticsearch\n  labels:\n    component: elasticsearch\n    role: data\nspec:\n  selector:\n    component: elasticsearch\n    role: data\n  ports:\n    - name: http\n      port: 9200\n#type: LoadBalancer\n---------------------------<\/code><\/pre>\n<h2>master configmap \uc0dd\uc131<\/h2>\n<pre><code class=\"language-bash\">vi elasticsearch-master-config.yaml\n---------------------------\napiVersion: v1\nkind: ConfigMap\nmetadata:\n  namespace: elasticsearch\n  name: elasticsearch-master-config\n  labels:\n    app: elasticsearch\n    role: master\ndata:\n  elasticsearch.yml: |-\n    cluster.name: ${CLUSTER_NAME}                     # \ud074\ub7ec\uc2a4\ud130 \uc774\ub984\n    discovery.seed_hosts: ${NODE_LIST}                # \ub178\ub4dc \ub9ac\uc2a4\ud2b8\n    cluster.initial_master_nodes: elasticsearch-master-0,elasticsearch-master-1,elasticsearch-master-2\n    network.host: 0.0.0.0                             # \uc678\ubd80 \uc811\uadfc\n    node:                                             # \ub178\ub4dc \uc815\ubcf4 \uc635\uc158\n      master: true\n      data: false\n      ingest: false\n    xpack.security.enabled: false                     # X pack \uc758 \uacbd\uc6b0 \ubcf4\uc548\uc124\uc815\n    xpack.monitoring.collection.enabled: false\n---------------------------<\/code><\/pre>\n<h2>master \uc0dd\uc131<\/h2>\n<pre><code class=\"language-bash\">vi elasticsearch-master.yaml\n---------------------------\napiVersion: apps\/v1\nkind: StatefulSet\nmetadata:\n  namespace: elasticsearch\n  name: elasticsearch-master\n  labels:\n    component: elasticsearch\n    role: master\nspec:\n  serviceName: &quot;elasticsearch-master&quot;\n  selector:\n    matchLabels:\n      component: elasticsearch\n      role: master\n  replicas: 3\n  template:\n    metadata:\n      labels:\n        component: elasticsearch\n        role: master\n    spec:\n      initContainers:\n        - name: fix-permissions\n          image: busybox\n          command: [&quot;sh&quot;, &quot;-c&quot;, &quot;chown -R 1000:1000 \/usr\/share\/elasticsearch\/data&quot;]\n          securityContext:\n            privileged: true\n          volumeMounts:\n            - name: storage\n              mountPath: \/usr\/share\/elasticsearch\/data\n        - name: init-sysctl\n          image: busybox\n          command: [&quot;sh&quot;, &quot;-c&quot;, &quot;sysctl -w vm.max_map_count=262144&quot;]\n          securityContext:\n            privileged: true\n      containers:\n        - name: elasticsearch-master\n          image: docker.elastic.co\/elasticsearch\/elasticsearch:7.17.8\n          env:\n            - name: CLUSTER_NAME\n              value: elasticsearch-cluster\n            - name: NODE_LIST\n              value: &quot;elasticsearch-discovery&quot;\n            - name: &quot;ES_JAVA_OPTS&quot;\n              value: &quot;-Xms300m -Xmx300m&quot;\n            - name: NODE_MASTER\n              value: &quot;true&quot;\n            - name: NODE_INGEST\n              value: &quot;false&quot;\n            - name: NODE_DATA\n              value: &quot;false&quot;\n          ports:\n            - name: http\n              containerPort: 9200\n            - name: transport\n              containerPort: 9300\n          livenessProbe:\n            tcpSocket:\n              port: transport\n            initialDelaySeconds: 20\n            periodSeconds: 10\n          volumeMounts:\n            - name: config\n              mountPath: \/usr\/share\/elasticsearch\/config\/elasticsearch.yml\n              readOnly: true\n              subPath: elasticsearch.yml\n            - name: storage\n              mountPath: \/usr\/share\/elasticsearch\/data\n            - name: tz-seoul\n              mountPath: \/etc\/localtime\n      volumes:\n        - name: config\n          configMap:\n            name: elasticsearch-master-config\n        - name: storage\n          emptyDir:\n            medium: &quot;&quot;\n        - name: tz-seoul\n          hostPath:\n            path: \/usr\/share\/zoneinfo\/Asia\/Seoul\n\n---------------------------<\/code><\/pre>\n<h2>ingest configmap \uc0dd\uc131<\/h2>\n<pre><code class=\"language-bash\">vi elasticsearch-ingest-config.yaml\n---------------------------\napiVersion: v1\nkind: ConfigMap\nmetadata:\n  namespace: elasticsearch\n  name: elasticsearch-ingest-config\n  labels:\n    app: elasticsearch\n    role: ingest\ndata:\n  elasticsearch.yml: |-\n    cluster.name: ${CLUSTER_NAME}                     # \ud074\ub7ec\uc2a4\ud130 \uc774\ub984\n    discovery.seed_hosts: ${NODE_LIST}                # \ub178\ub4dc \ub9ac\uc2a4\ud2b8\n    cluster.initial_master_nodes: elasticsearch-master-0,elasticsearch-master-1,elasticsearch-master-2\n    network.host: 0.0.0.0                             # \uc678\ubd80 \uc811\uadfc\n    node:                                             # \ub178\ub4dc \uc815\ubcf4 \uc635\uc158\n      master: false\n      data: false\n      ingest: true\n    xpack.security.enabled: false                     # X pack \uc758 \uacbd\uc6b0 \ubcf4\uc548\uc124\uc815\n    xpack.monitoring.collection.enabled: false\n---------------------------<\/code><\/pre>\n<h2>ingest \uc0dd\uc131<\/h2>\n<pre><code class=\"language-bash\">vi elasticsearch-ingest.yaml\n---------------------------\napiVersion: apps\/v1\nkind: StatefulSet\nmetadata:\n  namespace: elasticsearch\n  name: elasticsearch-ingest\n  labels:\n    component: elasticsearch\n    role: ingest\nspec:\n  serviceName: &quot;elasticsearch-ingest&quot;\n  selector:\n    matchLabels:\n      component: elasticsearch\n      role: ingest\n  replicas: 2\n  template:\n    metadata:\n      labels:\n        component: elasticsearch\n        role: ingest\n    spec:\n      initContainers:\n        - name: fix-permissions\n          image: busybox\n          command: [&quot;sh&quot;, &quot;-c&quot;, &quot;chown -R 1000:1000 \/usr\/share\/elasticsearch\/data&quot;]\n          securityContext:\n            privileged: true\n          volumeMounts:\n            - name: storage\n              mountPath: \/usr\/share\/elasticsearch\/data\n        - name: init-sysctl\n          image: busybox\n          command: [&quot;sh&quot;, &quot;-c&quot;, &quot;sysctl -w vm.max_map_count=262144&quot;]\n          securityContext:\n            privileged: true\n      containers:\n        - name: elasticsearch-ingest\n          image: docker.elastic.co\/elasticsearch\/elasticsearch:7.17.8\n          env:\n            - name: CLUSTER_NAME\n              value: elasticsearch-cluster\n            - name: NODE_LIST\n              value: &quot;elasticsearch-discovery&quot;\n            - name: &quot;ES_JAVA_OPTS&quot;\n              value: &quot;-Xms300m -Xmx300m&quot;\n            - name: NODE_MASTER\n              value: &quot;false&quot;\n            - name: NODE_INGEST\n              value: &quot;true&quot;\n            - name: NODE_DATA\n              value: &quot;false&quot;\n          ports:\n            - name: http\n              containerPort: 9200\n            - name: transport\n              containerPort: 9300\n          livenessProbe:\n            tcpSocket:\n              port: transport\n            initialDelaySeconds: 20\n            periodSeconds: 10\n          volumeMounts:\n            - name: config\n              mountPath: \/usr\/share\/elasticsearch\/config\/elasticsearch.yml\n              readOnly: true\n              subPath: elasticsearch.yml\n            - name: storage\n              mountPath: \/usr\/share\/elasticsearch\/data\n            - name: tz-seoul\n              mountPath: \/etc\/localtime\n      volumes:\n        - name: config\n          configMap:\n            name: elasticsearch-master-config\n        - name: storage\n          emptyDir:\n            medium: &quot;&quot;\n        - name: tz-seoul\n          hostPath:\n            path: \/usr\/share\/zoneinfo\/Asia\/Seoul\n---------------------------<\/code><\/pre>\n<h2>data configmap \uc0dd\uc131<\/h2>\n<pre><code class=\"language-bash\">vi elasticsearch-data-config.yaml\n---------------------------\napiVersion: v1\nkind: ConfigMap\nmetadata:\n  namespace: elasticsearch\n  name: elasticsearch-data-config\n  labels:\n    app: elasticsearch\n    role: data\ndata:\n  elasticsearch.yml: |-\n    cluster.name: ${CLUSTER_NAME}                     # \ud074\ub7ec\uc2a4\ud130 \uc774\ub984\n    discovery.seed_hosts: ${NODE_LIST}                # \ub178\ub4dc \ub9ac\uc2a4\ud2b8\n    cluster.initial_master_nodes: elasticsearch-master-0,elasticsearch-master-1,elasticsearch-master-2\n    network.host: 0.0.0.0                             # \uc678\ubd80 \uc811\uadfc\n    node:                                             # \ub178\ub4dc \uc815\ubcf4 \uc635\uc158\n      master: false\n      data: true\n      ingest: false\n    xpack.security.enabled: false                     # X pack \uc758 \uacbd\uc6b0 \ubcf4\uc548\uc124\uc815\n    xpack.monitoring.collection.enabled: false\n---------------------------<\/code><\/pre>\n<h2>data \uc0dd\uc131<\/h2>\n<pre><code class=\"language-bash\">vi elasticsearch-data.yaml\n---------------------------\napiVersion: apps\/v1\nkind: StatefulSet\nmetadata:\n  namespace: elasticsearch\n  name: elasticsearch-data\n  labels:\n    component: elasticsearch\n    role: data\nspec:\n  serviceName: &quot;elasticsearch-data&quot;\n  selector:\n    matchLabels:\n      component: elasticsearch\n      role: data\n  replicas: 3\n  template:\n    metadata:\n      labels:\n        component: elasticsearch\n        role: data\n    spec:\n      initContainers:\n        - name: fix-permissions\n          image: busybox\n          command: [&quot;sh&quot;, &quot;-c&quot;, &quot;chown -R 1000:1000 \/usr\/share\/elasticsearch\/data&quot;]\n          securityContext:\n            privileged: true\n          volumeMounts:\n            - name: storage\n              mountPath: \/usr\/share\/elasticsearch\/data\n        - name: init-sysctl\n          image: busybox\n          command: [&quot;sh&quot;, &quot;-c&quot;, &quot;sysctl -w vm.max_map_count=262144&quot;]\n          securityContext:\n            privileged: true\n      containers:\n        - name: elasticsearch-data\n          image: docker.elastic.co\/elasticsearch\/elasticsearch:7.17.8\n          env:\n            - name: CLUSTER_NAME\n              value: elasticsearch-cluster\n            - name: NODE_LIST\n              value: &quot;elasticsearch-discovery&quot;\n            - name: &quot;ES_JAVA_OPTS&quot;\n              value: &quot;-Xms300m -Xmx300m&quot;\n            - name: NODE_MASTER\n              value: &quot;false&quot;\n            - name: NODE_INGEST\n              value: &quot;false&quot;\n            - name: NODE_DATA\n              value: &quot;true&quot;\n          ports:\n            - name: http\n              containerPort: 9200\n            - name: transport\n              containerPort: 9300\n          livenessProbe:\n            tcpSocket:\n              port: transport\n            initialDelaySeconds: 20\n            periodSeconds: 10\n          volumeMounts:\n            - name: config\n              mountPath: \/usr\/share\/elasticsearch\/config\/elasticsearch.yml\n              readOnly: true\n              subPath: elasticsearch.yml\n            - name: storage\n              mountPath: \/usr\/share\/elasticsearch\/data\n            - name: tz-seoul\n              mountPath: \/etc\/localtime\n      volumes:\n        - name: config\n          configMap:\n            name: elasticsearch-data-config\n        - name: storage\n          emptyDir:\n            medium: &quot;&quot;\n        - name: tz-seoul\n          hostPath:\n            path: \/usr\/share\/zoneinfo\/Asia\/Seoul\n---------------------------<\/code><\/pre>\n<h2>\uc124\uce58 \ubc0f \ud655\uc778\ud558\uae30<\/h2>\n<pre><code class=\"language-bash\">kubectl apply -f elasticsearch-namespace.yaml\nkubectl apply -f elasticsearch-service-discovery.yaml\nkubectl apply -f elasticsearch-service-ingest.yaml\nkubectl apply -f elasticsearch-service-data.yaml\nkubectl apply -f elasticsearch-master-config.yaml\nkubectl apply -f elasticsearch-master.yaml\nkubectl apply -f elasticsearch-ingest-config.yaml\nkubectl apply -f elasticsearch-ingest.yaml\nkubectl apply -f elasticsearch-data-config.yaml\nkubectl apply -f elasticsearch-data.yaml<\/code><\/pre>\n<pre><code class=\"language-bash\">kubectl get pods -n elasticsearch -o wide\nNAME                     READY   STATUS    RESTARTS   AGE   IP           NODE       NOMINATED NODE   READINESS GATES\nelasticsearch-data-0     1\/1     Running   0          35m   10.32.0.31   notebook   &lt;none&gt;           &lt;none&gt;\nelasticsearch-data-1     1\/1     Running   0          33m   10.32.0.32   notebook   &lt;none&gt;           &lt;none&gt;\nelasticsearch-data-2     1\/1     Running   0          32m   10.32.0.33   notebook   &lt;none&gt;           &lt;none&gt;\nelasticsearch-ingest-0   1\/1     Running   0          30m   10.32.0.28   notebook   &lt;none&gt;           &lt;none&gt;\nelasticsearch-ingest-1   1\/1     Running   0          32m   10.32.0.29   notebook   &lt;none&gt;           &lt;none&gt;\nelasticsearch-master-0   1\/1     Running   0          70m   10.32.0.25   notebook   &lt;none&gt;           &lt;none&gt;\nelasticsearch-master-1   1\/1     Running   0          72m   10.32.0.26   notebook   &lt;none&gt;           &lt;none&gt;\nelasticsearch-master-2   1\/1     Running   0          16m   10.32.0.27   notebook   &lt;none&gt;           &lt;none&gt;\n\nkubectl get svc -n elasticsearch -o wide\nNAME                      TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE   SELECTOR\nelasticsearch             ClusterIP   10.101.44.9     &lt;none&gt;        9200\/TCP   15h   component=elasticsearch,role=data\nelasticsearch-discovery   ClusterIP   None            &lt;none&gt;        9300\/TCP   15h   component=elasticsearch,role=master\nelasticsearch-ingest      ClusterIP   10.107.197.61   &lt;none&gt;        9200\/TCP   15h   component=elasticsearch,role=ingest<\/code><\/pre>\n<pre><code class=\"language-bash\">curl http:\/\/10.101.44.9:9200\/_cluster\/health?pretty\n{\n  &quot;cluster_name&quot; : &quot;elasticsearch-cluster&quot;,\n  &quot;status&quot; : &quot;green&quot;,\n  &quot;timed_out&quot; : false,\n  &quot;number_of_nodes&quot; : 8,\n  &quot;number_of_data_nodes&quot; : 3,\n  &quot;active_primary_shards&quot; : 3,\n  &quot;active_shards&quot; : 6,\n  &quot;relocating_shards&quot; : 0,\n  &quot;initializing_shards&quot; : 0,\n  &quot;unassigned_shards&quot; : 0,\n  &quot;delayed_unassigned_shards&quot; : 0,\n  &quot;number_of_pending_tasks&quot; : 0,\n  &quot;number_of_in_flight_fetch&quot; : 0,\n  &quot;task_max_waiting_in_queue_millis&quot; : 0,\n  &quot;active_shards_percent_as_number&quot; : 100.0\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Kubernetes \u2013 Elasticsearch \ud074\ub7ec\uc2a4\ud130 \uad6c\uc131\ud558\uae30 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=7283\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-7283","post","type-post","status-publish","format-standard","hentry","category-elasticsearch"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/7283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7283"}],"version-history":[{"count":15,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/7283\/revisions"}],"predecessor-version":[{"id":7299,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/7283\/revisions\/7299"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}