更新 CloudWatch 代理容器镜像 - Amazon CloudWatch
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

更新 CloudWatch 代理容器镜像

如果需要将容器映像更新到最新版本,请使用本节中的步骤。

更新您的容器映像
  1. 输入以下命令,应用最新的 cwagent-serviceaccount.yaml 文件。

    kubectl apply -f https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/cwagent/cwagent-serviceaccount.yaml
  2. 此步骤仅适用于从 2019 年 8 月 20 日发布的 1.226589.0 之前的版本升级其容器化 CloudWatch 代理的客户。

    在 Configmap 文件 cwagentconfig 中,将关键字 structuredlogs 更改为 logs

    1. 首先,输入以下命令在编辑模式下打开现有的 cwagentconfig

      kubectl edit cm cwagentconfig -n amazon-cloudwatch

      在文件中,如果您看到关键字 structuredlogs,请将其更改为 logs

    2. 输入 wq 以保存该文件并退出编辑模式。

  3. 输入以下命令,应用最新的 cwagent-daemonset.yaml 文件。

    kubectl apply -f https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/cwagent/cwagent-daemonset.yaml

您可以在更改 cwagent-configmap.yaml 中的配置时随时实现 CloudWatch 代理 DaemonSet 的滚动更新。要实现滚动更新,您必须确保 cwagent-daemonset.yaml 文件中的 .spec.template 部分已相应更改。否则,Kubernetes 将 DaemonSet 视为未更改。通常的做法是将 ConfigMap 的哈希值添加到 .spec.template.metadata.annotations.configHash 中,如以下示例中所示。

yq 版本 4

$HASH=`kubectl get cm/cwagentconfig -n amazon-cloudwatch -o yaml | sha256sum` yq -i '.spec.template.metadata.annotations.configHash = strenv(HASH)' cwagent-daemonset.yaml
$cat cwagent-daemonset.yaml |grep Hash
$kubectl apply -f cwagent-daemonset.yaml

yq 版本 3

yq w -i cwagent-daemonset.yaml spec.template.metadata.annotations.configHash $(kubectl get cm/cwagentconfig -n amazon-cloudwatch -o yaml | sha256sum)

这会在 cwagent-daemonset.yaml 文件中添加哈希值,如以下示例中所示。

spec: selector: matchLabels: name: cloudwatch-agent template: metadata: labels: name: cloudwatch-agent annotations: configHash: 88915de4cf9c3551a8dc74c0137a3e83569d28c71044b0359c2578d2e0461825

然后,运行以下命令,以选择新配置。

kubectl apply -f cwagent-daemonset.yaml

有关 yq 的更多信息,请参阅 yq