基本的な考え方は、ローカルで実行されている fluentd エージェントと同様に、構造化されたログを TCP 経由で受信して Cloud Logging に転送する別のポッドを開始することです。私が使用した手順については、以下を参照してください。
(残念ながら、Docker と Kubernetes に組み込まれているロギング サポートは使用できません。stdout/stderr から個々のテキスト行を個別のログ エントリとして転送するだけで、Error Reporting が完全なスタック トレースを確認できなくなります。)
Dockerfile
次のようにを使用して、fluentd フォワーダーの Docker イメージを作成します。
FROM gcr.io/google_containers/fluentd-gcp:1.18
COPY fluentd-forwarder.conf /etc/google-fluentd/google-fluentd.conf
次fluentd-forwarder.conf
のものが含まれます。
<source>
type forward
port 24224
</source>
<match **>
type google_cloud
buffer_chunk_limit 2M
buffer_queue_limit 24
flush_interval 5s
max_retry_wait 30
disable_retry_limit
</match>
次に、イメージをビルドしてプッシュします。
$ docker build -t gcr.io/###your project id###/fluentd-forwarder:v1 .
$ gcloud docker push gcr.io/###your project id###/fluentd-forwarder:v1
fluentd-forwarder-controller.yaml
レプリケーション コントローラ ( )が必要です。
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
fluentd-forwarder-service.yaml
サービス ( )も必要です。
apiVersion: v1
kind: Service
metadata:
name: fluentd-forwarder
spec:
selector:
app: fluentd-forwarder
ports:
- protocol: TCP
port: 24224
次に、レプリケーション コントローラーとサービスを作成します。
$ kubectl create -f fluentd-forwarder-controller.yaml
$ kubectl create -f fluentd-forwarder-service.yaml
最後に、アプリケーションで、 https: //cloud.google.com/error-reporting/docs/setting-up-on-compute-engine で説明されているように、「localhost」と 24224 を使用して fluentd エージェントに接続する代わりに、次を使用します。環境変数の値FLUENTD_FORWARDER_SERVICE_HOST
とFLUENTD_FORWARDER_SERVICE_PORT
.