<p>I would like to know which steps I have to follow in order to send the logs created in my custom apache container (deployed in a pod with Kubernetes) to the Stackdriver collector.</p>

<p>I have noticed that if I create a pod with a standard apache (or nginx) container, access.log and error.log are sent automatically to Stackdriver.</p>

<p>In fact I'm able to see the log both on Kubernetes dashboard and on Google Cloud Dashboard--->Logging--->Logs
Instead I don't see anything related my custom apache...</p>

<p>Any suggestions?</p>

<p>After some researches I have resolved the problem of log forwarder from my custom apache container.</p>

<p>I don't know why the "standard redirection" (using /dev/stdout or /proc/self/fd/1) is not working anyway the solution that I followed is called "sidecar container with the logging agent"</p>

<p>1) create a configMag file where you'll set a fluentd configuration:</p>

<pre><code>apiVersion: v1
data:
  fluentd.conf: |
    &lt;source&gt;
      type tail
      format none
      path /var/log/access.log
      pos_file /var/log/access.log.pos
      tag count.format1
    &lt;/source&gt;

    &lt;source&gt;
      type tail
      format none
      path /var/log/error.log
      pos_file /var/log/error.log.pos
      tag count.format2
    &lt;/source&gt;

    &lt;match **&gt;
      type google_cloud
    &lt;/match&gt;
kind: ConfigMap
metadata:
  name: my-fluentd-config
</code></pre>

<p>2) create a pod with 2 containers: the custom apache + a log agent. Both containers will mount a log folder. Only log agent will mount the fluentd config:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: my-sidecar
  labels:
    app: my-sidecar 
spec:
  volumes:
  - name: varlog
    emptyDir: {}
  - name: config-volume
    configMap:
      name: my-fluentd-config 

  containers:
  - name: my-apache
    image: &lt;your_custom_image_repository&gt;
    ports:
      - containerPort: 80
        name: http
        protocol: TCP 
    volumeMounts:
    - name: varlog
      mountPath: /var/log

  - name: log-agent
    image: gcr.io/google_containers/fluentd-gcp:1.30
    env:
    - name: FLUENTD_ARGS
      value: -c /etc/fluentd-config/fluentd.conf
    volumeMounts:
    - name: varlog
      mountPath: /var/log
    - name: config-volume
      mountPath: /etc/fluentd-config
</code></pre>

<p>3) Enter in my-apache container with: </p>

<pre><code>kubectl exec -it my-sidecar --container my-apache -- /bin/bash
</code></pre>

<p>and change/check the httpd.conf is using the following files:</p>

<pre><code>ErrorLog /var/log/error.log

CustomLog /var/log/access.log common
</code></pre>

<p>(if you change something remember to restart apache..)</p>

<p>4) Now in Google Cloud Console -> Logging you'll be able to see the apache access/error logs in Stackdriver with a filter like:</p>

<pre><code>resource.type="container"
labels."compute.googleapis.com/resource_name"="my-sidecar"
</code></pre>
