19.06.2021 Views

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 14 ■ Configuring Logging

• Starting a replication controller

• Starting Fluentd and Elasticsearch to collect logs

• Starting Kibana

Setting the Environment

Create a Kubernetes cluster using a CoreOS-based AWS CloudFormation. List the nodes with kubectl get

nodes. The controller and worker nodes should be listed; we have used a single-controller, three-worker

node cluster as shown in Figure 14-3.

Figure 14-3. Listing Kubernetes nodes

Getting the Logs Generated by Default Logger

The logs generated by a running pod may be obtained with the kubectl logs <POD> command. If a pod has

more than one container, the logs for a particular container may be obtained with the command kubectl

logs <POD> <container>. Kubernetes performs log rotation, and only the latest logs are available to kubectl logs.

First, create a sample pod from which to get the logs. Use the following listing to create a pod definition

file counter-pod.yaml; the pod generates a message using a counter.

---

apiVersion: v1

kind: Pod

metadata:

name: counter

spec:

containers:

-

args:

- bash

- "-c"

- "for ((i = 0; ; i++)); do echo \"$i: $(date)\"; sleep 1; done"

image: "ubuntu:14.04"

name: count

The pod definition file is shown in the vi editor in Figure 14-4.

311

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

Saved successfully!

Ooh no, something went wrong!