<p>I'm a bit confused at how to setup error reporting in kubernetes, so errors are visible in Google Cloud Console / Stackdriver "Error Reporting"?</p>

<p>According to documentation
<a href="https://cloud.google.com/error-reporting/docs/setting-up-on-compute-engine" rel="noreferrer">https://cloud.google.com/error-reporting/docs/setting-up-on-compute-engine</a>
we need to enable fluentd' "forward input plugin" and then send exception data from our apps.  I think this approach would have worked if we had setup fluentd ourselves, but it's already pre-installed on every node in a pod that just runs  gcr.io/google_containers/fluentd-gcp docker image.</p>

<p>How do we enable forward input on those pods and make sure that http port available to every pod on the nodes? We also need to make sure this config is used by default when we add more nodes to our cluster.</p>

<p>Any help would be appreciated, may be I'm looking at all this from a wrong point?</p>

<p>The basic idea is to start a separate pod that receives structured logs over TCP and forwards it to Cloud Logging, similar to a locally-running fluentd agent. See below for the steps I used.</p>

<p>(Unfortunately, the logging support that is built into Docker and Kubernetes cannot be used - it just forwards individual lines of text from stdout/stderr as separate log entries which prevents Error Reporting from seeing complete stack traces.)</p>

<p>Create a docker image for a fluentd forwarder using a <code>Dockerfile</code> as follows:</p>

<pre><code>FROM gcr.io/google_containers/fluentd-gcp:1.18

COPY fluentd-forwarder.conf /etc/google-fluentd/google-fluentd.conf
</code></pre>

<p>Where <code>fluentd-forwarder.conf</code> contains the following:</p>

<pre><code>&lt;source&gt;
  type forward
  port 24224
&lt;/source&gt;

&lt;match **&gt;
  type google_cloud
  buffer_chunk_limit 2M
  buffer_queue_limit 24
  flush_interval 5s
  max_retry_wait 30
  disable_retry_limit
&lt;/match&gt;
</code></pre>

<p>Then build and push the image:</p>

<pre><code>$ docker build -t gcr.io/###your project id###/fluentd-forwarder:v1 .
$ gcloud docker push gcr.io/###your project id###/fluentd-forwarder:v1
</code></pre>

<p>You need a replication controller (<code>fluentd-forwarder-controller.yaml</code>):</p>

<pre><code>apiVersion: v1
kind: ReplicationController
metadata:
  name: fluentd-forwarder
spec:
  replicas: 1
  template:
    metadata:
      name: fluentd-forwarder
      labels:
        app: fluentd-forwarder
    spec:
      containers:
      - name: fluentd-forwarder
        image: gcr.io/###your project id###/fluentd-forwarder:v1
        env:
        - name: FLUENTD_ARGS
          value: -qq
        ports:
        - containerPort: 24224
</code></pre>

<p>You also need a service (<code>fluentd-forwarder-service.yaml</code>):</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: fluentd-forwarder
spec:
  selector:
    app: fluentd-forwarder
  ports:
  - protocol: TCP
    port: 24224
</code></pre>

<p>Then create the replication controller and service:</p>

<pre><code>$ kubectl create -f fluentd-forwarder-controller.yaml
$ kubectl create -f fluentd-forwarder-service.yaml
</code></pre>

<p>Finally, in your application, instead of using 'localhost' and 24224 to connect to the fluentd agent as described on <a href="https://cloud.google.com/error-reporting/docs/setting-up-on-compute-engine">https://cloud.google.com/error-reporting/docs/setting-up-on-compute-engine</a>, use the values of evironment variables <code>FLUENTD_FORWARDER_SERVICE_HOST</code> and <code>FLUENTD_FORWARDER_SERVICE_PORT</code>.</p>
