Amazon EKS 和 Kubernetes 上的 Container Insights 的快速入门设置
要完成 Container Insights 的设置,您可以按照本节中的快速入门说明进行操作。
在完成本节中的步骤之前,您必须已对 IAM 权限等先决条件进行验证。有关更多信息,请参阅验证 先决条件。
或者,您可以按照以下两节中的说明操作:设置 CloudWatch 代理以收集集群指标和 将日志发送到 CloudWatch Logs。这些章节提供有关 CloudWatch 代理如何与 Amazon EKS 和 Kubernetes 结合使用的更多配置详细信息,但需要您执行更多安装步骤。
Amazon 现已推出 Fluent Bit 作为 Container Insights 的默认日志解决方案,其性能显着提高。我们建议您使用 Fluent Bit 而不是 Fluentd。
使用 CloudWatch 代理和 Fluent Bit 快速入门
Fluent Bit 有两种配置:优化版本和更类似于 FluentD 的体验的版本。快速入门配置使用优化版本。有关 FluentD 兼容配置的更多详细信息,请参阅 将 Fluent Bit 设置为 DaemonSet 以将日志发送到 CloudWatch Logs。
要使用快速入门部署 Container Insights,请输入以下命令。
默认情况下,以下设置步骤以匿名用户身份从 Docker Hub 拉取容器镜像。这种拉取可能会受到速率限制。有关更多信息,请参阅CloudWatch 代理容器镜像。
ClusterName=<my-cluster-name> RegionName=<my-cluster-region> FluentBitHttpPort='2020' FluentBitReadFromHead='Off' [[ ${FluentBitReadFromHead} = 'On' ]] && FluentBitReadFromTail='Off'|| FluentBitReadFromTail='On' [[ -z ${FluentBitHttpPort} ]] && FluentBitHttpServer='Off' || FluentBitHttpServer='On' curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/quickstart/cwagent-fluent-bit-quickstart.yaml | sed 's/{{cluster_name}}/'${ClusterName}'/;s/{{region_name}}/'${RegionName}'/;s/{{http_server_toggle}}/"'${FluentBitHttpServer}'"/;s/{{http_server_port}}/"'${FluentBitHttpPort}'"/;s/{{read_from_head}}/"'${FluentBitReadFromHead}'"/;s/{{read_from_tail}}/"'${FluentBitReadFromTail}'"/' | kubectl apply -f -
在此命令中,my-cluster-name
是 Amazon EKS 或 Kubernetes 集群的名称,my-cluster-region
是在其中发布日志的区域的名称。我们建议您使用在其中部署集群的同一个区域来降低 AWS 出站数据传输成本。
例如,要在名为 MyCluster
的集群上部署 Container Insights 并将日志和指标发布到美国西部(俄勒冈),请输入以下命令。
ClusterName='MyCluster' LogRegion='us-west-2' FluentBitHttpPort='2020' FluentBitReadFromHead='Off' [[ ${FluentBitReadFromHead} = 'On' ]] && FluentBitReadFromTail='Off'|| FluentBitReadFromTail='On' [[ -z ${FluentBitHttpPort} ]] && FluentBitHttpServer='Off' || FluentBitHttpServer='On' curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/quickstart/cwagent-fluent-bit-quickstart.yaml | sed 's/{{cluster_name}}/'${ClusterName}'/;s/{{region_name}}/'${LogRegion}'/;s/{{http_server_toggle}}/"'${FluentBitHttpServer}'"/;s/{{http_server_port}}/"'${FluentBitHttpPort}'"/;s/{{read_from_head}}/"'${FluentBitReadFromHead}'"/;s/{{read_from_tail}}/"'${FluentBitReadFromTail}'"/' | kubectl apply -f -
从 Fluentd 迁移
如果您已配置 Fluentd 并希望迁移到 Fluent Bit,则必须在安装 Fluent Bit 后删除 FluentD pod。可以使用以下命令删除 FluentD。
curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/fluentd/fluentd.yaml | kubectl delete -f - kubectl delete configmap cluster-info -n amazon-cloudwatch
删除 Container Insights
如果您想使用快速入门设置删除 Container Insights,请输入以下命令。
curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/quickstart/cwagent-fluent-bit-quickstart.yaml | sed 's/{{cluster_name}}/'${ClusterName}'/;s/{{region_name}}/'${LogRegion}'/;s/{{http_server_toggle}}/"'${FluentBitHttpServer}'"/;s/{{http_server_port}}/"'${FluentBitHttpPort}'"/;s/{{read_from_head}}/"'${FluentBitReadFromHead}'"/;s/{{read_from_tail}}/"'${FluentBitReadFromTail}'"/' | kubectl delete -f -
使用 CloudWatch 代理和 Fluentd 快速入门
如果您已在 Kubernetes 集群中使用 Fluentd,并希望将其扩展为 Container Insights 的日志解决方案,我们会为您提供 FluentD 配置。
要使用快速入门部署 CloudWatch 代理和 Fluentd,请使用以下命令。以下设置包含社群支持的 FluentD 容器镜像。只要符合 FluentD 镜像要求,您就可以将该镜像替换为您自己的 FluentD 镜像。有关更多信息,请参阅(可选)将 FluentD 设置为 DaemonSet 以将日志发送到 CloudWatch Logs。
curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/quickstart/cwagent-fluentd-quickstart.yaml | sed "s/{{cluster_name}}/
cluster-name
/;s/{{region_name}}/cluster-region
/" | kubectl apply -f -
在此命令中,cluster-name
是 Amazon EKS 或 Kubernetes 集群的名称,cluster-region
是在其中发布日志的区域的名称。我们建议您使用在其中部署集群的同一个区域来降低 AWS 出站数据传输成本。
例如,要在名为 MyCluster
的集群上部署 Container Insights 并将日志和指标发布到美国西部(俄勒冈),请输入以下命令。
curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/quickstart/cwagent-fluentd-quickstart.yaml | sed "s/{{cluster_name}}/MyCluster/;s/{{region_name}}/us-west-2/" | kubectl apply -f -
删除 Container Insights
如果您想使用快速入门设置删除 Container Insights,请输入以下命令。
curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/quickstart/cwagent-fluentd-quickstart.yaml | sed "s/{{cluster_name}}/
cluster-name
/;s/{{region_name}}/cluster-region
/" | kubectl delete -f -