LoginSignup
0
0

k8sへのDatadog導入

Posted at

Datadogの導入手順です

環境、ツール
・GKE(standard)
・Kustomize

今回は新規にnamespaceをつくります

namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: datadog

External Secret Operatorを使ったので下記のようにしてSecretを作成します。

secret.yaml
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
  name: datadog-secret-es
spec:
  secretStoreRef:
    kind: ClusterSecretStore
    name: gcp-cluster-secret-store
  target:
    name: datadog-secret
    creationPolicy: Owner
  dataFrom:
    - extract:
        key: datadog-key

Datadog AgentのデプロイにはDatadog Operatorを使いました。 https://docs.datadoghq.com/ja/containers/kubernetes/installation/?tab=operator (ちなみにGKE Autopilotだとうまくいかなかったため、こちらの方法になるかと思います https://docs.datadoghq.com/ja/containers/kubernetes/installation/?tab=helm)

kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: datadog
resources:
  - namespace.yaml
  - secret.yaml
helmCharts:
  - name: datadog-operator
    repo: https://helm.datadoghq.com
    version: v1.0.3
    releaseName: datadog-operator
    namespace: datadog

DatadogAgentをデプロイします。
spec.featuresでオプションを設定できます。

datadog-agent.yaml
kind: DatadogAgent
apiVersion: datadoghq.com/v2alpha1
metadata:
  name: datadog
  namespace: datadog
spec:
  global:
    site: ap1.datadoghq.com
    credentials:
      apiSecret:
        secretName: datadog-secret
        keyName: api-key
      appSecret:
        secretName: datadog-secret
        keyName: app-key
  override:
    clusterAgent:
      image:
        name: gcr.io/datadoghq/cluster-agent:7.46.0
    nodeAgent:
      image:
        name: gcr.io/datadoghq/agent:7.46.0
  features:
    logCollection:
      enabled: true
      containerCollectAll: true
    apm:
      enabled: true
      hostPortConfig:
        enabled: true
    admissionController:
      enabled: true
      mutateUnlabelled: false
    kubeStateMetricsCore:
      enabled: true

APM(分散トレーシング)は別途設定が必要です。Datadog Admission Controllerを有効にしてDeploymentを下記のようにします。

deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: example
    tags.datadoghq.com/env: 'prod'
    tags.datadoghq.com/service: 'example'
    tags.datadoghq.com/version: '0.0'
  name: example
spec:
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
        tags.datadoghq.com/env: 'prod'
        tags.datadoghq.com/service: 'example'
        tags.datadoghq.com/version: '0.0'
        admission.datadoghq.com/enabled: 'true'
      annotations:
        admission.datadoghq.com/js-lib.version: v4.7.0
    spec:
      containers:
        - name: example
          image: ghcr.io/org/example
      imagePullSecrets:
        - name: ghcr-secret

Podでinit containerが起動していることが確認できます。
スクリーンショット 2023-08-09 8.17.46.png
スクリーンショット 2023-08-09 8.18.36.png

0
0
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
0
0