Kubernetes環境でのNew Relic Infrastructure Agent導入
はじめに
Kubernetes環境でのインフラ監視は、ノードレベルの監視とクラスター全体の可視性を同時に実現する必要があります。New Relic Infrastructure Agentは、Helm ChartやDaemonSetを使用してKubernetesクラスターに効率的に導入でき、ノード、Pod、サービスの包括的な監視を提供します。
この記事では、Helm Chartを使用した標準的な導入から、カスタムDaemonSet設定、マルチクラスター環境での運用まで、実践的な導入手順を詳しく解説します。また、Kubernetes特有の監視要件とパフォーマンス最適化についても併せて説明します。
Kubernetes監視の基本概念
Infrastructure AgentのKubernetes対応
KubernetesでのInfrastructure Agentは、DaemonSetとして展開されることで、各ワーカーノードに1つずつPodが配置されます。すべてのノードの詳細な監視が可能です。
監視対象の範囲
Kubernetes環境でのInfrastructure Agentは、以下の情報を収集します。
ノードレベル情報
- ワーカーノードのCPU、メモリ、ディスク使用量
- ノードの健全性とリソース可用性
- kubeletのメトリクス
クラスターレベル情報
- Pod、Deployment、Serviceの状態
- コンテナのリソース消費量
- ネットワークポリシーとトラフィック
Kubernetesメタデータ
- ラベル、アノテーション
- ネームスペース情報
- オーナーリファレンス
Helm Chartを使用した導入
Helmリポジトリの追加
New Relic公式Helmリポジトリを追加して、最新のChartを使用できるようにします。
# New Relic Helmリポジトリの追加
helm repo add newrelic https://helm-charts.newrelic.com
# リポジトリの更新
helm repo update
# 利用可能なChartの確認
helm search repo newrelic/newrelic-infrastructure
基本的なHelm Chart導入
最もシンプルな設定での導入例です。
# 基本的なインストール
helm install newrelic-infra newrelic/newrelic-infrastructure \
--set licenseKey=YOUR_LICENSE_KEY \
--set cluster=production-cluster \
--namespace=newrelic \
--create-namespace
カスタム値ファイルを使用した導入
より詳細な設定を含むvalues.yamlファイルを作成して導入します。
# values.yaml
licenseKey: "YOUR_LICENSE_KEY"
cluster: "production-cluster"
# 詳細設定
global:
fargate: false
nrStaging: false
image:
repository: newrelic/infrastructure-k8s
tag: "" # 空文字列で最新版を使用
pullPolicy: IfNotPresent
# DaemonSet設定
daemonSet:
# ノードセレクター(特定ノードにのみ配置する場合)
nodeSelector: {}
# Tolerations(taintがあるノードにも配置する場合)
tolerations:
- operator: "Exists"
effect: "NoSchedule"
- operator: "Exists"
effect: "NoExecute"
# リソース制限
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 100m
memory: 128Mi
# サービスアカウント設定
serviceAccount:
create: true
name: ""
annotations: {}
# RBAC設定
rbac:
create: true
pspEnabled: false
# Prometheus設定(メトリクス公開)
prometheus:
enabled: true
port: 8080
# カスタム属性
config:
custom_attributes:
environment: "production"
team: "platform"
cluster_location: "tokyo"
# ログレベル設定
verboseLog: false
# カスタム設定での導入
helm install newrelic-infra newrelic/newrelic-infrastructure \
-f values.yaml \
--namespace=newrelic \
--create-namespace
DaemonSetを使用した手動導入
基本的なDaemonSet設定
Helm Chartを使用せずに、DaemonSetを直接定義する場合の設定例です(要点抜粋)。
# newrelic-infrastructure-daemonset.yaml(要点抜粋)
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: newrelic-infra
namespace: newrelic
spec:
selector:
matchLabels:
app: newrelic-infra
template:
spec:
serviceAccountName: newrelic-infra
hostNetwork: true
hostPID: true
containers:
- name: newrelic-infra
image: newrelic/infrastructure-k8s:latest
env:
- name: CLUSTER_NAME
value: "production-cluster"
- name: NRIA_LICENSE_KEY
valueFrom:
secretKeyRef:
name: newrelic-license
key: license
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 100m
memory: 128Mi
💡 完全な設定例: Namespace、ServiceAccount、RBAC設定など全量はNew Relic公式ドキュメントを参照してください。
DaemonSetの適用
# DaemonSetの適用
kubectl apply -f newrelic-infrastructure-daemonset.yaml
# デプロイメント状態の確認
kubectl get daemonset -n newrelic
kubectl get pods -n newrelic -o wide
高度な設定オプション
マルチクラスター環境での管理
複数のKubernetesクラスターを管理する場合の設定例です。
# multi-cluster-values.yaml(要点抜粋)
licenseKey: "YOUR_LICENSE_KEY"
cluster: "production-cluster-tokyo"
config:
custom_attributes:
environment: "production"
region: "asia-pacific"
cluster_role: "primary"
daemonSet:
resources:
limits:
cpu: 300m # Asia環境では控えめに設定
memory: 256Mi
requests:
cpu: 50m
memory: 64Mi
カスタムメトリクス収集の設定
特定のアプリケーションメトリクスを収集する設定です。
# custom-metrics-values.yaml(要点抜粋)
config:
integrations:
- name: nri-prometheus
config:
targets:
- description: "Application metrics"
urls: ["http://localhost:8080/metrics"]
custom_attributes:
cluster_version: "1.28"
monitoring_tier: "premium"
💡 詳細設定: Prometheusメトリクスの変換ルールなど詳細な設定は公式ドキュメントを参照してください。
ネットワークポリシーとセキュリティ
NetworkPolicyの設定
セキュリティ要件に応じたネットワークポリシーの例です。
# network-policy.yaml(要点抜粋)
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: newrelic-infra-netpol
namespace: newrelic
spec:
podSelector:
matchLabels:
app: newrelic-infra
policyTypes:
- Egress
egress:
# New Relic APIへの通信許可
- to: []
ports:
- protocol: TCP
port: 443
# DNSクエリ許可
- to: []
ports:
- protocol: UDP
port: 53
PodSecurityPolicyの設定
より厳しいセキュリティ環境での設定例です。
# pod-security-policy.yaml(要点抜粋)
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: newrelic-infra-psp
spec:
privileged: true
hostNetwork: true
hostPID: true
runAsUser:
rule: 'RunAsAny'
⚠️ 注意: PodSecurityPolicyはKubernetes 1.25で廃止され、Pod Security Standardsに置き換えられました。
運用と監視
アップグレード戦略
Infrastructure Agentのローリングアップデート設定です。
# upgrade-strategy.yaml(要点抜粋)
spec:
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1 # 一度に1ノードずつ更新
template:
spec:
containers:
- name: newrelic-infra
# ヘルスチェック設定
livenessProbe:
exec:
command: ["sh", "-c", "pgrep -f newrelic-infra"]
initialDelaySeconds: 30
periodSeconds: 30
Helm Chartのアップグレード
# Chart情報の更新
helm repo update
# 現在のバージョン確認
helm list -n newrelic
# アップグレードの実行
helm upgrade newrelic-infra newrelic/newrelic-infrastructure \
-f values.yaml \
--namespace=newrelic
# ロールバック(必要な場合)
helm rollback newrelic-infra 1 -n newrelic
トラブルシューティング
一般的な問題と解決方法
Podが起動しない場合
# Pod状態の確認
kubectl get pods -n newrelic
kubectl describe pod <POD_NAME> -n newrelic
# ログの確認
kubectl logs <POD_NAME> -n newrelic
# ノードのリソース状況確認
kubectl describe nodes
kubectl top nodes
RBAC権限の問題
# ServiceAccountの確認
kubectl get serviceaccount -n newrelic
kubectl describe serviceaccount newrelic-infra -n newrelic
# ClusterRoleBindingの確認
kubectl get clusterrolebinding | grep newrelic
kubectl describe clusterrolebinding newrelic-infra
メトリクスが収集されない場合
# Infrastructure Agentのログ詳細確認
kubectl logs -f <POD_NAME> -n newrelic
# ネットワーク接続テスト
kubectl exec -it <POD_NAME> -n newrelic -- curl -I https://infra-api.newrelic.com
# Kubernetes APIアクセステスト
kubectl exec -it <POD_NAME> -n newrelic -- curl -k https://kubernetes.default.svc.cluster.local
パフォーマンス最適化
リソース使用量を最適化するための設定です。
# performance-optimized-values.yaml
licenseKey: "YOUR_LICENSE_KEY"
cluster: "production-cluster"
# リソース最適化設定
daemonSet:
resources:
limits:
cpu: 200m # CPU使用量を制限
memory: 256Mi # メモリ使用量を制限
requests:
cpu: 50m
memory: 128Mi
config:
# 収集間隔の調整
metrics_process_sample_rate: 60 # デフォルト: 20秒 → 60秒
metrics_storage_sample_rate: 60 # デフォルト: 20秒 → 60秒
metrics_network_sample_rate: 30 # デフォルト: 10秒 → 30秒
# 不要な機能の無効化
enable_win_services: false
enable_win_firewall: false
アンインストール
Helm Chartのアンインストール
# Helm releaseの削除
helm uninstall newrelic-infra -n newrelic
# ネームスペースの削除(必要に応じて)
kubectl delete namespace newrelic
手動DaemonSetのアンインストール
# DaemonSetとリソースの削除
kubectl delete -f newrelic-infrastructure-daemonset.yaml
# 残存リソースの確認
kubectl get all -n newrelic
まとめ
Kubernetes環境でのNew Relic Infrastructure Agent導入は、Helm ChartまたはDaemonSetを使用すると効率的に実行できます。適切なRBAC設定とリソース制限により、クラスターの安定性を保ちながら包括的な監視を実現できます。
マルチクラスター環境では、クラスター固有の設定を通じて一貫した監視戦略を実装できるでしょう。次回は、AWS統合設定について詳しく解説します。
関連記事: Docker環境での導入関連記事: AWS統合設定