Search

AWS X-Ray

ENV

EKS_CLUSTER_NAME="<CLUSTER_NAME>" CLUSTER_OIDC=$(aws eks describe-cluster --name $EKS_CLUSTER_NAME --query "cluster.identity.oidc.issuer" --output text | cut -c 9-100) AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --output text)
Shell
복사

IRSA (Create the service account for X-Ray)

eksctl create iamserviceaccount \ --name xray-daemon \ --namespace default \ --cluster $EKS_CLUSTER_NAME \ --attach-policy-arn arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess \ --override-existing-serviceaccounts \ --approve
Shell
복사

Apply a label to the service account

kubectl label serviceaccount xray-daemon app=xray-daemon
Shell
복사

X-Ray DaemonSet

# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. # A copy of the License is located at # # http://www.apache.org/licenses/LICENSE-2.0 # # or in the "license" file accompanying this file. This file is distributed # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either # express or implied. See the License for the specific language governing # permissions and limitations under the License. apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: xray-daemon labels: app: xray-daemon roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: xray-daemon namespace: default --- apiVersion: apps/v1 kind: DaemonSet metadata: name: xray-daemon spec: updateStrategy: type: RollingUpdate selector: matchLabels: app: xray-daemon template: metadata: labels: app: xray-daemon spec: volumes: - name: config-volume configMap: name: xray-config hostNetwork: true serviceAccountName: xray-daemon containers: - name: xray-daemon image: amazon/aws-xray-daemon imagePullPolicy: Always command: ["/usr/bin/xray", "-c", "/aws/xray/config.yaml"] resources: limits: memory: 24Mi ports: - name: xray-ingest containerPort: 2000 hostPort: 2000 protocol: UDP volumeMounts: - name: config-volume mountPath: /aws/xray readOnly: true --- # Configuration for AWS X-Ray daemon apiVersion: v1 kind: ConfigMap metadata: name: xray-config data: config.yaml: |- # Maximum buffer size in MB (minimum 3). Choose 0 to use 1% of host memory. TotalBufferSizeMB: 0 # Maximum number of concurrent calls to AWS X-Ray to upload segment documents. Concurrency: 8 # Send segments to AWS X-Ray service in a specific region Region: "" # Change the X-Ray service endpoint to which the daemon sends segment documents. Endpoint: "" Socket: # Change the address and port on which the daemon listens for UDP packets containing segment documents. # Make sure we listen on all IP's by default for the k8s setup UDPAddress: 0.0.0.0:2000 Logging: LogRotation: true # Change the log level, from most verbose to least: dev, debug, info, warn, error, prod (default). LogLevel: prod # Output logs to the specified file path. LogPath: "" # Turn on local mode to skip EC2 instance metadata check. LocalMode: false # Amazon Resource Name (ARN) of the AWS resource running the daemon. ResourceARN: "" # Assume an IAM role to upload segments to a different account. RoleARN: "" # Disable TLS certificate verification. NoVerifySSL: false # Upload segments to AWS X-Ray through a proxy. ProxyAddress: "" # Daemon configuration file format version. Version: 1 --- # k8s service definition for AWS X-Ray daemon headless service apiVersion: v1 kind: Service metadata: name: xray-service spec: selector: app: xray-daemon clusterIP: None ports: - name: incoming port: 2000 protocol: UDP
Shell
복사
kubectl apply -f xray-k8s-daemonset.yaml kubectl describe daemonset xray-daemon kubectl logs -l app=xray-daemon
Shell
복사

X-Ray Sample App Deploy

# frontend kubectl apply -f https://eksworkshop.com/intermediate/245_x-ray/sample-front.files/x-ray-sample-front-k8s.yml # backend kubectl apply -f https://eksworkshop.com/intermediate/245_x-ray/sample-back.files/x-ray-sample-back-k8s.yml
Shell
복사
kubectl describe deployments x-ray-sample-front-k8s x-ray-sample-back-k8s kubectl describe services x-ray-sample-front-k8s x-ray-sample-back-k8s kubectl get service x-ray-sample-front-k8s -o wide
Shell
복사

Delete

kubectl delete deployments x-ray-sample-front-k8s x-ray-sample-back-k8s kubectl delete services x-ray-sample-front-k8s x-ray-sample-back-k8s kubectl delete -f xray-k8s-daemonset.yaml eksctl delete iamserviceaccount --name xray-daemon --cluster $EKS_CLUSTER_NAME
Shell
복사