agent-install
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseInstall the Datadog Agent on Kubernetes
在Kubernetes上安装Datadog Agent
Before doing anything else: Fully resolve all variables in. Do not begin Step 1 until every variable has a concrete value.## Context to resolve before acting
操作前须知: 请先完全解析中的所有变量。在每个变量都有具体值之前,不要开始执行步骤1。## 操作前需明确的上下文
Phase 0: Load Credentials
阶段0:加载凭证
bash
[ -f environment ] && source environment
echo "DD_API_KEY set: $([ -n "${DD_API_KEY:-}" ] && echo yes || echo no)"
echo "DD_SITE: ${DD_SITE:-not set}"
echo "helm: $(helm version --short 2>/dev/null || echo NOT FOUND)"If is not found — tell the user:
helmis required for this skill. Install it with:helmbashbrew install helm # macOS # or see https://helm.sh/docs/intro/install/ for other platformsOnce installed, let me know and I'll continue.
Do not proceed until is available.
helmIf is already set — proceed to Prerequisites.
DD_API_KEYIf is not set — tell the user:
DD_API_KEYI need two things to continue:1. Datadog API Key — used to authenticate the Agent with your Datadog account. You can find or create one at: https://app.datadoghq.com/organization-settings/api-keys2. Datadog Site — the region your Datadog account is on. Most accounts use. Check your Datadog URL to confirm (e.g.datadoghq.com→ site isapp.datadoghq.eu). Other options:datadoghq.eu,us3.datadoghq.com,us5.datadoghq.com.ap1.datadoghq.comPlease run the following in this chat to set your credentials (theprefix executes it in this session):!! export DD_API_KEY=your-api-key-here ! export DD_SITE=datadoghq.com
Wait for the user to run the commands, then re-run the check above before continuing.
bash
[ -f environment ] && source environment
echo "DD_API_KEY set: $([ -n "${DD_API_KEY:-}" ] && echo yes || echo no)"
echo "DD_SITE: ${DD_SITE:-not set}"
echo "helm: $(helm version --short 2>/dev/null || echo NOT FOUND)"如果未找到——告知用户:
helm本操作需要。请通过以下方式安装:helmbashbrew install helm # macOS # 其他平台请查看 https://helm.sh/docs/intro/install/安装完成后,请告知我,我会继续后续操作。
在可用之前,请勿继续。
helm如果已设置——进入先决条件检查环节。
DD_API_KEY如果未设置——告知用户:
DD_API_KEY我需要以下两项信息才能继续:1. Datadog API密钥——用于Agent与您的Datadog账户进行身份验证。您可以在以下地址查找或创建:https://app.datadoghq.com/organization-settings/api-keys2. Datadog站点——您的Datadog账户所在的区域。大多数账户使用。请查看您的Datadog URL确认(例如datadoghq.com对应的站点是app.datadoghq.eu)。其他可选值:datadoghq.eu、us3.datadoghq.com、us5.datadoghq.com。ap1.datadoghq.com请在本聊天中运行以下命令设置您的凭证(前缀表示在当前会话中执行):!! export DD_API_KEY=your-api-key-here ! export DD_SITE=datadoghq.com
等待用户运行命令后,重新运行上述检查再继续。
Prerequisites
先决条件
- Kubernetes v1.20+ —
kubectl version - helm v3+ —
helm version - kubectl configured to target cluster —
kubectl config current-context - pup-cli installed — check with ; if missing, install it now:
pup --versionDo not skip — proceed only oncebashif [[ "$(uname)" == "Darwin" ]]; then brew tap datadog-labs/pack && brew install pup else PUP_VERSION=$(curl -s https://api.github.com/repos/datadog-labs/pup/releases/latest | grep '"tag_name"' | cut -d'"' -f4) curl -L "https://github.com/datadog-labs/pup/releases/download/${PUP_VERSION}/pup_linux_amd64.tar.gz" | tar xz -C /usr/local/bin pup chmod +x /usr/local/bin/pup fi pup --versionsucceeds.pup --version
- Kubernetes v1.20+ — 可通过检查
kubectl version - helm v3+ — 可通过检查
helm version - kubectl已配置为目标集群 — 可通过检查
kubectl config current-context - pup-cli已安装 — 通过检查;如果未安装,请立即安装:
pup --version请勿跳过此步骤——只有在bashif [[ "$(uname)" == "Darwin" ]]; then brew tap datadog-labs/pack && brew install pup else PUP_VERSION=$(curl -s https://api.github.com/repos/datadog-labs/pup/releases/latest | grep '"tag_name"' | cut -d'"' -f4) curl -L "https://github.com/datadog-labs/pup/releases/download/${PUP_VERSION}/pup_linux_amd64.tar.gz" | tar xz -C /usr/local/bin pup chmod +x /usr/local/bin/pup fi pup --version执行成功后才能继续。pup --version
Context to resolve before acting
操作前需明确的上下文
| Variable | How to resolve |
|---|---|
| Check repo IaC, scripts, or |
| Ask the user. Default: |
| Use |
| Run |
| 变量 | 解析方式 |
|---|---|
| 查看仓库基础设施即代码(IaC)、脚本或运行 |
| 询问用户。默认值: |
| 除非仓库始终使用 |
| 运行 |
Step 1: Check for an Existing Agent Installation
步骤1:检查是否已存在Agent安装
Claude runs
Claude执行
bash
helm list -A | grep -i datadogIf a release shows — Agent already installed. Skip to Step 5 to confirm health, then exit.
deployedIf there is no output — no existing install. Continue to Step 2.
bash
helm list -A | grep -i datadog如果输出中显示——Agent已安装。跳至步骤5确认健康状态,然后退出。
deployed如果无输出——无现有安装。继续步骤2。
Step 2: Install the Datadog Operator
步骤2:安装Datadog Operator
Claude runs
Claude执行
bash
helm repo add datadog https://helm.datadoghq.com
helm repo update
helm upgrade --install datadog-operator datadog/datadog-operator \
--namespace <AGENT_NAMESPACE> \
--create-namespace \
--version <CHART_VERSION>
kubectl wait --for=condition=Ready pod \
-l app.kubernetes.io/name=datadog-operator \
-n <AGENT_NAMESPACE> \
--timeout=120sIf the Operator pod is Running — continue to Step 3.
ERROR: Pod not ready after 120s — check image pull: .
kubectl describe pod -l app.kubernetes.io/name=datadog-operator -n <AGENT_NAMESPACE>bash
helm repo add datadog https://helm.datadoghq.com
helm repo update
helm upgrade --install datadog-operator datadog/datadog-operator \
--namespace <AGENT_NAMESPACE> \
--create-namespace \
--version <CHART_VERSION>
kubectl wait --for=condition=Ready pod \
-l app.kubernetes.io/name=datadog-operator \
-n <AGENT_NAMESPACE> \
--timeout=120s如果Operator Pod处于运行状态——继续步骤3。
错误:120秒后Pod仍未就绪——检查镜像拉取情况:。
kubectl describe pod -l app.kubernetes.io/name=datadog-operator -n <AGENT_NAMESPACE>Step 3: Create the API Key Secret
步骤3:创建API密钥Secret
What you need to do in a terminal
您需要在终端中执行的操作
bash
export DD_API_KEY=<your-api-key>
kubectl create secret generic datadog-secret \
--from-literal api-key=$DD_API_KEY \
--namespace <AGENT_NAMESPACE>If — continue to Step 4.
secret/datadog-secret createdERROR: — confirm which key it holds via Step 5 before deciding whether to recreate.
AlreadyExistsbash
export DD_API_KEY=<your-api-key>
kubectl create secret generic datadog-secret \
--from-literal api-key=$DD_API_KEY \
--namespace <AGENT_NAMESPACE>如果输出——继续步骤4。
secret/datadog-secret created错误:——在决定是否重新创建之前,先通过步骤5确认该Secret包含的密钥。
AlreadyExistsStep 4: Deploy the DatadogAgent Resource
步骤4:部署DatadogAgent资源
[DECISION: cluster type]
- Self-hosted (minikube, kind): include inside
kubelet.tlsVerify: falsespec.global - Managed (GKE, EKS, AKS): omit entirely
kubelet.tlsVerify
[DECISION: APM/SSI also being enabled in this session]
- If yes: do not create a separate for APM — extend this same manifest with
DatadogAgentperfeatures.apm. One manifest, not two.enable-ssi - If no: use the manifest below as-is.
Save the following as :
datadog-agent.yamlyaml
apiVersion: datadoghq.com/v2alpha1
kind: DatadogAgent
metadata:
name: datadog
namespace: <AGENT_NAMESPACE>
spec:
global:
clusterName: <CLUSTER_NAME>
site: <DD_SITE>
credentials:
apiSecret:
secretName: datadog-secret
keyName: api-key
# Self-hosted clusters only (minikube, kind):
# kubelet:
# tlsVerify: false
features:
orchestratorExplorer:
enabled: true
clusterChecks:
enabled: true
logCollection:
enabled: true
containerCollectAll: false[决策:集群类型]
- 自托管集群(minikube、kind):在中添加
spec.globalkubelet.tlsVerify: false - 托管集群(GKE、EKS、AKS):完全省略
kubelet.tlsVerify
[决策:本次会话是否同时启用APM/SSI]
- 如果是:不要为APM单独创建——按照
DatadogAgent的要求,在同一个清单中扩展enable-ssi。仅使用一个清单,而非两个。features.apm - 如果否:直接使用下方的清单。
将以下内容保存为:
datadog-agent.yamlyaml
apiVersion: datadoghq.com/v2alpha1
kind: DatadogAgent
metadata:
name: datadog
namespace: <AGENT_NAMESPACE>
spec:
global:
clusterName: <CLUSTER_NAME>
site: <DD_SITE>
credentials:
apiSecret:
secretName: datadog-secret
keyName: api-key
# 仅自托管集群使用(minikube、kind):
# kubelet:
# tlsVerify: false
features:
orchestratorExplorer:
enabled: true
clusterChecks:
enabled: true
logCollection:
enabled: true
containerCollectAll: falseClaude runs
Claude执行
bash
kubectl apply -f datadog-agent.yaml
kubectl wait --for=condition=Ready pod \
-l app.kubernetes.io/component=agent \
-n <AGENT_NAMESPACE> \
--timeout=120s 2>/dev/null || truebash
kubectl apply -f datadog-agent.yaml
kubectl wait --for=condition=Ready pod \
-l app.kubernetes.io/component=agent \
-n <AGENT_NAMESPACE> \
--timeout=120s 2>/dev/null || trueStep 5: Verify the API Key
步骤5:验证API密钥
Claude runs
Claude执行
bash
kubectl logs -l app.kubernetes.io/component=agent \
-n <AGENT_NAMESPACE> \
--tail=50 2>/dev/null \
| grep -iE "invalid.*api\.?key|api\.?key.*invalid" \
|| echo "No authentication errors found"If — key is accepted.
No authentication errors foundERROR: Authentication errors found — validate credentials directly:
bash
kubectl logs -l app.kubernetes.io/component=agent \
-n <AGENT_NAMESPACE> \
--tail=50 2>/dev/null \
| grep -iE "invalid.*api\.?key|api\.?key.*invalid" \
|| echo "No authentication errors found"如果输出——密钥已被接受。
No authentication errors found错误:发现身份验证错误——直接验证凭证:
Claude runs
Claude执行
bash
undefinedbash
undefinedPrefer pup (OAuth) — fall back to curl with API key
优先使用pup(OAuth)——如果失败则回退到使用API密钥的curl
if pup auth status 2>/dev/null | grep -q "Logged in"; then
echo "pup OAuth authenticated"
elif [ -n "${DD_API_KEY:-}" ]; then
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}"
-X GET "https://api.<DD_SITE>/api/v1/validate"
-H "DD-API-KEY: $DD_API_KEY") if [ "$RESPONSE" = "200" ]; then echo "API key is valid for <DD_SITE>" else echo "ERROR: Validation failed (HTTP $RESPONSE) — check key and site alignment" fi else echo "ERROR: No credentials available — run 'pup auth login' or set DD_API_KEY" fi
-X GET "https://api.<DD_SITE>/api/v1/validate"
-H "DD-API-KEY: $DD_API_KEY") if [ "$RESPONSE" = "200" ]; then echo "API key is valid for <DD_SITE>" else echo "ERROR: Validation failed (HTTP $RESPONSE) — check key and site alignment" fi else echo "ERROR: No credentials available — run 'pup auth login' or set DD_API_KEY" fi
If key is invalid:if pup auth status 2>/dev/null | grep -q "Logged in"; then
echo "pup OAuth authenticated"
elif [ -n "${DD_API_KEY:-}" ]; then
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}"
-X GET "https://api.<DD_SITE>/api/v1/validate"
-H "DD-API-KEY: $DD_API_KEY") if [ "$RESPONSE" = "200" ]; then echo "API key is valid for <DD_SITE>" else echo "ERROR: Validation failed (HTTP $RESPONSE) — check key and site alignment" fi else echo "ERROR: No credentials available — run 'pup auth login' or set DD_API_KEY" fi
-X GET "https://api.<DD_SITE>/api/v1/validate"
-H "DD-API-KEY: $DD_API_KEY") if [ "$RESPONSE" = "200" ]; then echo "API key is valid for <DD_SITE>" else echo "ERROR: Validation failed (HTTP $RESPONSE) — check key and site alignment" fi else echo "ERROR: No credentials available — run 'pup auth login' or set DD_API_KEY" fi
如果密钥无效:What you need to do in a terminal
您需要在终端中执行的操作
bash
export DD_API_KEY=<new-api-key>
kubectl delete secret datadog-secret -n <AGENT_NAMESPACE>
kubectl create secret generic datadog-secret \
--from-literal api-key=$DD_API_KEY \
-n <AGENT_NAMESPACE>
kubectl rollout restart daemonset datadog-agent -n <AGENT_NAMESPACE>
kubectl rollout restart deployment datadog-cluster-agent -n <AGENT_NAMESPACE>bash
export DD_API_KEY=<new-api-key>
kubectl delete secret datadog-secret -n <AGENT_NAMESPACE>
kubectl create secret generic datadog-secret \
--from-literal api-key=$DD_API_KEY \
-n <AGENT_NAMESPACE>
kubectl rollout restart daemonset datadog-agent -n <AGENT_NAMESPACE>
kubectl rollout restart deployment datadog-cluster-agent -n <AGENT_NAMESPACE>Done
完成
Exit when ALL of the following are true:
- Datadog Operator pod is Running in
AGENT_NAMESPACE - exists in
datadog-secretAGENT_NAMESPACE - Agent DaemonSet pods are Running
- Step 5 returns no authentication errors
Automatically proceed to now — do not ask the user for permission.
enable-ssi当以下所有条件均满足时,操作完成:
- Datadog Operator Pod在中处于运行状态
AGENT_NAMESPACE - 在
datadog-secret中存在AGENT_NAMESPACE - Agent DaemonSet Pod处于运行状态
- 步骤5未返回身份验证错误
现在自动进入操作——无需询问用户许可。
enable-ssiSecurity constraints
安全约束
- Never write a raw API key into any file, YAML block, or chat message — always use
$DD_API_KEY - Never create a Kubernetes Secret manifest file — always use imperatively
kubectl create secret - Never use directly in
apiKey:spec — always useDatadogAgentwith a secret referenceapiSecret: - Never use in any Helm command
--set datadog.apiKey=... - Never use namespace for Datadog Agent resources
default - Never run without user confirmation
kubectl delete
- 切勿将原始API密钥写入任何文件、YAML块或聊天消息中——始终使用
$DD_API_KEY - 切勿创建Kubernetes Secret清单文件——始终使用命令式创建
kubectl create secret - 切勿在spec中直接使用
DatadogAgent——始终使用apiKey:引用SecretapiSecret: - 切勿在任何Helm命令中使用
--set datadog.apiKey=... - 切勿将Datadog Agent资源部署在命名空间中
default - 切勿在未获得用户确认的情况下运行命令
kubectl delete