上記の記事を書いたが、NewRelicのKubernetes integration(nri-bundle)自体は既に導入済みで、Namespace単位・Deployment単位のGolden Metricsは普通に取れていたにもかかわらず、Pod/Container単位の詳細メトリクスだけが一切収集されていないことに気づいた。
原因
前提として、コスト・影響範囲を絞るためにnamespaceSelectorで明示的にオプトインしたnamespaceだけに限定する設計になっている。
EKS Fargate環境特有の制約で、DaemonSetという概念がない。(何回書いてるんや!?) そのためNewRelicはFargate向けに、対象PodへNewRelic Infrastructureのサイドカーコンテナが必要。
|
1 2 3 4 5 6 7 |
newrelic-infra-operator: config: infraAgentInjection: policies: - namespaceSelector: matchLabels: newrelic.com/scrape: "true" |
ブラスして肝心のnewrelic.com/scrape: “true”ラベルが、どのnamespaceにも付与されていなかった。nri-bundle自体の導入直後で、個別アプリのオプトインまで確認していなかった。これは盲点。
対応方法
|
1 2 3 4 5 6 7 8 9 10 11 |
# namespace.yaml metadata: labels: ... {{- if .Values.namespace.newrelicScrape }} newrelic.com/scrape: "true" {{- end }} # values/hoge namespace: newrelicScrape: true |
反映後にはkubectl rollout restart deploymentでローリング再起動が必要。
収集できるようになったデータ
- Pod状態: status(Running等), isReady
- リソース使用率: cpuCoresUtilization, memoryWorkingSetUtilization: restartCount, restartCountDelta
- ネットワーク: net.rxBytesPerSecond, net.txBytesPerSecond- Pod状態: status(Running等), isReady
Failed to watchが出る場合
|
1 2 3 |
"Failed to watch" err="nodes is forbidden: User \"system:serviceaccount:api-hoge:api-hoge-app\" cannot watch resource \"nodes\" in API group \"\" at the cluster scope" logger="UnhandledError" reflector="pkg/mod/k8s.io/client-go@v0.36.2/tools/cache/reflector.go:343" type="*v1.Node" |
これで終わりじゃないということに注意してほしい。 このサイドカーは注入先Podの既存ServiceAccountで動作するため、権限がそのままエージェントの権限になる。ここが罠で、operatorが自動生成するClusterRoleは以下の通りget・listのみでwatchが含まれていない。なので上記デプロイ後にエラーが出る想定。
方法としはServiceAccountにwatch権限だけを追加で付与するClusterRole/ClusterRoleBindingを作成した。KubernetesのRBACは複数のBindingが単純に足し算(union)される仕組みなので、operator管理の既存Bindingとは競合しない。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: newrelic-infra-agent-watch rules: # nodes/metrics, nodes/stats, nodes/proxyはlist/watch不可能な単一プロキシ # エンドポイントのため対象外(watchを付与しても意味を持たない) - apiGroups: [""] resources: ["nodes", "pods", "services", "namespaces"] verbs: ["watch"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: newrelic-infra-agent-watch roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: newrelic-infra-agent-watch subjects: - kind: Group apiGroup: rbac.authorization.k8s.io name: system:serviceaccounts |
Was this helpful?
1 / 0
1989年生まれのSRE 。ホスティングから大規模なアドテクなどのインフラエンジニアとして携わる。 現在はサービスの信頼性向上、DevOps、可用性、レイテンシ、パフォーマンス、モニタリング、オブザーバビリティ、 緊急対応、AWSでのインフラ構築、Docker開発環境の提供、IaC、新技術の検証、リファクタリング、セキュリティ強化を担当している。
個人事業主では数社サーバー保守とベンチャー企業のインフラコンサルティングを行うほか、TechBullを創業し、ジュニアエンジニアのコミュニティを運営している。さらに、エンジニア向けYouTubeメディア「TECH WORLD」ではSRE関連の動画に出演し、過去には脆弱性スキャナ「Vuls」のOSS活動にも貢献。 ガジェット系エンジニアYouTuberとしても発信。