前提
New RelicのAWS Integration(API Polling方式)はnewrelic_cloud_aws_integrationsにeks ブロックが存在せず、EKSのノード/Pod/クラスタメトリクスが取得できない。これを補うため、New Relic 公式のKubernetes Integrationを利用する。
New Relic Kubernetes Integrationは通常DaemonSet(各ノードに1つエージェントを配置)で動く。しかし対象クラスターは EC2ノードグループを持たず、Fargateのみで構成されており、Fargateの仕組み上DaemonSetはスケジュールされない。
アーキテクチャ
newrelic-infra-operatorがMutatingWebhookConfigurationを通じて、対象PodにNew Relicの監視サイドカーコンテナを自動注入する方式が望ましい。
Pod作成イベント → MutatingWebhook → newrelic-infra-operator が判定 → 該当すればサイドカー注入
Fargateクラスター全体に対してWebhookが有効だと、global.fargate=true かつ、policies未指定の場合はクラスタ内の全Fargate Podが対象になってしまうため、namespaceSelectorで明示的にオプトインする方式が良い。
対応方法
Terraform
- newrelic_api_access_key リソースでIngest/LICENSEキーをTerraformから直接発行
- SSM Parameter Storeに格納
- newrelic namespace用のFargate Profileを新規追加
- External Secrets Operator用のIRSAロールを追加
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
resource "aws_iam_role" "newrelic_external_secrets" { name = "${local.prefix}-newrelic-external-secrets" assume_role_policy = jsonencode({ Statement = [{ Action = "sts:AssumeRoleWithWebIdentity" Principal = { Federated = aws_iam_openid_connect_provider.this.arn } Condition = { StringEquals = { "${replace(aws_iam_openid_connect_provider.this.url, "https://", "")}:sub" : "system:serviceaccount:newrelic:newrelic-external-secrets" } } }] }) } resource "aws_iam_policy" "newrelic_external_secrets" { policy = jsonencode({ Statement = [{ Effect = "Allow" Action = ["ssm:GetParameter", "ssm:GetParameters", "ssm:GetParametersByPath"] Resource = "arn:aws:ssm:ap-northeast-1:${data.aws_caller_identity.current.account_id}:parameter/hoge/${var.env}/newrelic/*" }] }) } |
Kubernetes(ArgoCD)
- SecretStore + ExternalSecret でSSMからLicense Keyをnewrelic namespaceに同期
- nri-bundle Helmチャートをnewrelic-infra-operator有効・Fargateモードで導入
・argocd_base.yaml
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: newrelic-secret-hoge namespace: argocd spec: project: default source: repoURL: hoge.git targetRevision: hoge path: cluster/hoge directory: recurse: false include: newrelic-secret.yaml destination: server: arn:aws:eks:ap-northeast-1:<account>:cluster/hoge-eks syncPolicy: automated: prune: true selfHeal: true syncOptions: - Prune=true - ApplyOutOfSyncOnly=true - ServerSideApply=true - CreateNamespace=true apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: newrelic-bundle-hoge namespace: argocd spec: sources: - repoURL: https://helm-charts.newrelic.com chart: nri-bundle targetRevision: "8.0.0" helm: valueFiles: - $values/cluster/hoge/newrelic-bundle.yaml - repoURL: hoge.git targetRevision: hoge ref: values destination: namespace: newrelic ~省略~ |
・newrelic-secret.yaml
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
apiVersion: v1 kind: ServiceAccount metadata: name: newrelic-external-secrets namespace: newrelic annotations: eks.amazonaws.com/role-arn: "arn:aws:iam::<account>:role/hoge-eks-newrelic-external-secrets" --- apiVersion: external-secrets.io/v1 kind: SecretStore metadata: name: aws-parameter-store namespace: newrelic spec: provider: aws: service: ParameterStore auth: jwt: serviceAccountRef: name: newrelic-external-secrets --- apiVersion: external-secrets.io/v1 kind: ExternalSecret metadata: name: newrelic-license-key namespace: newrelic spec: secretStoreRef: { name: aws-parameter-store, kind: SecretStore } target: { name: newrelic-license-key } data: - secretKey: licenseKey remoteRef: key: /hoge/newrelic/LICENSE_KEY |
・newrelic-bundle.yaml
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
global: fargate: true lowDataMode: true privileged: false customSecretName: newrelic-license-key customSecretLicenseKey: licenseKey newrelic-infra-operator: enabled: true config: infraAgentInjection: policies: - namespaceSelector: matchLabels: newrelic.com/scrape: "true" |
- 確認
|
1 2 3 |
newrelic-bundle-hoge-newrelic-infra-operator 1/1 Running newrelic-bundle-hoge-nri-kube-events 2/2 Running newrelic-bundle-hoge-nrk8s-ksm 2/2 Running |
Was this helpful?
0 / 0
1989年生まれのSRE 。ホスティングから大規模なアドテクなどのインフラエンジニアとして携わる。 現在はサービスの信頼性向上、DevOps、可用性、レイテンシ、パフォーマンス、モニタリング、オブザーバビリティ、 緊急対応、AWSでのインフラ構築、Docker開発環境の提供、IaC、新技術の検証、リファクタリング、セキュリティ強化を担当している。
個人事業主では数社サーバー保守とベンチャー企業のインフラコンサルティングを行うほか、TechBullを創業し、ジュニアエンジニアのコミュニティを運営している。さらに、エンジニア向けYouTubeメディア「TECH WORLD」ではSRE関連の動画に出演し、過去には脆弱性スキャナ「Vuls」のOSS活動にも貢献。 ガジェット系エンジニアYouTuberとしても発信。