5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Kubernetes APM auto-attach で APM がうまく動かない時に確認することの小ネタ

Last updated at Posted at 2025-03-05

New Relic には Kubernetes APM auto-attach という Kubernetes のオペレーターを使用して APM を自動的にアプリケーションが動く Pod にアタッチするという機能を提供しています。

本記事ではその auto-attach が期待通りに Pod に対して APM が期待通りに動作しない時、確認する小ネタを紹介したいと思います。

一般的なトラブルシューティングはドキュメントにあります。
https://docs.newrelic.com/docs/kubernetes-pixie/kubernetes-integration/installation/k8s-agent-operator/#troubleshooting

Secret の Key は new_relic_license_key を参照している

ドキュメントの手順で Secret を作成している箇所がありますがこの際にカスタムの Secret を任意で作成、参照できるような記述があります。

この Secret を作成する際に key が new_relic_license_key でないと正常に動作しないという注意点があります。記事執筆時点ではこのように固定値で指定されています。
https://github.com/newrelic/k8s-agents-operator/blob/main/internal/apm/helper.go#L240-L255

この点からカスタムで Secret を作成される際には上記の点に注意してもらえればと思います。
helm でインストールする際に secret の値などを同時にセットされている場合はこの問題には合うことはないので無視してもらって大丈夫な内容です。

Security Groups Per Pod との共存ができない

Security Groups Per Pod という Pod ごとに固有の Security Group を設定できるコンポーネントが EKS にはあります。例えば Node レベルでは複数のアプリケーションが動いておりとあるアプリケーションのみ RDS への接続を許可したい場合などに便利です。

AWS公式ドキュメントにある画像がわかりやすい例です。
image.png

詳しい設定は省略しますがこの設定をした場合に Pod の起動時に VPC CNI がブランチENIを 作成してその情報を metadata.annotation に書き込みます。

この動作自体は問題ないのですが実際にこの設定をしている環境下で auto-attach を導入すると Pod が起動できなくなる問題が発生します。

Warning  BranchENIAnnotationFailed  5s (x12 over 15s)  vpc-resource-controller  
failed to annotate pod with branch ENI details: Pod "<Pod名>" is invalid: spec: 
Forbidden: pod updates may not change fields other than 
`spec.containers[*].image`,`spec.initContainers[*].image`,
`spec.activeDeadlineSeconds`,`spec.tolerations` 
(only additions to existing tolerations),`spec.terminationGracePeriodSeconds` 
(allow it to be set to 1 if it was previously negative)

annotation への上書きを許容していない

これは Kubernetes における Pod の仕様に記載されていて spec.containers[*].image,spec.initContainers[*].image,
spec.activeDeadlineSeconds,spec.tolerations
(only additions to existing tolerations) これら以外のフィールドへの変更、追加などを許容しておらず今回 vpc-resource-controller、APM auto-attach 双方とも書き込みをするような挙動をしておりそれが原因となって Pod が正常に起動しない問題になってしまっています。

Pod updates may not change fields other than spec.containers[*].image,
spec.initContainers[*].image, spec.activeDeadlineSeconds or spec.tolerations. 
For spec.tolerations, you can only add new entries.

現状こちらに対しての有効なワークアラウンドの手段はなく通常の APM を導入する手段を採用する形になります。
今回は Security Group for Pod のケースで紹介しましたが同様の仕組みを使っているような Webhook 等がある場合は注意が必要になります。

おわりに

以上が私が遭遇したトラブルに対しての対処法になります。
参考になれば幸いです。

New Relic株式会社のQiita OrganizationOrganizationでは、
新機能を含む活用方法を公開していますので、ぜひフォローをお願いします。

無料のアカウントで試してみよう!

New Relic フリープランで始めるオブザーバビリティ!

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?