From 616c33b28a398653daf5a68b4b71b7d48a59b940 Mon Sep 17 00:00:00 2001 From: emil Date: Wed, 11 Jan 2017 17:29:31 +0000 Subject: [PATCH 01/16] Initial commit --- LICENSE.txt | 15 + NOTICE.txt | 16 + README.md | 405 +++++------- elasticsearch.yml | 25 +- header.txt | 13 + kubernetes.yml | 178 +++++ pom.xml | 619 ++++++++---------- resources/es-plugin.properties | 2 + src/docker/Dockerfile | 76 +++ src/docker/config/elasticsearch.yml | 17 + src/docker/config/logging.yml | 31 + src/docker/docker-entrypoint.sh | 39 ++ src/main/assemblies/plugin.xml | 38 +- .../plugin-descriptor.properties | 23 + src/plugin-metadata/plugin-security.policy | 24 + 15 files changed, 926 insertions(+), 595 deletions(-) create mode 100644 header.txt create mode 100644 kubernetes.yml create mode 100644 resources/es-plugin.properties create mode 100644 src/docker/Dockerfile create mode 100644 src/docker/config/elasticsearch.yml create mode 100644 src/docker/config/logging.yml create mode 100644 src/docker/docker-entrypoint.sh create mode 100644 src/plugin-metadata/plugin-descriptor.properties create mode 100644 src/plugin-metadata/plugin-security.policy diff --git a/LICENSE.txt b/LICENSE.txt index d645695..acd9779 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,3 +1,18 @@ +==== + Copyright (C) 2015 Red Hat, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==== Apache License Version 2.0, January 2004 diff --git a/NOTICE.txt b/NOTICE.txt index e69de29..561df81 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -0,0 +1,16 @@ +==== + Copyright (C) 2015 Red Hat, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==== + diff --git a/README.md b/README.md index 501a20f..0e71191 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,21 @@ Kubernetes Cloud Plugin for Elasticsearch: The Kubernetes Cloud plugin allows to use Kubernetes API for the unicast discovery mechanism. -## Version 1.0.x for Elasticsearch: 1.4 -## Version 1.1.x/1.2.x for Elasticsearch: 1.5 -## Version 1.3.x for Elasticsearch: 1.6 - Installation ============ ``` -plugin install io.fabric8/elasticsearch-cloud-kubernetes/1.2.1 +plugin install io.fabric8/elasticsearch-cloud-kubernetes/2.4.0 ``` +Versions available +================== + +As of `2.0.0`, each released version of this plugin is compatible with the equal version of Elasticsearch, +e.g. `2.2.0` of this plugin is compatible with `2.2.0` of Elasticsearch. + +**Older versions**: +* `1.3.x` for Elasticsearch `1.6` and `1.7` + Kubernetes Pod Discovery =============================== @@ -23,10 +28,11 @@ Here is a simple sample configuration: ```yaml cloud: - k8s: - servicedns: ${SERVICE_DNS} + kubernetes: + service: ${SERVICE} + namespace: ${NAMESPACE} discovery: - type: io.fabric8.elasticsearch.discovery.k8s.K8sDiscoveryModule + type: kubernetes path: data: /data/data @@ -35,19 +41,6 @@ path: work: /data/work ``` -If you want to use Kubernetes service endpoints instead (remember this will require auth to the -Kubernetes API server if you do this), then use: - -``` -service: ${SERVICE} -namespace: ${NAMESPACE} -``` - -Depending on which once you choose, you can then either: - -* Set the `SERVICE` & `NAMESPACE` environment variables to specify the service to discover endpoints for, e.g. `elasticsearch-cluster`. -* Set the `SERVICE_DNS` environment variable to specify the service name to look up endpoints for in DNS, e.g. `elasticsearch-cluster`. - ## Kubernetes auth The preferred way to authenticate to Kubernetes is to use [service accounts](https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/design/service_accounts.md). @@ -57,7 +50,7 @@ As an example, to create a service account do something like: ``` cat < spec: - serviceAccount: elasticsearch + serviceAccountName: elasticsearch ``` This will mount the service account token at `/var/run/secrets/kubernetes.io/servicaccount/token` & will be automatically read by the fabric8 kubernetes client when the request is made to the API server. -There are also a number of different environment variables that you may find useful: - -. `KUBERNETES_TRUST_CERT=false`: disable certificate validation. Set to true to trust the Kubernetes API server certificate. -. `KUBECONFIG`: path to a standard Kubernetes config file to use for authentication configuration. - # Kubernetes example -In this example, we're going to use `servicedns` to look up the Elasticsearch cluster nodes to join. +In this example, we're going to use a headless service to look up the Elasticsearch cluster nodes to join. The following manifest uses 3 replication controllers to created Elasticsearch pods in 3 different modes: @@ -101,218 +89,147 @@ We use 2 services as well: * One to target the client pods so that all requests to the cluster go through the client nodes * A headless service to list all cluster endpoints managed by all 3 RCs. -The DNS lookup is on the headless service name so that all existing nodes from the cluster are discovered on startup & the cluster is joined. - -```json -{ - "id": "elasticsearch-list", - "kind": "List", - "apiVersion": "v1beta2", - "name": "elasticsearch-config", - "description": "Configuration for elasticsearch", - "items": [ - { - "id": "elasticsearch", - "apiVersion": "v1beta1", - "kind": "Service", - "containerPort": 9200, - "port": 9200, - "selector": { - "component": "elasticsearch", - "type": "client", - "provider": "fabric8" - } - }, - { - "id": "elasticsearch-cluster", - "apiVersion": "v1beta1", - "PortalIP": "None", - "kind": "Service", - "containerPort": 9300, - "port": 9300, - "selector": { - "component": "elasticsearch", - "provider": "fabric8" - } - }, - { - "id": "elasticsearch-client-rc", - "kind": "ReplicationController", - "apiVersion": "v1beta1", - "desiredState": { - "replicas": 1, - "replicaSelector": { - "component": "elasticsearch", - "type": "client", - "provider": "fabric8" - }, - "podTemplate": { - "desiredState": { - "manifest": { - "version": "v1beta1", - "id": "elasticsearchPod", - "containers": [ - { - "name": "elasticsearch-container", - "image": "fabric8/elasticsearch-k8s:1.5.0", - "imagePullPolicy": "PullIfNotPresent", - "env": [ - { - "name": "SERVICE_DNS", - "value": "elasticsearch-cluster" - }, - { - "name": "KUBERNETES_TRUST_CERT", - "value": "true" - }, - { - "name": "NODE_DATA", - "value": "false" - }, - { - "name": "NODE_MASTER", - "value": "false" - } - ], - "ports": [ - { - "containerPort": 9200 - }, - { - "containerPort": 9300 - } - ] - } - ] - } - }, - "labels": { - "component": "elasticsearch", - "type": "client", - "provider": "fabric8" - } - } - }, - "labels": { - "component": "elasticsearch", - "type": "client", - "provider": "fabric8" - } - }, - { - "id": "elasticsearch-data-rc", - "kind": "ReplicationController", - "apiVersion": "v1beta1", - "desiredState": { - "replicas": 1, - "replicaSelector": { - "component": "elasticsearch", - "type": "data", - "provider": "fabric8" - }, - "podTemplate": { - "desiredState": { - "manifest": { - "version": "v1beta1", - "id": "elasticsearchPod", - "containers": [ - { - "name": "elasticsearch-container", - "image": "fabric8/elasticsearch-k8s:1.5.0", - "imagePullPolicy": "PullIfNotPresent", - "env": [ - { - "name": "SERVICE_DNS", - "value": "elasticsearch-cluster" - }, - { - "name": "KUBERNETES_TRUST_CERT", - "value": "true" - }, - { - "name": "NODE_MASTER", - "value": "false" - } - ], - "ports": [ - { - "containerPort": 9300 - } - ] - } - ] - } - }, - "labels": { - "component": "elasticsearch", - "type": "data", - "provider": "fabric8" - } - } - }, - "labels": { - "component": "elasticsearch", - "type": "data", - "provider": "fabric8" - } - }, - { - "id": "elasticsearch-master-rc", - "kind": "ReplicationController", - "apiVersion": "v1beta1", - "desiredState": { - "replicas": 1, - "replicaSelector": { - "component": "elasticsearch", - "type": "master", - "provider": "fabric8" - }, - "podTemplate": { - "desiredState": { - "manifest": { - "version": "v1beta1", - "id": "elasticsearchPod", - "containers": [ - { - "name": "elasticsearch-container", - "image": "fabric8/elasticsearch-k8s:1.5.0", - "imagePullPolicy": "PullIfNotPresent", - "env": [ - { - "name": "SERVICE_DNS", - "value": "elasticsearch-cluster" - }, - { - "name": "KUBERNETES_TRUST_CERT", - "value": "true" - }, - { - "name": "NODE_DATA", - "value": "false" - } - ], - "ports": [ - { - "containerPort": 9300 - } - ] - } - ] - } - }, - "labels": { - "component": "elasticsearch", - "type": "master", - "provider": "fabric8" - } - } - }, - "labels": { - "component": "elasticsearch", - "type": "master", - "provider": "fabric8" - } - } - ] -} +```yaml +kind: "List" +apiVersion: "v1" +items: +- apiVersion: "v1" + kind: "Service" + metadata: + name: "elasticsearch" + spec: + ports: + - port: 9200 + targetPort: "http" + selector: + component: "elasticsearch" + type: "client" + provider: "fabric8" + type: "LoadBalancer" +- apiVersion: "v1" + kind: "Service" + metadata: + name: "elasticsearch-cluster" + spec: + clusterIP: "None" + ports: + - port: 9300 + targetPort: 9300 + selector: + provider: "fabric8" + component: "elasticsearch" +- apiVersion: "v1" + kind: "ReplicationController" + metadata: + name: "elasticsearch-data" + spec: + replicas: 1 + selector: + component: "elasticsearch" + type: "data" + provider: "fabric8" + template: + metadata: + labels: + component: "elasticsearch" + type: "data" + provider: "fabric8" + spec: + serviceAccount: elasticsearch + serviceAccountName: elasticsearch + containers: + - env: + - name: "SERVICE" + value: "elasticsearch-cluster" + - name: "KUBERNETES_NAMESPACE" + valueFrom: + fieldRef: + fieldPath: "metadata.namespace" + - name: "NODE_MASTER" + value: "false" + image: "fabric8/elasticsearch-k8s:2.4.0" + name: "elasticsearch" + ports: + - containerPort: 9300 + name: "transport" + volumeMounts: + - mountPath: "/usr/share/elasticsearch/data" + name: "elasticsearch-data" + readOnly: false + volumes: + - emptyDir: + medium: "" + name: "elasticsearch-data" +- apiVersion: "v1" + kind: "ReplicationController" + metadata: + name: "elasticsearch-master" + spec: + replicas: 1 + selector: + component: "elasticsearch" + type: "master" + provider: "fabric8" + template: + metadata: + labels: + component: "elasticsearch" + type: "master" + provider: "fabric8" + spec: + serviceAccount: elasticsearch + serviceAccountName: elasticsearch + containers: + - env: + - name: "SERVICE" + value: "elasticsearch-cluster" + - name: "KUBERNETES_NAMESPACE" + valueFrom: + fieldRef: + fieldPath: "metadata.namespace" + - name: "NODE_DATA" + value: "false" + image: "fabric8/elasticsearch-k8s:2.4.0" + name: "elasticsearch" + ports: + - containerPort: 9300 + name: "transport" +- apiVersion: "v1" + kind: "ReplicationController" + metadata: + name: "elasticsearch-client" + spec: + replicas: 1 + selector: + component: "elasticsearch" + type: "client" + provider: "fabric8" + template: + metadata: + labels: + component: "elasticsearch" + type: "client" + provider: "fabric8" + spec: + serviceAccount: elasticsearch + serviceAccountName: elasticsearch + containers: + - env: + - name: "SERVICE" + value: "elasticsearch-cluster" + - name: "KUBERNETES_NAMESPACE" + valueFrom: + fieldRef: + fieldPath: "metadata.namespace" + - name: "NODE_DATA" + value: "false" + - name: "NODE_MASTER" + value: "false" + image: "fabric8/elasticsearch-k8s:2.4.0" + name: "elasticsearch" + ports: + - containerPort: 9200 + name: "http" + - containerPort: 9300 + name: "transport" ``` diff --git a/elasticsearch.yml b/elasticsearch.yml index 13d4675..b194ad1 100644 --- a/elasticsearch.yml +++ b/elasticsearch.yml @@ -1,12 +1,31 @@ +# +# Copyright (C) 2015 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + node.data: ${NODE_DATA} node.master: ${NODE_MASTER} +network.host: 0.0.0.0 + cloud: - k8s: - servicedns: ${SERVICE_DNS} + kubernetes: + service: ${SERVICE} + namespace: ${KUBERNETES_NAMESPACE} discovery: - type: io.fabric8.elasticsearch.discovery.k8s.K8sDiscoveryModule + type: kubernetes path: plugins: /usr/share/elasticsearch/plugins diff --git a/header.txt b/header.txt new file mode 100644 index 0000000..12de4d4 --- /dev/null +++ b/header.txt @@ -0,0 +1,13 @@ +Copyright (C) ${project.inceptionYear} ${owner} + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/kubernetes.yml b/kubernetes.yml new file mode 100644 index 0000000..d90fc32 --- /dev/null +++ b/kubernetes.yml @@ -0,0 +1,178 @@ +# +# Copyright (C) 2015 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +kind: "List" +apiVersion: "v1" +items: +- apiVersion: "v1" + kind: "Service" + metadata: + name: "elasticsearch" + labels: + component: "elasticsearch" + provider: "fabric8" + spec: + ports: + - port: 9200 + targetPort: 9200 + selector: + component: "elasticsearch" + type: "client" + provider: "fabric8" + type: "LoadBalancer" +- apiVersion: "v1" + kind: "Service" + metadata: + name: "elasticsearch-masters" + labels: + component: "elasticsearch" + type: "master" + provider: "fabric8" + spec: + clusterIP: "None" + ports: + - port: 9300 + targetPort: 9300 + selector: + provider: "fabric8" + type: "master" + component: "elasticsearch" +- apiVersion: "v1" + kind: "ReplicationController" + metadata: + name: "elasticsearch-data" + labels: + component: "elasticsearch" + type: "data" + provider: "fabric8" + spec: + replicas: 1 + selector: + component: "elasticsearch" + type: "data" + provider: "fabric8" + template: + metadata: + labels: + component: "elasticsearch" + type: "data" + provider: "fabric8" + spec: + serviceAccount: elasticsearch + serviceAccountName: elasticsearch + containers: + - env: + - name: "SERVICE" + value: "elasticsearch-masters" + - name: "KUBERNETES_NAMESPACE" + valueFrom: + fieldRef: + fieldPath: "metadata.namespace" + - name: "NODE_MASTER" + value: "false" + image: "fabric8/elasticsearch-k8s:2.2.1" + name: "elasticsearch" + ports: + - containerPort: 9300 + name: "transport" + volumeMounts: + - mountPath: "/usr/share/elasticsearch/data" + name: "elasticsearch-data" + readOnly: false + volumes: + - emptyDir: + medium: "" + name: "elasticsearch-data" +- apiVersion: "v1" + kind: "ReplicationController" + metadata: + name: "elasticsearch-master" + labels: + component: "elasticsearch" + type: "master" + provider: "fabric8" + spec: + replicas: 1 + selector: + component: "elasticsearch" + type: "master" + provider: "fabric8" + template: + metadata: + labels: + component: "elasticsearch" + type: "master" + provider: "fabric8" + spec: + serviceAccount: elasticsearch + serviceAccountName: elasticsearch + containers: + - env: + - name: "SERVICE" + value: "elasticsearch-masters" + - name: "KUBERNETES_NAMESPACE" + valueFrom: + fieldRef: + fieldPath: "metadata.namespace" + - name: "NODE_DATA" + value: "false" + image: "fabric8/elasticsearch-k8s:2.2.1" + name: "elasticsearch" + ports: + - containerPort: 9300 + name: "transport" +- apiVersion: "v1" + kind: "ReplicationController" + metadata: + name: "elasticsearch-client" + labels: + component: "elasticsearch" + type: "master" + provider: "fabric8" + spec: + replicas: 1 + selector: + component: "elasticsearch" + type: "client" + provider: "fabric8" + template: + metadata: + labels: + component: "elasticsearch" + type: "client" + provider: "fabric8" + spec: + serviceAccount: elasticsearch + serviceAccountName: elasticsearch + containers: + - env: + - name: "SERVICE" + value: "elasticsearch-masters" + - name: "KUBERNETES_NAMESPACE" + valueFrom: + fieldRef: + fieldPath: "metadata.namespace" + - name: "NODE_DATA" + value: "false" + - name: "NODE_MASTER" + value: "false" + image: "fabric8/elasticsearch-k8s:2.2.1" + name: "elasticsearch" + ports: + - containerPort: 9200 + name: "http" + - containerPort: 9300 + name: "transport" diff --git a/pom.xml b/pom.xml index b3aba40..1f6f355 100644 --- a/pom.xml +++ b/pom.xml @@ -1,358 +1,301 @@ - + + + 4.0.0 + io.fabric8 + elasticsearch-cloud-kubernetes + 1.7.6-SNAPSHOT - - 1.6.0 - 2.2.4 - 4.10.4 - true - onerror - - 9300 - INFO - ${project.build.testOutputDirectory}/elasticsearch.yml - + Elasticsearch Kubernetes cloud plugin + The Kubernetes Cloud plugin allows to use Kubernetes for the unicast discovery mechanism. + https://github.com/jimmidyson/elasticsearch-cloud-kubernetes/ + 2015 - - - org.hamcrest - hamcrest-core - 1.3.RC2 - test - - - org.hamcrest - hamcrest-library - 1.3.RC2 - test - + + org.sonatype.oss + oss-parent + 9 + - - org.apache.lucene - lucene-test-framework - ${lucene.version} - test - + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + scm:git:git@github.com:fabric8io/elasticsearch-cloud-kubernetes.git + scm:git:git@github.com:fabric8io/elasticsearch-cloud-kubernetes.git + http://github.com/fabric8io/elasticsearch-cloud-kubernetes + - - - org.elasticsearch - elasticsearch - ${elasticsearch.version} - + + GitHub + https://github.com/fabric8io/elasticsearch-cloud-kubernetes/issues/ + - - - io.fabric8 - kubernetes-api - ${fabric8.version} - + + 2.2.4 + cloud-kubernetes + 1.7.6 + 1.3.83 + 5.5.2 + true + onerror + + 9300 + INFO + ${project.build.testOutputDirectory}/elasticsearch.yml + - - - org.slf4j - slf4j-log4j12 - 1.7.7 - + + + org.hamcrest + hamcrest-core + 1.3.RC2 + test + + + org.hamcrest + hamcrest-library + 1.3.RC2 + test + - - - log4j - log4j - 1.2.17 - test - + + org.apache.lucene + lucene-test-framework + ${lucene.version} + test + - - org.elasticsearch - elasticsearch - ${elasticsearch.version} - test-jar - test - + + + org.elasticsearch + elasticsearch + ${elasticsearch.version} + - + + + com.fasterxml.jackson.core + jackson-databind + 2.5.3 + - - - - org.kuali.maven.wagons - maven-s3-wagon - 1.1.19 - - + + + io.fabric8 + kubernetes-api + ${fabric8.version} + - - - src/main/resources - true - - - - - src/test/resources - true - - plugin-test.properties - elasticsearch.yml - - - - src/test/resources - false - - log4j.xml - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - - - - com.carrotsearch.randomizedtesting - junit4-maven-plugin - 2.0.14 - - - tests - test - - junit4 - - - 20 - pipe,warn - true - - - - - - - - - 1 - - - - - - - **/*Tests.class - **/*Test.class - - - **/Abstract*.class - **/*StressTest.class - - - ${tests.jvm.argline} - - - -Xmx512m - -Xss256k - -XX:MaxDirectMemorySize=512m - -Des.logger.prefix= - - ${tests.shuffle} - ${tests.verbose} - ${tests.seed} - ${tests.failfast} - - - ${tests.jvm.argline} - ${tests.iters} - ${tests.maxfailures} - ${tests.failfast} - ${tests.class} - ${tests.method} - ${tests.nightly} - ${tests.badapples} - ${tests.weekly} - ${tests.slow} - ${tests.k8s} - ${tests.config} - ${tests.awaitsfix} - ${tests.slow} - ${tests.timeoutSuite} - ${tests.showSuccess} - ${tests.integration} - ${tests.cluster_seed} - ${tests.client.ratio} - false - network - ${es.logger.level} - true - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.15 - - true - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar - - - - - - maven-assembly-plugin - 2.4 - - false - ${project.build.directory}/releases/ - - ${basedir}/src/main/assemblies/plugin.xml - - - - - package - - single - - - - - - org.jolokia - docker-maven-plugin - 0.12.0 - - - - docker.io/fabric8/elasticsearch-k8s:${elasticsearch.version} - - elasticsearch:${elasticsearch.version} - - ${basedir}/src/main/assemblies/docker-image.xml - /usr/share/elasticsearch/ - - - true - true - - - - - - - - org.apache.maven.plugins - maven-release-plugin - 2.5 - - docker-push - - - - - - - docker-push - + + + io.fabric8 + kubernetes-client + ${kubernetes-client.version} + + + + + org.slf4j + slf4j-log4j12 + 1.7.7 + + + + + log4j + log4j + 1.2.17 + test + + + + org.elasticsearch + elasticsearch + ${elasticsearch.version} + test-jar + test + + + + + + + + org.kuali.maven.wagons + maven-s3-wagon + 1.1.19 + + + + + + src/main/plugin-metadata + true + + + + + src/test/resources + true + + plugin-test.properties + elasticsearch.yml + + + + src/test/resources + false + + log4j.xml + + + - - org.jolokia - docker-maven-plugin - - - - build - - package - - - - - org.codehaus.mojo - exec-maven-plugin - 1.4.0 - - - - exec - - package - - - - docker - - push - -f - docker.io/fabric8/elasticsearch-k8s:${elasticsearch.version} - - - + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.15 + + true + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar + + + + + + maven-assembly-plugin + 2.4 + + false + ${project.build.directory}/releases/ + + ${basedir}/src/main/assemblies/plugin.xml + + + + + package + + single + + + + + + io.fabric8 + docker-maven-plugin + 0.15.7 + + + + docker.io/fabric8/elasticsearch:${elasticsearch.version} + + ${project.basedir}/src/main/docker + + + + docker.io/fabric8/elasticsearch-k8s:${elasticsearch.version} + + docker.io/fabric8/elasticsearch:${elasticsearch.version} + + ${basedir}/src/main/assemblies/docker-image.xml + /usr/share/elasticsearch/ + + + true + true + -Djava.net.preferIPv4Stack=true + + + + + + + + org.apache.maven.plugins + maven-release-plugin + 2.5 + + docker-deploy + deploy docker:build docker:push + + + + com.mycila + license-maven-plugin + 2.11 + + true +
header.txt
+ + Red Hat, Inc. + + + .editorconfig + license.txt + +
+
-
- - + + + + + docker-build + + clean install docker:build + + + + docker-deploy + + clean install docker:build docker:push + + +
diff --git a/resources/es-plugin.properties b/resources/es-plugin.properties new file mode 100644 index 0000000..028a92e --- /dev/null +++ b/resources/es-plugin.properties @@ -0,0 +1,2 @@ +plugin=io.fabric8.elasticsearch.plugin.cloud.k8s.CloudK8sPlugin +version=${project.version} diff --git a/src/docker/Dockerfile b/src/docker/Dockerfile new file mode 100644 index 0000000..4a89f14 --- /dev/null +++ b/src/docker/Dockerfile @@ -0,0 +1,76 @@ +# +# Copyright (C) 2015 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +FROM java:8-jre + +# grab gosu for easy step-down from root +ENV GOSU_VERSION 1.7 +RUN set -x \ + && wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \ + && wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \ + && export GNUPGHOME="$(mktemp -d)" \ + && gpg --keyserver hkp://hkps.pool.sks-keyservers.net:80 --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \ + && gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \ + && rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \ + && chmod +x /usr/local/bin/gosu \ + && gosu nobody true + +# https://artifacts.elastic.co/GPG-KEY-elasticsearch +RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 46095ACC8548582C1A2699A9D27D666CD88E42B4 + +# https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-repositories.html +# https://www.elastic.co/guide/en/elasticsearch/reference/5.0/deb.html +RUN set -x \ + && apt-get update && apt-get install -y --no-install-recommends apt-transport-https && rm -rf /var/lib/apt/lists/* \ + && echo 'deb http://packages.elasticsearch.org/elasticsearch/1.7/debian stable main' > /etc/apt/sources.list.d/elasticsearch.list + +ENV ELASTICSEARCH_VERSION 1.7.6 +ENV ELASTICSEARCH_DEB_VERSION 1.7.6 + +RUN set -x \ + \ +# don't allow the package to install its sysctl file (causes the install to fail) +# Failed to write '262144' to '/proc/sys/vm/max_map_count': Read-only file system + && dpkg-divert --rename /usr/lib/sysctl.d/elasticsearch.conf \ + \ + && apt-get update \ + && apt-get install -y --no-install-recommends "elasticsearch=$ELASTICSEARCH_DEB_VERSION" \ + && rm -rf /var/lib/apt/lists/* + +ENV PATH /usr/share/elasticsearch/bin:$PATH + +WORKDIR /usr/share/elasticsearch + +RUN set -ex \ + && for path in \ + ./data \ + ./logs \ + ./config \ + ./config/scripts \ + ; do \ + mkdir -p "$path"; \ + chown -R elasticsearch:elasticsearch "$path"; \ + done + +COPY config ./config + +VOLUME /usr/share/elasticsearch/data + +COPY docker-entrypoint.sh / + +EXPOSE 9200 9300 +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["elasticsearch"] diff --git a/src/docker/config/elasticsearch.yml b/src/docker/config/elasticsearch.yml new file mode 100644 index 0000000..2644bc7 --- /dev/null +++ b/src/docker/config/elasticsearch.yml @@ -0,0 +1,17 @@ +# +# Copyright (C) 2015 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +network.host: 0.0.0.0 diff --git a/src/docker/config/logging.yml b/src/docker/config/logging.yml new file mode 100644 index 0000000..3046ddb --- /dev/null +++ b/src/docker/config/logging.yml @@ -0,0 +1,31 @@ +# +# Copyright (C) 2015 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# you can override this using by setting a system property, for example -Des.logger.level=DEBUG +es.logger.level: INFO +rootLogger: ${es.logger.level}, console +logger: + # log action execution errors for easier debugging + action: DEBUG + # reduce the logging for aws, too much is logged under the default INFO + com.amazonaws: WARN + +appender: + console: + type: console + layout: + type: consolePattern + conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n" diff --git a/src/docker/docker-entrypoint.sh b/src/docker/docker-entrypoint.sh new file mode 100644 index 0000000..a6c7492 --- /dev/null +++ b/src/docker/docker-entrypoint.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# +# Copyright (C) 2015 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +set -e + +# Add elasticsearch as command if needed +if [ "${1:0:1}" = '-' ]; then + set -- elasticsearch "$@" +fi + +# Drop root privileges if we are running elasticsearch +# allow the container to be started with `--user` +if [ "$1" = 'elasticsearch' -a "$(id -u)" = '0' ]; then + # Change the ownership of /usr/share/elasticsearch/data to elasticsearch + chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data + + set -- gosu elasticsearch "$@" + #exec gosu elasticsearch "$BASH_SOURCE" "$@" +fi + +# As argument is not related to elasticsearch, +# then assume that user wants to run his own process, +# for example a `bash` shell to explore this image +exec "$@" diff --git a/src/main/assemblies/plugin.xml b/src/main/assemblies/plugin.xml index 634831c..a290915 100644 --- a/src/main/assemblies/plugin.xml +++ b/src/main/assemblies/plugin.xml @@ -1,21 +1,39 @@ - + plugin zip false + + + ${basedir}/src/main/plugin-metadata/plugin-security.policy + + false + + + ${basedir}/src/main/plugin-metadata/plugin-descriptor.properties + + true + + / diff --git a/src/plugin-metadata/plugin-descriptor.properties b/src/plugin-metadata/plugin-descriptor.properties new file mode 100644 index 0000000..c0ac594 --- /dev/null +++ b/src/plugin-metadata/plugin-descriptor.properties @@ -0,0 +1,23 @@ +# +# Copyright (C) 2015 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +name=${elasticsearch.plugin.name} +version=${project.version} +jvm=true +classname=io.fabric8.elasticsearch.plugin.discovery.kubernetes.KubernetesDiscoveryPlugin +description=${project.name} +elasticsearch.version=${elasticsearch.version} +java.version=1.8 diff --git a/src/plugin-metadata/plugin-security.policy b/src/plugin-metadata/plugin-security.policy new file mode 100644 index 0000000..3ccaf5a --- /dev/null +++ b/src/plugin-metadata/plugin-security.policy @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +grant { + permission java.lang.RuntimePermission "accessDeclaredMembers"; + permission java.lang.RuntimePermission "setFactory"; + permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; + permission java.io.FilePermission "<>", "read,execute,readlink"; + permission java.net.NetPermission "getProxySelector"; + permission java.net.NetPermission "getCookieHandler"; +}; From 8729c71f297ecac3f102d97ada8dc66aeb1ef78b Mon Sep 17 00:00:00 2001 From: emil Date: Thu, 12 Jan 2017 10:50:56 +0000 Subject: [PATCH 02/16] adapt version 1.3.0 for ES 1.7.6 --- elasticsearch.yml | 5 ++--- kubernetes.yml | 6 +++--- pom.xml | 11 ++++++++--- src/main/assemblies/plugin.xml | 4 ++-- src/{ => main}/docker/Dockerfile | 1 + src/{ => main}/docker/config/elasticsearch.yml | 0 src/{ => main}/docker/config/logging.yml | 0 src/{ => main}/docker/docker-entrypoint.sh | 0 .../plugin-metadata/plugin-descriptor.properties | 0 src/{ => main}/plugin-metadata/plugin-security.policy | 2 +- .../java/io/fabric8/cloud/k8s/AbstractK8sTest.java | 7 ++++--- .../java/io/fabric8/k8s/itest/K8sSimpleITest.java | 3 ++- 12 files changed, 23 insertions(+), 16 deletions(-) rename src/{ => main}/docker/Dockerfile (98%) rename src/{ => main}/docker/config/elasticsearch.yml (100%) rename src/{ => main}/docker/config/logging.yml (100%) rename src/{ => main}/docker/docker-entrypoint.sh (100%) rename src/{ => main}/plugin-metadata/plugin-descriptor.properties (100%) rename src/{ => main}/plugin-metadata/plugin-security.policy (99%) diff --git a/elasticsearch.yml b/elasticsearch.yml index b194ad1..fdbb9de 100644 --- a/elasticsearch.yml +++ b/elasticsearch.yml @@ -21,11 +21,10 @@ network.host: 0.0.0.0 cloud: kubernetes: - service: ${SERVICE} - namespace: ${KUBERNETES_NAMESPACE} + servicedns: ${SERVICE_DNS} discovery: - type: kubernetes + type: io.fabric8.elasticsearch.discovery.k8s.K8sDiscoveryModule path: plugins: /usr/share/elasticsearch/plugins diff --git a/kubernetes.yml b/kubernetes.yml index d90fc32..b12623d 100644 --- a/kubernetes.yml +++ b/kubernetes.yml @@ -83,7 +83,7 @@ items: fieldPath: "metadata.namespace" - name: "NODE_MASTER" value: "false" - image: "fabric8/elasticsearch-k8s:2.2.1" + image: "essearch/elasticsearch-k8s:1.7.6" name: "elasticsearch" ports: - containerPort: 9300 @@ -129,7 +129,7 @@ items: fieldPath: "metadata.namespace" - name: "NODE_DATA" value: "false" - image: "fabric8/elasticsearch-k8s:2.2.1" + image: "essearch/elasticsearch-k8s:1.7.6" name: "elasticsearch" ports: - containerPort: 9300 @@ -169,7 +169,7 @@ items: value: "false" - name: "NODE_MASTER" value: "false" - image: "fabric8/elasticsearch-k8s:2.2.1" + image: "essearch/elasticsearch-k8s:1.7.6" name: "elasticsearch" ports: - containerPort: 9200 diff --git a/pom.xml b/pom.xml index 1f6f355..3d0d734 100644 --- a/pom.xml +++ b/pom.xml @@ -67,6 +67,11 @@ + + junit + junit + 4.12 + org.hamcrest hamcrest-core @@ -229,15 +234,15 @@ - docker.io/fabric8/elasticsearch:${elasticsearch.version} + essearch/elasticsearch:${elasticsearch.version}.2 ${project.basedir}/src/main/docker - docker.io/fabric8/elasticsearch-k8s:${elasticsearch.version} + essearch/elasticsearch-k8s:${elasticsearch.version}.2 - docker.io/fabric8/elasticsearch:${elasticsearch.version} + essearch/elasticsearch:${elasticsearch.version}.2 ${basedir}/src/main/assemblies/docker-image.xml /usr/share/elasticsearch/ diff --git a/src/main/assemblies/plugin.xml b/src/main/assemblies/plugin.xml index a290915..1be2863 100644 --- a/src/main/assemblies/plugin.xml +++ b/src/main/assemblies/plugin.xml @@ -24,12 +24,12 @@ false - ${basedir}/src/main/plugin-metadata/plugin-security.policy + src/main/plugin-metadata/plugin-security.policy false - ${basedir}/src/main/plugin-metadata/plugin-descriptor.properties + src/main/plugin-metadata/plugin-descriptor.properties true diff --git a/src/docker/Dockerfile b/src/main/docker/Dockerfile similarity index 98% rename from src/docker/Dockerfile rename to src/main/docker/Dockerfile index 4a89f14..027dd88 100644 --- a/src/docker/Dockerfile +++ b/src/main/docker/Dockerfile @@ -70,6 +70,7 @@ COPY config ./config VOLUME /usr/share/elasticsearch/data COPY docker-entrypoint.sh / +RUN chmod a+x /docker-entrypoint.sh EXPOSE 9200 9300 ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/src/docker/config/elasticsearch.yml b/src/main/docker/config/elasticsearch.yml similarity index 100% rename from src/docker/config/elasticsearch.yml rename to src/main/docker/config/elasticsearch.yml diff --git a/src/docker/config/logging.yml b/src/main/docker/config/logging.yml similarity index 100% rename from src/docker/config/logging.yml rename to src/main/docker/config/logging.yml diff --git a/src/docker/docker-entrypoint.sh b/src/main/docker/docker-entrypoint.sh similarity index 100% rename from src/docker/docker-entrypoint.sh rename to src/main/docker/docker-entrypoint.sh diff --git a/src/plugin-metadata/plugin-descriptor.properties b/src/main/plugin-metadata/plugin-descriptor.properties similarity index 100% rename from src/plugin-metadata/plugin-descriptor.properties rename to src/main/plugin-metadata/plugin-descriptor.properties diff --git a/src/plugin-metadata/plugin-security.policy b/src/main/plugin-metadata/plugin-security.policy similarity index 99% rename from src/plugin-metadata/plugin-security.policy rename to src/main/plugin-metadata/plugin-security.policy index 3ccaf5a..f57cea6 100644 --- a/src/plugin-metadata/plugin-security.policy +++ b/src/main/plugin-metadata/plugin-security.policy @@ -17,7 +17,7 @@ grant { permission java.lang.RuntimePermission "accessDeclaredMembers"; permission java.lang.RuntimePermission "setFactory"; - permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; + permission java.lang.reflect.ReflectPermission "suppressAccessChecksv"; permission java.io.FilePermission "<>", "read,execute,readlink"; permission java.net.NetPermission "getProxySelector"; permission java.net.NetPermission "getCookieHandler"; diff --git a/src/test/java/io/fabric8/cloud/k8s/AbstractK8sTest.java b/src/test/java/io/fabric8/cloud/k8s/AbstractK8sTest.java index ee1f061..352d9f9 100644 --- a/src/test/java/io/fabric8/cloud/k8s/AbstractK8sTest.java +++ b/src/test/java/io/fabric8/cloud/k8s/AbstractK8sTest.java @@ -8,6 +8,7 @@ import org.elasticsearch.env.FailedToResolveConfigException; import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.test.ElasticsearchIntegrationTest; +import org.junit.Assert; import java.lang.annotation.Documented; import java.lang.annotation.Inherited; @@ -23,7 +24,7 @@ public abstract class AbstractK8sTest extends ElasticsearchIntegrationTest { * Annotation for tests that require GCE to run. GCE tests are disabled by default. * See README file for details. */ - @Documented + @Documented @Inherited @Retention(RetentionPolicy.RUNTIME) @TestGroup(enabled = false, sysProperty = SYSPROP_K8S) @@ -47,10 +48,10 @@ protected Settings nodeSettings(int nodeOrdinal) { if (Strings.hasText(System.getProperty("tests.config"))) { settings.loadFromUrl(environment.resolveConfig(System.getProperty("tests.config"))); } else { - fail("to run integration tests, you need to set -Dtest.k8s=true and -Dtests.config=/path/to/elasticsearch.yml"); + Assert.fail("to run integration tests, you need to set -Dtest.k8s=true and -Dtests.config=/path/to/elasticsearch.yml"); } } catch (FailedToResolveConfigException exception) { - fail("your test configuration file is incorrect: " + System.getProperty("tests.config")); + Assert.fail("your test configuration file is incorrect: " + System.getProperty("tests.config")); } return settings.build(); } diff --git a/src/test/java/io/fabric8/k8s/itest/K8sSimpleITest.java b/src/test/java/io/fabric8/k8s/itest/K8sSimpleITest.java index ad4763b..6e2a3f6 100644 --- a/src/test/java/io/fabric8/k8s/itest/K8sSimpleITest.java +++ b/src/test/java/io/fabric8/k8s/itest/K8sSimpleITest.java @@ -7,6 +7,7 @@ import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.hamcrest.Matchers; +import org.junit.Assert; import org.junit.Test; @AbstractK8sTest.K8sTest @@ -32,7 +33,7 @@ public void one_node_should_run() { System.out.println(clusterState.getState().getNodes().getSize()); - assertThat(clusterState.getState().getNodes().getSize(), Matchers.greaterThanOrEqualTo(2)); + Assert.assertThat(clusterState.getState().getNodes().getSize(), Matchers.greaterThanOrEqualTo(2)); } @Override From 1e1671829a4c362f5d6808559be84dd871da53fe Mon Sep 17 00:00:00 2001 From: emil Date: Thu, 12 Jan 2017 11:15:43 +0000 Subject: [PATCH 03/16] Fix issues --- elasticsearch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticsearch.yml b/elasticsearch.yml index fdbb9de..ec911fe 100644 --- a/elasticsearch.yml +++ b/elasticsearch.yml @@ -20,7 +20,7 @@ node.master: ${NODE_MASTER} network.host: 0.0.0.0 cloud: - kubernetes: + k8s: servicedns: ${SERVICE_DNS} discovery: From 211398e21c7ec4be071242c370413bf728df21c2 Mon Sep 17 00:00:00 2001 From: emil Date: Thu, 12 Jan 2017 11:56:37 +0000 Subject: [PATCH 04/16] working version with ES 1.7.6 --- kubernetes.yml | 85 ++++++------------- pom.xml | 6 +- .../k8s/K8sUnicastHostsProvider.java | 4 +- 3 files changed, 30 insertions(+), 65 deletions(-) diff --git a/kubernetes.yml b/kubernetes.yml index b12623d..418b8c1 100644 --- a/kubernetes.yml +++ b/kubernetes.yml @@ -1,46 +1,36 @@ -# -# Copyright (C) 2015 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - kind: "List" apiVersion: "v1" items: + +- apiVersion: v1 + kind: ServiceAccount + metadata: + name: elasticsearch + - apiVersion: "v1" kind: "Service" metadata: name: "elasticsearch" - labels: - component: "elasticsearch" - provider: "fabric8" spec: - ports: - - port: 9200 - targetPort: 9200 + type: "LoadBalancer" selector: component: "elasticsearch" type: "client" provider: "fabric8" - type: "LoadBalancer" + ports: + - name: http + port: 9200 + protocol: TCP + - name: transport + port: 9300 + protocol: TCP + loadBalancerSourceRanges: + - 10.0.0.0/8 + - apiVersion: "v1" kind: "Service" metadata: - name: "elasticsearch-masters" - labels: - component: "elasticsearch" - type: "master" - provider: "fabric8" + name: "elasticsearch-cluster" spec: clusterIP: "None" ports: @@ -48,16 +38,11 @@ items: targetPort: 9300 selector: provider: "fabric8" - type: "master" component: "elasticsearch" - apiVersion: "v1" kind: "ReplicationController" metadata: name: "elasticsearch-data" - labels: - component: "elasticsearch" - type: "data" - provider: "fabric8" spec: replicas: 1 selector: @@ -75,12 +60,8 @@ items: serviceAccountName: elasticsearch containers: - env: - - name: "SERVICE" - value: "elasticsearch-masters" - - name: "KUBERNETES_NAMESPACE" - valueFrom: - fieldRef: - fieldPath: "metadata.namespace" + - name: "SERVICE_DNS" + value: "elasticsearch-cluster" - name: "NODE_MASTER" value: "false" image: "essearch/elasticsearch-k8s:1.7.6" @@ -100,10 +81,6 @@ items: kind: "ReplicationController" metadata: name: "elasticsearch-master" - labels: - component: "elasticsearch" - type: "master" - provider: "fabric8" spec: replicas: 1 selector: @@ -121,12 +98,8 @@ items: serviceAccountName: elasticsearch containers: - env: - - name: "SERVICE" - value: "elasticsearch-masters" - - name: "KUBERNETES_NAMESPACE" - valueFrom: - fieldRef: - fieldPath: "metadata.namespace" + - name: "SERVICE_DNS" + value: "elasticsearch-cluster" - name: "NODE_DATA" value: "false" image: "essearch/elasticsearch-k8s:1.7.6" @@ -138,10 +111,6 @@ items: kind: "ReplicationController" metadata: name: "elasticsearch-client" - labels: - component: "elasticsearch" - type: "master" - provider: "fabric8" spec: replicas: 1 selector: @@ -159,12 +128,8 @@ items: serviceAccountName: elasticsearch containers: - env: - - name: "SERVICE" - value: "elasticsearch-masters" - - name: "KUBERNETES_NAMESPACE" - valueFrom: - fieldRef: - fieldPath: "metadata.namespace" + - name: "SERVICE_DNS" + value: "elasticsearch-cluster" - name: "NODE_DATA" value: "false" - name: "NODE_MASTER" @@ -175,4 +140,4 @@ items: - containerPort: 9200 name: "http" - containerPort: 9300 - name: "transport" + name: "transport" \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3d0d734..955389d 100644 --- a/pom.xml +++ b/pom.xml @@ -234,15 +234,15 @@ - essearch/elasticsearch:${elasticsearch.version}.2 + essearch/elasticsearch:${elasticsearch.version} ${project.basedir}/src/main/docker - essearch/elasticsearch-k8s:${elasticsearch.version}.2 + essearch/elasticsearch-k8s:${elasticsearch.version} - essearch/elasticsearch:${elasticsearch.version}.2 + essearch/elasticsearch:${elasticsearch.version} ${basedir}/src/main/assemblies/docker-image.xml /usr/share/elasticsearch/ diff --git a/src/main/java/io/fabric8/elasticsearch/discovery/k8s/K8sUnicastHostsProvider.java b/src/main/java/io/fabric8/elasticsearch/discovery/k8s/K8sUnicastHostsProvider.java index 1cba70a..26b41ba 100644 --- a/src/main/java/io/fabric8/elasticsearch/discovery/k8s/K8sUnicastHostsProvider.java +++ b/src/main/java/io/fabric8/elasticsearch/discovery/k8s/K8sUnicastHostsProvider.java @@ -51,8 +51,8 @@ static final public class Fields { @Inject public K8sUnicastHostsProvider(Settings settings, - TransportService transportService, - NetworkService networkService) { + TransportService transportService, + NetworkService networkService) { super(settings); this.transportService = transportService; this.networkService = networkService; From b7a2972490c7337b3f3a9c7cf354fa28f4eafac5 Mon Sep 17 00:00:00 2001 From: Emilien Brigand Date: Thu, 12 Jan 2017 12:40:22 +0000 Subject: [PATCH 05/16] Revert to the fabric8 docker id for an official release --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 955389d..60e974e 100644 --- a/pom.xml +++ b/pom.xml @@ -234,15 +234,15 @@ - essearch/elasticsearch:${elasticsearch.version} + fabric8/elasticsearch:${elasticsearch.version} ${project.basedir}/src/main/docker - essearch/elasticsearch-k8s:${elasticsearch.version} + fabric8/elasticsearch-k8s:${elasticsearch.version} - essearch/elasticsearch:${elasticsearch.version} + fabric8/elasticsearch:${elasticsearch.version} ${basedir}/src/main/assemblies/docker-image.xml /usr/share/elasticsearch/ From a94805297bc431c43ee089c761ac07ac15591069 Mon Sep 17 00:00:00 2001 From: Emilien Brigand Date: Thu, 12 Jan 2017 12:47:50 +0000 Subject: [PATCH 06/16] Revert to the original version of the file coming from the tag elasticsearch-cloud-kubernetes-2.4.0_01 --- src/main/assemblies/plugin.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/assemblies/plugin.xml b/src/main/assemblies/plugin.xml index 1be2863..a290915 100644 --- a/src/main/assemblies/plugin.xml +++ b/src/main/assemblies/plugin.xml @@ -24,12 +24,12 @@ false - src/main/plugin-metadata/plugin-security.policy + ${basedir}/src/main/plugin-metadata/plugin-security.policy false - src/main/plugin-metadata/plugin-descriptor.properties + ${basedir}/src/main/plugin-metadata/plugin-descriptor.properties true From 76ca7fdce81de2fa5bd6143859911b5072e28a4f Mon Sep 17 00:00:00 2001 From: Emilien Brigand Date: Thu, 12 Jan 2017 12:54:46 +0000 Subject: [PATCH 07/16] Update to reflect the change for ES 1.7.6 --- README.md | 133 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 110 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 0e71191..d1be52a 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,13 @@ The Kubernetes Cloud plugin allows to use Kubernetes API for the unicast discove Installation ============ ``` -plugin install io.fabric8/elasticsearch-cloud-kubernetes/2.4.0 +plugin install io.fabric8/elasticsearch-cloud-kubernetes/1.7.6 ``` Versions available ================== -As of `2.0.0`, each released version of this plugin is compatible with the equal version of Elasticsearch, -e.g. `2.2.0` of this plugin is compatible with `2.2.0` of Elasticsearch. - -**Older versions**: -* `1.3.x` for Elasticsearch `1.6` and `1.7` +* `1.7.6` for Elasticsearch `1.7.6` Kubernetes Pod Discovery =============================== @@ -27,12 +23,14 @@ Kubernetes Pod discovery allows to use the kubernetes APIs to perform automatic Here is a simple sample configuration: ```yaml -cloud: - kubernetes: - service: ${SERVICE} - namespace: ${NAMESPACE} discovery: - type: kubernetes + +cloud: + k8s: + servicedns: ${SERVICE_DNS} + +discovery: + type: io.fabric8.elasticsearch.discovery.k8s.K8sDiscoveryModule path: data: /data/data @@ -178,18 +176,111 @@ items: provider: "fabric8" spec: serviceAccount: elasticsearch +kind: "List" +apiVersion: "v1" +items: + +- apiVersion: v1 + kind: ServiceAccount + metadata: + name: elasticsearch + +- apiVersion: "v1" + kind: "Service" + metadata: + name: "elasticsearch" + spec: + type: "LoadBalancer" + selector: + component: "elasticsearch" + type: "client" + provider: "fabric8" + ports: + - name: http + port: 9200 + protocol: TCP + - name: transport + port: 9300 + protocol: TCP + loadBalancerSourceRanges: + - 10.0.0.0/8 + +- apiVersion: "v1" + kind: "Service" + metadata: + name: "elasticsearch-cluster" + spec: + clusterIP: "None" + ports: + - port: 9300 + targetPort: 9300 + selector: + provider: "fabric8" + component: "elasticsearch" +- apiVersion: "v1" + kind: "ReplicationController" + metadata: + name: "elasticsearch-data" + spec: + replicas: 1 + selector: + component: "elasticsearch" + type: "data" + provider: "fabric8" + template: + metadata: + labels: + component: "elasticsearch" + type: "data" + provider: "fabric8" + spec: + serviceAccount: elasticsearch serviceAccountName: elasticsearch containers: - env: - - name: "SERVICE" + - name: "SERVICE_DNS" + value: "elasticsearch-cluster" + - name: "NODE_MASTER" + value: "false" + image: "essearch/elasticsearch-k8s:1.7.6" + name: "elasticsearch" + ports: + - containerPort: 9300 + name: "transport" + volumeMounts: + - mountPath: "/usr/share/elasticsearch/data" + name: "elasticsearch-data" + readOnly: false + volumes: + - emptyDir: + medium: "" + name: "elasticsearch-data" +- apiVersion: "v1" + kind: "ReplicationController" + metadata: + name: "elasticsearch-master" + spec: + replicas: 1 + selector: + component: "elasticsearch" + type: "master" + provider: "fabric8" + template: + metadata: + labels: + component: "elasticsearch" + type: "master" + provider: "fabric8" + spec: + serviceAccount: elasticsearch + serviceAccountName: elasticsearch + containers: + - env: + - name: "SERVICE_DNS" value: "elasticsearch-cluster" - - name: "KUBERNETES_NAMESPACE" - valueFrom: - fieldRef: - fieldPath: "metadata.namespace" - name: "NODE_DATA" value: "false" - image: "fabric8/elasticsearch-k8s:2.4.0" + image: "essearch/elasticsearch-k8s:1.7.6" name: "elasticsearch" ports: - containerPort: 9300 @@ -215,17 +306,13 @@ items: serviceAccountName: elasticsearch containers: - env: - - name: "SERVICE" + - name: "SERVICE_DNS" value: "elasticsearch-cluster" - - name: "KUBERNETES_NAMESPACE" - valueFrom: - fieldRef: - fieldPath: "metadata.namespace" - name: "NODE_DATA" value: "false" - name: "NODE_MASTER" value: "false" - image: "fabric8/elasticsearch-k8s:2.4.0" + image: "essearch/elasticsearch-k8s:1.7.6" name: "elasticsearch" ports: - containerPort: 9200 From 20efb6f087274126b6038a7401707ea4753b258d Mon Sep 17 00:00:00 2001 From: Emilien Brigand Date: Thu, 12 Jan 2017 12:56:49 +0000 Subject: [PATCH 08/16] Revert to tag 1.3.0 --- LICENSE.txt | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index acd9779..d645695 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,18 +1,3 @@ -==== - Copyright (C) 2015 Red Hat, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==== Apache License Version 2.0, January 2004 From 0fad367b6ad6df70074b22ce1293bc13839d4bf4 Mon Sep 17 00:00:00 2001 From: Emilien Brigand Date: Thu, 12 Jan 2017 12:58:22 +0000 Subject: [PATCH 09/16] Revert to the version of the tag 1.3.0 --- NOTICE.txt | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index 561df81..8b13789 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -1,16 +1 @@ -==== - Copyright (C) 2015 Red Hat, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==== From 2ec745d371de8dee69b39dec1be7de9ec937824d Mon Sep 17 00:00:00 2001 From: Emilien Brigand Date: Thu, 12 Jan 2017 12:58:58 +0000 Subject: [PATCH 10/16] Remove an unnecessary carriage return From 4a885e5e6a0751215a2df101c45a615a3628aacb Mon Sep 17 00:00:00 2001 From: Emilien Brigand Date: Thu, 12 Jan 2017 12:59:36 +0000 Subject: [PATCH 11/16] Remove an unnecessary carriage return From 049a3ac57772f60faafcd087c96cf676f28b1403 Mon Sep 17 00:00:00 2001 From: Emilien Brigand Date: Thu, 12 Jan 2017 13:02:32 +0000 Subject: [PATCH 12/16] Use the fabric8 docker id for an official release --- kubernetes.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kubernetes.yml b/kubernetes.yml index 418b8c1..cb68484 100644 --- a/kubernetes.yml +++ b/kubernetes.yml @@ -64,7 +64,7 @@ items: value: "elasticsearch-cluster" - name: "NODE_MASTER" value: "false" - image: "essearch/elasticsearch-k8s:1.7.6" + image: "fabric8/elasticsearch-k8s:1.7.6" name: "elasticsearch" ports: - containerPort: 9300 @@ -102,7 +102,7 @@ items: value: "elasticsearch-cluster" - name: "NODE_DATA" value: "false" - image: "essearch/elasticsearch-k8s:1.7.6" + image: "fabric8/elasticsearch-k8s:1.7.6" name: "elasticsearch" ports: - containerPort: 9300 @@ -134,10 +134,10 @@ items: value: "false" - name: "NODE_MASTER" value: "false" - image: "essearch/elasticsearch-k8s:1.7.6" + image: "fabric8/elasticsearch-k8s:1.7.6" name: "elasticsearch" ports: - containerPort: 9200 name: "http" - containerPort: 9300 - name: "transport" \ No newline at end of file + name: "transport" From 00424c8c6dfca1be8301361906e6c2205f7aadeb Mon Sep 17 00:00:00 2001 From: Emilien Brigand Date: Thu, 12 Jan 2017 13:03:37 +0000 Subject: [PATCH 13/16] Use the fabric8 docker id for an official release --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d1be52a..b4cb2f6 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ read by the fabric8 kubernetes client when the request is made to the API server # Kubernetes example -In this example, we're going to use a headless service to look up the Elasticsearch cluster nodes to join. +In this example, we're going to use a headle service to look up the Elasticsearch cluster nodes to join. The following manifest uses 3 replication controllers to created Elasticsearch pods in 3 different modes: @@ -242,7 +242,7 @@ items: value: "elasticsearch-cluster" - name: "NODE_MASTER" value: "false" - image: "essearch/elasticsearch-k8s:1.7.6" + image: "fabric8/elasticsearch-k8s:1.7.6" name: "elasticsearch" ports: - containerPort: 9300 @@ -280,7 +280,7 @@ items: value: "elasticsearch-cluster" - name: "NODE_DATA" value: "false" - image: "essearch/elasticsearch-k8s:1.7.6" + image: "fabric8/elasticsearch-k8s:1.7.6" name: "elasticsearch" ports: - containerPort: 9300 @@ -312,7 +312,7 @@ items: value: "false" - name: "NODE_MASTER" value: "false" - image: "essearch/elasticsearch-k8s:1.7.6" + image: "fabric8/elasticsearch-k8s:1.7.6" name: "elasticsearch" ports: - containerPort: 9200 From ba5075218121f074d888da6cbef9dda572476dab Mon Sep 17 00:00:00 2001 From: emil Date: Thu, 12 Jan 2017 16:43:56 +0000 Subject: [PATCH 14/16] Change the dockerfile to just be an import of the official ES image since what we had was a copy past of the official dockerfile and no need of an entrypoint, it will use the official one --- src/main/docker/Dockerfile | 78 +--------------------------- src/main/docker/docker-entrypoint.sh | 39 -------------- 2 files changed, 1 insertion(+), 116 deletions(-) delete mode 100644 src/main/docker/docker-entrypoint.sh diff --git a/src/main/docker/Dockerfile b/src/main/docker/Dockerfile index 027dd88..d343e28 100644 --- a/src/main/docker/Dockerfile +++ b/src/main/docker/Dockerfile @@ -1,77 +1 @@ -# -# Copyright (C) 2015 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -FROM java:8-jre - -# grab gosu for easy step-down from root -ENV GOSU_VERSION 1.7 -RUN set -x \ - && wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \ - && wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \ - && export GNUPGHOME="$(mktemp -d)" \ - && gpg --keyserver hkp://hkps.pool.sks-keyservers.net:80 --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \ - && gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \ - && rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \ - && chmod +x /usr/local/bin/gosu \ - && gosu nobody true - -# https://artifacts.elastic.co/GPG-KEY-elasticsearch -RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 46095ACC8548582C1A2699A9D27D666CD88E42B4 - -# https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-repositories.html -# https://www.elastic.co/guide/en/elasticsearch/reference/5.0/deb.html -RUN set -x \ - && apt-get update && apt-get install -y --no-install-recommends apt-transport-https && rm -rf /var/lib/apt/lists/* \ - && echo 'deb http://packages.elasticsearch.org/elasticsearch/1.7/debian stable main' > /etc/apt/sources.list.d/elasticsearch.list - -ENV ELASTICSEARCH_VERSION 1.7.6 -ENV ELASTICSEARCH_DEB_VERSION 1.7.6 - -RUN set -x \ - \ -# don't allow the package to install its sysctl file (causes the install to fail) -# Failed to write '262144' to '/proc/sys/vm/max_map_count': Read-only file system - && dpkg-divert --rename /usr/lib/sysctl.d/elasticsearch.conf \ - \ - && apt-get update \ - && apt-get install -y --no-install-recommends "elasticsearch=$ELASTICSEARCH_DEB_VERSION" \ - && rm -rf /var/lib/apt/lists/* - -ENV PATH /usr/share/elasticsearch/bin:$PATH - -WORKDIR /usr/share/elasticsearch - -RUN set -ex \ - && for path in \ - ./data \ - ./logs \ - ./config \ - ./config/scripts \ - ; do \ - mkdir -p "$path"; \ - chown -R elasticsearch:elasticsearch "$path"; \ - done - -COPY config ./config - -VOLUME /usr/share/elasticsearch/data - -COPY docker-entrypoint.sh / -RUN chmod a+x /docker-entrypoint.sh - -EXPOSE 9200 9300 -ENTRYPOINT ["/docker-entrypoint.sh"] -CMD ["elasticsearch"] +FROM elasticsearch:1.7.6 \ No newline at end of file diff --git a/src/main/docker/docker-entrypoint.sh b/src/main/docker/docker-entrypoint.sh deleted file mode 100644 index a6c7492..0000000 --- a/src/main/docker/docker-entrypoint.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2015 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -set -e - -# Add elasticsearch as command if needed -if [ "${1:0:1}" = '-' ]; then - set -- elasticsearch "$@" -fi - -# Drop root privileges if we are running elasticsearch -# allow the container to be started with `--user` -if [ "$1" = 'elasticsearch' -a "$(id -u)" = '0' ]; then - # Change the ownership of /usr/share/elasticsearch/data to elasticsearch - chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data - - set -- gosu elasticsearch "$@" - #exec gosu elasticsearch "$BASH_SOURCE" "$@" -fi - -# As argument is not related to elasticsearch, -# then assume that user wants to run his own process, -# for example a `bash` shell to explore this image -exec "$@" From da9b1a53963562c1a55d0a9c3669c2bd5ce03dc8 Mon Sep 17 00:00:00 2001 From: emil Date: Mon, 16 Jan 2017 17:47:19 +0000 Subject: [PATCH 15/16] Reflect file from version 1.3.0 --- NOTICE.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/NOTICE.txt b/NOTICE.txt index 8b13789..e69de29 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -1 +0,0 @@ - From a8f8ce348890a4be3f0377aad8bb5889a5b70246 Mon Sep 17 00:00:00 2001 From: emil Date: Thu, 9 Feb 2017 16:44:42 +0000 Subject: [PATCH 16/16] Open the access from outside of kubernetes for the load balancer service. --- kubernetes.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/kubernetes.yml b/kubernetes.yml index cb68484..4dc02fb 100644 --- a/kubernetes.yml +++ b/kubernetes.yml @@ -24,8 +24,6 @@ items: - name: transport port: 9300 protocol: TCP - loadBalancerSourceRanges: - - 10.0.0.0/8 - apiVersion: "v1" kind: "Service"