0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

fluent-bitを使ってログをLog Analyticsに転送する サイドカー編

Posted at

作業環境が必要なのでAKSのクラスタを作ります。

az aks create \
    --resource-group $RESOURCE_GROUP \
    --name $CLUSTER_NAME \
    --node-count 2 \
    --generate-ssh-keys \
    --node-vm-size Standard_B2s \
    --network-plugin azure

クラスタができたら、kubectlを使えるようにします。

az aks get-credentials --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP

ワークスペースIDとワークスペースKeyを指定して以下のYAMLをデプロイします。

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.21.3-perl
        ports:
        - containerPort: 80
        volumeMounts:
        - name: log-volume
          mountPath: /var/log/nginx
      - name: fluentdbit
        image: fluent/fluent-bit:1.5-debug
        command: ["/fluent-bit/bin/fluent-bit",  "-i", "tail", "-p", 'path=/var/log/nginx/*.log', "-o", "azure", "-p", "customer_id=ワークスペースID", "-p", 'shared_key=ワークスペースのID', "-m", '*' ,"-f", "1"]
        volumeMounts:
        - name: log-volume
          mountPath: /var/log/nginx
      volumes:
        - name: log-volume
          emptyDir: {}

curlを2, 3回たたいて10分ほど待つと、反映されると思います。

kubectl exec -it nginx-deployment-676dfb48c7-6x888 -c nginx -- curl "http://localhost"

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?