采集容器文本日志或容器标准输出之前,需要先在 Kubernetes 集群中安装 LogCollector,并配置相关环境。本文介绍通过 DaemonSet 方式安装 LogCollector 的操作步骤。
背景信息
通过 DaemonSet 方式在 Kubernetes 集群上安装 LogCollector 后,LogCollector 能够采集其他 Pod 内的容器文本日志或容器标准输出。在安装的过程中,主要完成以下步骤。
- 配置 ServiceAccount、ClusterRole、ClusterRoleBinding,完成 LogCollector 的认证和授权。
- 创建 LogCollector 的 ConfigMap。
- 创建 LogCollector DaemonSet。
已创建 IAM 用户,获取 Access Key ID、Secret Access Key。并至少为用户授予日志服务(TLS)采集预置策略TLSLogCollectorAccess权限策略,权限详情可参考 IAM 概述。 说明
已安装 Helm 3 客户端(3.7 之后版本)。具体操作,请参考Helm。 1 下载 LogCollector Chart 包
登录待安装 LogCollector 的 Kubernetes 集群,根据集群所在地域,执行对应的下载命令下载 LogCollector Chart 包。
说明
- Region ID:请替换为实际环境对应地域的 ID,如华北2(北京)地域为cn-beijing。支持的地域请参考服务地址列表。
- --version 0.1.0:用于获取 LogCollector chart 的参数,固定值。
- LogCollector 版本:以部署 LogCollector Chart 命令中的image参数对应的 LogCollector 镜像为准,默认获取最新版本 LogCollector。
2 部署 LogCollector Chart 包
执行以下命令部署 LogCollector Chart 包。
注意
- 如果报错 Error: INSTALLATION FAILED: Unable to continue with install: ClusterRole "logcollector" in namespace "" exists and cannot be imported into the current release……,说明已经安装 Logcollector 同名的ClusterRole,则需要先执行 kubectl delete clusterrole logcollector 删除该 ClusterRole。
- 如果报错 Error: INSTALLATION FAILED: Unable to continue with install: ClusterRoleBinding "logcollector" in namespace "" exists and cannot be imported into the current release……,说明已经安装 Logcollector 同名的ClusterRoleBinding,则需要先执行 kubectl delete clusterrolebinding logcollector 删除该 ClusterRoleBinding。
其中,region、endpoint、secret_id、secret_key、label、image、logcollector_data 为必选参数,详细说明如下。
登录用于安装 LogCollector 的 Kubernetes 集群,根据集群地域与网络类型,执行对应的下载命令将 LogCollector 安装包下载到指定目录下。
下载地址中的 Region ID 请替换为实际环境对应地域的 ID,支持的地域请参考服务地址列表。 执行以下命令安装 LogCollector。
其中,region、endpoint、secret_id、secret_key、label、logcollector-data为必选参数,namepspace、image为可选参数,详细说明如下。
1 创建 Namespace
此步骤会创建一个 Namespace。
- 登录需要安装 LogCollector 的 Kubernetes 集群。
- 创建一个名为 logcollector_ns.yaml 的 YAML 文件。
- 编辑 YAML 文件,并在 YAML 文件中输入以下内容。
2 创建 ServiceAccount
为 LogCollector 创建一个 ServiceAccount,并配置基本的身份信息。
- 创建一个名为 logcollector_sa.yaml的 YAML 文件。
- 执行如下命令使 ServiceAccount 配置生效。
3 创建 ClusterRole
为 LogCollector 创建 ClusterRole。
- 创建一个名为 logcollector_cr.yaml的 YAML 文件。
- 执行如下命令使 ClusterRole 配置生效。
4 创建 ClusterRoleBinding
为 LogCollector 创建一个 ClusterRoleBinding。
- 创建一个名为 logcollector_crb.yaml的 YAML 文件。
- 执行如下命令使 ClusterRoleBinding 配置生效。
5 创建 ConfigMap
为 LogCollector 创建一个 ConfigMap。
- 创建一个名为 logcollector_config.yaml的 YAML 文件。
为 LogCollector 创建 Daemonset,用于采集当前节点中的日志。
- 创建一个名为 logcollector_ds.yaml的 YAML 文件。
- 在 YAML 文件中输入如下内容,并根据实际情况替换其中的参数。
日志服务在各个区域提供的最新版本 LogCollector 镜像地址如下:
镜像地址中的 Region ID 请替换为实际环境对应地域的 ID,如华北2(北京)地域为cn-beijing。支持的地域请参考服务地址列表。