2
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?

LocalStackで作成したS3 BucketにVectorでログを送る

Last updated at Posted at 2025-07-23

はじめに

LocalStackで作成したS3 BucketにVectorでログを送ってみます。
今回はkindでKubernetesクラスタにLocalStackとVectorをデプロイします。

Vectorとは

Rustで書かれたログやメトリクスを収集、変換、転送するためのツールです。
詳しくは以下のサイトをご覧ください。
https://vector.dev/

環境情報

Component Version
PC M1 MacBook Pro
OS macOS 15.5
Docker Desktop 4.43.2
kind v0.29.0
Kubernetes v1.33.1
LocalStack 4.6.1
Vector 0.48.0

kindでKubernetesクラスタを作成

kindでKubernetesクラスタを作成します。

kind-sandbox.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: sandbox
nodes:
- role: control-plane
- role: worker
kind create cluster --config kind-sandbox.yaml

LocalStackをデプロイ

LocalStackをhelm chartからデプロイします。

helm install localstack localstack/localstack --namespace localstack --create-namespace

LocalStackのpodがRunningになったら、localstackのServiceをport-forwardします。

k -n localstack port-forward svc/localstack 4566:4566

--endpoint-urlを指定し、aws s3 lsコマンドが実行できることを確認します。

aws s3 ls --endpoint-url http://localhost:4566

Vectorのログを格納するs3 bucketを作成

vector-log-bucketというS3 Bucketを作成し、aws s3 lsで作成できたことを確認します。

aws s3 mb s3://vector-log-bucket --endpoint-url http://localhost:4566
aws s3 ls --endpoint-url http://localhost:4566

vector namespaceから疎通確認

念の為、vector namespaceを作成し、ClusterIP経由でアクセスできるか確認します。

まずは、vector namespaceを作成し、awsコマンドを含むpodをデプロイします。

vector_aws-cli.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: vector
---
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: aws-cli
  name: aws-cli
  namespace: vector
spec:
  containers:
  - image: amazon/aws-cli
    name: aws-cli
    command: [ "/bin/bash", "-c", "--" ]
    args: [ "while true; do sleep 60; done;" ]
  restartPolicy: OnFailure
k apply -f vector_aws-cli.yaml

aws-cliのpodのシェルにログインします。

k -n vector exec aws-cli -it -- /bin/bash 

--endpoint-urlにFQDNを指定して、aws s3 lsコマンドが実行できることを確認します。

export AWS_ACCESS_KEY_ID="test"
export AWS_SECRET_ACCESS_KEY="test"
export AWS_DEFAULT_REGION="us-east-1"
aws s3 ls --endpoint-url http://localstack.localstack.svc.cluster.local:4566

ここで指定するFQDNは後のvectorの設定に使用します。

Vectorをデプロイ

Vectorをhelm chartからデプロイします。
ここではAgentモードで起動し、kubernetes_logsをs3 bucketに送る設定をしています。

values.yaml
role: "Agent"
service:
  ports:
    - name: prom-exporter
      port: 9090
      protocol: TCP
customConfig:
  data_dir: /vector-data-dir
  sources:
    kubernetes_logs:
      type: kubernetes_logs
  sinks:
    s3_logs:
      type: aws_s3
      inputs: [kubernetes_logs]
      bucket: vector-log-bucket
      key_prefix: "logs/date=%F/"
      compression: gzip
      encoding:
        codec: json
      auth:
        access_key_id: "test"
        secret_access_key: "test"
      region: "us-east-1"
      endpoint:  http://localstack.localstack.svc.cluster.local:4566
helm -n vector install vector vector/vector -f values.yaml

VectorをAgentモードで起動するとDaemonSetとして起動するため、正常に起動しているか確認します。

k -n vector get ds

s3 bucketへのログ格納を確認

aws-cliのpodから以下のコマンドを実行し、ログが格納されていることを確認できます。

aws s3 ls s3://vector-log-bucket --endpoint-url http://localstack.localstack.svc.cluster.local:4566 --recursive

最後に

Vectorを利用してLocalStackで作成したS3 Bucketにログを送ることができました。

参考情報

2
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
2
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?