作業環境が必要なので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"