Commit 0a64995b authored by Paulo Pires's avatar Paulo Pires

Revamped Elasticsearch example that now uses an Alpine Linux container with JRE…

Revamped Elasticsearch example that now uses an Alpine Linux container with JRE 8u51 and Elasticsearch 1.7.1. Replaced Go discovery mechanism for Elasticsearch discovery plug-in that supports Kubernetes.
parent ae123630
FROM java:7-jre
RUN apt-get update && \
apt-get install -y curl && \
apt-get clean
RUN cd / && \
curl -O https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.5.2.tar.gz && \
tar xf elasticsearch-1.5.2.tar.gz && \
rm elasticsearch-1.5.2.tar.gz
COPY elasticsearch.yml /elasticsearch-1.5.2/config/elasticsearch.yml
COPY run.sh /
COPY elasticsearch_discovery /
EXPOSE 9200 9300
CMD ["/run.sh"]
\ No newline at end of file
.PHONY: elasticsearch_discovery build push all
TAG = 1.2
build: elasticsearch_discovery
docker build -t kubernetes/elasticsearch:$(TAG) .
push:
docker push kubernetes/elasticsearch:$(TAG)
elasticsearch_discovery:
go build elasticsearch_discovery.go
all: elasticsearch_discovery build push
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
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.
*/
package main
import (
"flag"
"fmt"
"strings"
"time"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
)
var (
namespace = flag.String("namespace", api.NamespaceDefault, "The namespace containing Elasticsearch pods")
selector = flag.String("selector", "", "Selector (label query) for selecting Elasticsearch pods")
)
func main() {
flag.Parse()
glog.Info("Elasticsearch discovery")
glog.Infof("Namespace: %q", *namespace)
glog.Infof("selector: %q", *selector)
c, err := client.NewInCluster()
if err != nil {
glog.Fatalf("Failed to make client: %v", err)
}
l, err := labels.Parse(*selector)
if err != nil {
glog.Fatalf("Failed to parse selector %q: %v", *selector, err)
}
pods, err := c.Pods(*namespace).List(l, fields.Everything())
if err != nil {
glog.Fatalf("Failed to list pods: %v", err)
}
glog.Infof("Elasticsearch pods in namespace %s with selector %q", *namespace, *selector)
podIPs := []string{}
for i := range pods.Items {
p := &pods.Items[i]
for attempt := 0; attempt < 10; attempt++ {
glog.Infof("%d: %s PodIP: %s", i, p.Name, p.Status.PodIP)
if p.Status.PodIP != "" {
podIPs = append(podIPs, fmt.Sprintf(`"%s"`, p.Status.PodIP))
break
}
time.Sleep(1 * time.Second)
p, err = c.Pods(*namespace).Get(p.Name)
if err != nil {
glog.Warningf("Failed to get pod %s: %v", p.Name, err)
}
}
if p.Status.PodIP == "" {
glog.Warningf("Failed to obtain PodIP for %s", p.Name)
}
}
fmt.Printf("discovery.zen.ping.unicast.hosts: [%s]\n", strings.Join(podIPs, ", "))
}
apiVersion: v1
kind: ReplicationController
metadata:
name: es
labels:
component: elasticsearch
spec:
replicas: 1
selector:
component: elasticsearch
template:
metadata:
labels:
component: elasticsearch
spec:
serviceAccount: elasticsearch
containers:
- name: es
securityContext:
capabilities:
add:
- IPC_LOCK
image: quay.io/pires/docker-elasticsearch-kubernetes:1.7.1-4
env:
- name: KUBERNETES_CA_CERTIFICATE_FILE
value: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: "CLUSTER_NAME"
value: "myesdb"
- name: "DISCOVERY_SERVICE"
value: "elasticsearch"
- name: NODE_MASTER
value: "true"
- name: NODE_DATA
value: "true"
- name: HTTP_ENABLE
value: "true"
ports:
- containerPort: 9200
name: http
protocol: TCP
- containerPort: 9300
name: transport
protocol: TCP
volumeMounts:
- mountPath: /data
name: storage
volumes:
- name: storage
source:
emptyDir: {}
apiVersion: v1
kind: Service
metadata:
name: elasticsearch
labels:
component: elasticsearch
spec:
type: LoadBalancer
selector:
component: elasticsearch
ports:
- name: http
port: 9200
protocol: TCP
- name: transport
port: 9300
protocol: TCP
apiVersion: v1
kind: ReplicationController
metadata:
labels:
name: music-db
namespace: mytunes
name: music-db
spec:
replicas: 4
selector:
name: music-db
template:
metadata:
labels:
name: music-db
spec:
containers:
- name: es
image: kubernetes/elasticsearch:1.2
env:
- name: "CLUSTER_NAME"
value: "mytunes-db"
- name: "SELECTOR"
value: "name=music-db"
- name: "NAMESPACE"
value: "mytunes"
ports:
- name: es
containerPort: 9200
- name: es-transport
containerPort: 9300
kind: Namespace
apiVersion: v1
metadata:
name: mytunes
labels:
name: mytunes
apiVersion: v1
kind: ReplicationController
metadata:
name: es-client
labels:
component: elasticsearch
role: client
spec:
replicas: 1
selector:
component: elasticsearch
role: client
template:
metadata:
labels:
component: elasticsearch
role: client
spec:
serviceAccount: elasticsearch
containers:
- name: es-client
securityContext:
capabilities:
add:
- IPC_LOCK
image: quay.io/pires/docker-elasticsearch-kubernetes:1.7.1-4
env:
- name: KUBERNETES_CA_CERTIFICATE_FILE
value: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: "CLUSTER_NAME"
value: "myesdb"
- name: NODE_MASTER
value: "false"
- name: NODE_DATA
value: "false"
- name: HTTP_ENABLE
value: "true"
ports:
- containerPort: 9200
name: http
protocol: TCP
- containerPort: 9300
name: transport
protocol: TCP
volumeMounts:
- mountPath: /data
name: storage
volumes:
- name: storage
source:
emptyDir: {}
apiVersion: v1
kind: ReplicationController
metadata:
name: es-data
labels:
component: elasticsearch
role: data
spec:
replicas: 1
selector:
component: elasticsearch
role: data
template:
metadata:
labels:
component: elasticsearch
role: data
spec:
serviceAccount: elasticsearch
containers:
- name: es-data
securityContext:
capabilities:
add:
- IPC_LOCK
image: quay.io/pires/docker-elasticsearch-kubernetes:1.7.1-4
env:
- name: KUBERNETES_CA_CERTIFICATE_FILE
value: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: "CLUSTER_NAME"
value: "myesdb"
- name: NODE_MASTER
value: "false"
- name: HTTP_ENABLE
value: "false"
ports:
- containerPort: 9300
name: transport
protocol: TCP
volumeMounts:
- mountPath: /data
name: storage
volumes:
- name: storage
source:
emptyDir: {}
apiVersion: v1
kind: Service
metadata:
name: elasticsearch-discovery
labels:
component: elasticsearch
role: master
spec:
selector:
component: elasticsearch
role: master
ports:
- name: transport
port: 9300
protocol: TCP
apiVersion: v1
kind: ReplicationController
metadata:
name: es-master
labels:
component: elasticsearch
role: master
spec:
replicas: 1
selector:
component: elasticsearch
role: master
template:
metadata:
labels:
component: elasticsearch
role: master
spec:
serviceAccount: elasticsearch
containers:
- name: es-master
securityContext:
capabilities:
add:
- IPC_LOCK
image: quay.io/pires/docker-elasticsearch-kubernetes:1.7.1-4
env:
- name: KUBERNETES_CA_CERTIFICATE_FILE
value: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: "CLUSTER_NAME"
value: "myesdb"
- name: NODE_MASTER
value: "true"
- name: NODE_DATA
value: "false"
- name: HTTP_ENABLE
value: "false"
ports:
- containerPort: 9300
name: transport
protocol: TCP
volumeMounts:
- mountPath: /data
name: storage
volumes:
- name: storage
source:
emptyDir: {}
apiVersion: v1
kind: Service
metadata:
name: music-server
namespace: mytunes
name: elasticsearch
labels:
name: music-db
component: elasticsearch
role: client
spec:
type: LoadBalancer
selector:
name: music-db
component: elasticsearch
role: client
ports:
- name: db
- name: http
port: 9200
targetPort: es
type: LoadBalancer
protocol: TCP
apiVersion: v1
kind: ServiceAccount
metadata:
name: elasticsearch
#!/bin/bash
# Copyright 2015 The Kubernetes Authors All rights reserved.
#
# 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.
export CLUSTER_NAME=${CLUSTER_NAME:-elasticsearch-default}
export NODE_MASTER=${NODE_MASTER:-true}
export NODE_DATA=${NODE_DATA:-true}
export MULTICAST=${MULTICAST:-false}
/elasticsearch_discovery --namespace="${NAMESPACE}" --selector="${SELECTOR}" >> /elasticsearch-1.5.2/config/elasticsearch.yml
export HTTP_PORT=${HTTP_PORT:-9200}
export TRANSPORT_PORT=${TRANSPORT_PORT:-9300}
/elasticsearch-1.5.2/bin/elasticsearch
apiVersion: v1
kind: ServiceAccount
metadata:
name: elasticsearch
......@@ -237,9 +237,9 @@ func TestExampleObjectSchemas(t *testing.T) {
"dapi-pod": &api.Pod{},
},
"../examples/elasticsearch": {
"mytunes-namespace": &api.Namespace{},
"music-rc": &api.ReplicationController{},
"music-service": &api.Service{},
"es-rc": &api.ReplicationController{},
"es-svc": &api.Service{},
"service-account": nil,
},
"../examples/explorer": {
"pod": &api.Pod{},
......
......@@ -63,10 +63,10 @@ docs/getting-started-guides/coreos/azure/lib/deployment_logic/kubernetes.js:var
docs/getting-started-guides/logging-elasticsearch.md: "cluster_name" : "kubernetes-logging",
docs/user-guide/accessing-the-cluster.md: "cluster_name" : "kubernetes_logging",
examples/cluster-dns/images/frontend/client.py: service_address = socket.gethostbyname(hostname)
examples/elasticsearch/README.md: "cluster_name" : "mytunes-db",
examples/elasticsearch/README.md: "cluster_name" : "mytunes-db",
examples/elasticsearch/README.md: "cluster_name" : "mytunes-db",
examples/elasticsearch/README.md:"cluster_name" : "mytunes-db",
examples/elasticsearch/README.md: "cluster_name" : "myesdb",
examples/elasticsearch/README.md: "cluster_name" : "myesdb",
examples/elasticsearch/production_cluster/README.md: "cluster_name" : "myesdb",
examples/elasticsearch/production_cluster/README.md: "cluster_name" : "myesdb",
hack/lib/logging.sh: local source_file=${BASH_SOURCE[$frame_no]}
hack/lib/logging.sh: local source_file=${BASH_SOURCE[$stack_skip]}
hack/local-up-cluster.sh: runtime_config="--runtime-config=\"${RUNTIME_CONFIG}\""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment