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

volumes:

-

emptyDir: {}

name: es-persistent-storage

Create an RC using the definition file:

./kubectl create -f es-controller.yaml

Create a service definition file es-service.yaml for the Elasticsearch RC. Expose the service at port

9200. The selector labels should match labels in the pod.

---

apiVersion: v1

kind: Service

metadata:

labels:

k8s-app: elasticsearch-logging

kubernetes.io/cluster-service: "true"

kubernetes.io/name: Elasticsearch

name: elasticsearch-logging

namespace: kube-system

spec:

ports:

-

port: 9200

protocol: TCP

targetPort: db

selector:

k8s-app: elasticsearch-logging

Create a service from the definition file:

./kubectl create -f es-service.yaml

The RC, pods, and service for Elasticsearch are created in the kube-system namespace and may be

listed and described as shown in Figure 14-15.

319

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

Saved successfully!

Ooh no, something went wrong!