Aws

Fluentbit Sidecar

wngnl05 2024. 12. 27. 15:12

NameSpace

kubectl create ns fluentd

Apply CloudWatch-Namespace

kubectl apply -f https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/cloudwatch-namespace.yaml
CLUSTER_NAME=<클러스터 이름>
REGION=<리전>
FluentBitHttpPort='2020'
FluentBitReadFromHead='Off'
[[ ${FluentBitReadFromHead} = 'On' ]] && FluentBitReadFromTail='Off'|| FluentBitReadFromTail='On'
[[ -z ${FluentBitHttpPort} ]] && FluentBitHttpServer='Off' || FluentBitHttpServer='On'
kubectl create configmap fluent-bit-cluster-info --from-literal=cluster.name=${CLUSTER_NAME} --from-literal=http.server=${FluentBitHttpServer} --from-literal=http.port=${FluentBitHttpPort} --from-literal=read.head=${FluentBitReadFromHead} --from-literal=read.tail=${FluentBitReadFromTail} --from-literal=logs.region=${REGION} -n amazon-cloudwatch

Create IAM Service Account

eksctl create iamserviceaccount --name fluentd --region $REGION --cluster $CLUSTER_NAME --namespace fluentd --attach-policy-arn arn:aws:iam::aws:policy/CloudWatchFullAccess --override-existing-serviceaccounts --approve

Create Config MAP

kubectl create configmap cluster-info --from-literal=cluster.name=$CLUSTER_NAME --from-literal=logs.region=$REGION -n fluentd

Create Namespace

cat <<\EOF> fluentd-ns.yaml
kind: Namespace
apiVersion: v1
metadata:
  name: fluentd
  labels:
    aws-observability: enabled
EOF
kubectl apply -f fluentd-ns.yaml

Down File & Apply

wget https://raw.githubusercontent.com/wngnl-dev/AWS/main/EKS/SideCar/fluentd.yaml
wget https://raw.githubusercontent.com/wngnl-dev/AWS/main/EKS/SideCar/service.yaml
wget https://raw.githubusercontent.com/wngnl-dev/AWS/main/EKS/SideCar/service-cm.yaml
wget https://raw.githubusercontent.com/wngnl-dev/AWS/main/EKS/SideCar/deployment.yaml
kubectl apply -f fluentd.yaml
kubectl apply -f service.yaml

서비스를 확인하고 "CLUSTER-IP"를 복사해서 service-cm.yaml에 넣어주세요.

kubectl get svc -n fluentd

deployment에 ECR URL을 추가하고

kubectl apply -f deployment.yaml
kubectl apply -f service-cm.yaml

Container 에 Curl 요청

date
kubectl exec -it -n app deployment.apps/service-a -- curl localhost:8080 > /dev/null 2>&1
kubectl exec -it -n app deployment.apps/service-b -- curl localhost:8080 > /dev/null 2>&1
kubectl exec -it -n app deployment.apps/service-c -- curl localhost:8080 > /dev/null 2>&1