Home Explore Blog CI



kubernetes

7th chunk of `content/en/blog/_posts/2015-06-00-Cluster-Level-Logging-With-Kubernetes.md`
edb12f87e5fff214317bf049b38548f515c4815c3da3b1980000000100000853
To help explain how cluster level logging works let’s start off with a synthetic log generator pod specification [counter-pod.yaml](https://github.com/GoogleCloudPlatform/kubernetes/blob/master/examples/blog-logging/counter-pod.yaml):



```
  apiVersion : v1  
  kind : Pod  
  metadata :  
    name : counter  
  spec :  
    containers :  
   - name : count  
      image : ubuntu:14.04  
      args : [bash, -c,   
            'for ((i = 0; ; i++)); do echo "$i: $(date)"; sleep 1; done']  
```


This pod specification has one container which runs a bash script when the container is born. This script simply writes out the value of a counter and the date once per second and runs indefinitely. Let’s create the pod.

```

$ kubectl create -f counter-pod.yaml


pods/counter

```
We can observe the running pod:
```
$ kubectl get pods
```
```
NAME                                           READY     REASON    RESTARTS   AGE

counter                                        1/1       Running   0          5m

fluentd-cloud-logging-kubernetes-minion-0f64   1/1       Running   0          55m

fluentd-cloud-logging-kubernetes-minion-27gf   1/1       Running   0          55m

fluentd-cloud-logging-kubernetes-minion-pk22   1/1       Running   0          55m

fluentd-cloud-logging-kubernetes-minion-20ej   1/1       Running   0          55m

kube-dns-v3-pk22                               3/3       Running   0          55m

monitoring-heapster-v1-20ej                    0/1       Running   9          56m
```


This step may take a few minutes to download the ubuntu:14.04 image during which the pod status will be shown as Pending.


One of the nodes is now running the counter pod:


[![](https://4.bp.blogspot.com/-BI3zOVlrHwA/Vxf0KwcqtCI/AAAAAAAAAbw/vzv8X8vQrso9Iycx4qQHuOslE8So7smLgCLcB/s400/27gf-counter.png)](https://4.bp.blogspot.com/-BI3zOVlrHwA/Vxf0KwcqtCI/AAAAAAAAAbw/vzv8X8vQrso9Iycx4qQHuOslE8So7smLgCLcB/s1600/27gf-counter.png)




When the pod status changes to Running we can use the kubectl logs command to view the output of this counter pod.

```
$ kubectl logs counter

0: Tue Jun  2 21:37:31 UTC 2015


Title: Creating and Observing a Sample Counter Pod in Kubernetes
Summary
This passage details the process of creating a simple 'counter' pod in Kubernetes using a YAML specification. The pod runs a bash script that outputs an incrementing counter and the current date. The example demonstrates how to create the pod using 'kubectl create', observe its status with 'kubectl get pods', and view its logs using 'kubectl logs'.