148422597X Kubernetes Management Design Patterns [Vohra 2017-01-29] {E559F6BB}

marco.cirilli
from marco.cirilli More from this publisher
19.06.2021 Views

Chapter 14 ■ Configuring LoggingStarting Elastic SearchIn this section we shall create a replication controller and service for Elasticsearch using the Docker imagegcr.io/google_containers/elasticsearch:1.9. Create an RC definition file es-controller.yaml andcopy the following listing into it.---apiVersion: v1kind: ReplicationControllermetadata:labels:k8s-app: elasticsearch-loggingkubernetes.io/cluster-service: "true"version: v1name: elasticsearch-logging-v1namespace: kube-systemspec:replicas: 2selector:k8s-app: elasticsearch-loggingversion: v1template:metadata:labels:k8s-app: elasticsearch-loggingkubernetes.io/cluster-service: "true"version: v1spec:containers:-image: "gcr.io/google_containers/elasticsearch:1.9"name: elasticsearch-loggingports:-containerPort: 9200name: dbprotocol: TCP-containerPort: 9300name: transportprotocol: TCPresources:limits:cpu: "0.1"requests:cpu: "0.1"volumeMounts:-mountPath: /dataname: es-persistent-storage318

Chapter 14 ■ Configuring Loggingvolumes:-emptyDir: {}name: es-persistent-storageCreate an RC using the definition file:./kubectl create -f es-controller.yamlCreate a service definition file es-service.yaml for the Elasticsearch RC. Expose the service at port9200. The selector labels should match labels in the pod.---apiVersion: v1kind: Servicemetadata:labels:k8s-app: elasticsearch-loggingkubernetes.io/cluster-service: "true"kubernetes.io/name: Elasticsearchname: elasticsearch-loggingnamespace: kube-systemspec:ports:-port: 9200protocol: TCPtargetPort: dbselector:k8s-app: elasticsearch-loggingCreate a service from the definition file:./kubectl create -f es-service.yamlThe RC, pods, and service for Elasticsearch are created in the kube-system namespace and may belisted and described as shown in Figure 14-15.319

Chapter 14 ■ Configuring Logging

Starting Elastic Search

In this section we shall create a replication controller and service for Elasticsearch using the Docker image

gcr.io/google_containers/elasticsearch:1.9. Create an RC definition file es-controller.yaml and

copy the following listing into it.

---

apiVersion: v1

kind: ReplicationController

metadata:

labels:

k8s-app: elasticsearch-logging

kubernetes.io/cluster-service: "true"

version: v1

name: elasticsearch-logging-v1

namespace: kube-system

spec:

replicas: 2

selector:

k8s-app: elasticsearch-logging

version: v1

template:

metadata:

labels:

k8s-app: elasticsearch-logging

kubernetes.io/cluster-service: "true"

version: v1

spec:

containers:

-

image: "gcr.io/google_containers/elasticsearch:1.9"

name: elasticsearch-logging

ports:

-

containerPort: 9200

name: db

protocol: TCP

-

containerPort: 9300

name: transport

protocol: TCP

resources:

limits:

cpu: "0.1"

requests:

cpu: "0.1"

volumeMounts:

-

mountPath: /data

name: es-persistent-storage

318

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!