• 对EKS(AWS云k8s)启用AMP(AWS云Prometheus)监控+AMG(AWS云 grafana)


    问题

    需要在针对已有的EKS k8s集群启用Prometheus指标监控。而且,这里使用AMP即AWS云的Prometheus托管服务。好像这个服务,只有AWS国际云才有,AWS中国云没得这个托管服务。下面,我们就来尝试在已有的EKS集群上面启用AMP监控。

    步骤

    下面使用页面方式创建的抓取程序有问题,创建抓取程序的安全组不能指定,如果想指定安全组,需要使用CLI工具进行抓取程序创建。
    获取默认抓取程序配置命令,如下:

    aws amp get-default-scraper-configuration --region us-east-1
    
    • 1

    这里会得到一个base64编码的抓取程序配置。
    然后,使用下面的手动命令创建抓取程序,如下:

    aws amp create-scraper --source eksConfiguration="{clusterArn='arn:aws:eks:us-east-1:xxxxxx:cluster/xxxxx', securityGroupIds=['sg-xxxxxx'],subnetIds=['subnet-xxxxxxx', 'subnet-xxxxxx', 'subnet-xxxxxxxx']}" --scrape-configuration configurationBlob="asdfaslkdgjoasdlnOQo=" --destination ampConfiguration="{workspaceArn='arn:aws:aps:us-east-1:xxxxxx:workspace/ws-xxxx-xxxx-xxxx'}"
    
    • 1

    这里使用aws amp create-scraper命令行进行抓取程序创建,主要是为了设置安全组,这里的安全组,是EKS集群的安全组,类似如下:

    eks-cluster-sg-xxxx-009384
    
    • 1

    是这样描述的:

    EKS created security group applied to ENI that is attached to EKS Control Plane master nodes, as well as any managed workloads.

    这个安全组基本上面没有端口和ip限制。
    下面使用页面创建方式作废。

    打开如下页面:
    添加prometheus入口
    点击“添加抓取程序”,接下来,使用创建AMP工作空间,如下图:
    创建抓取程序页面
    这里我们直接用默认的设置就好。等待一段时间,这里的等待时间可能有点久。

    ClusterRole

    创建aps-collector-user用户

    创建一个集群角色和用户,内容如下:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: aps-collector-role
    rules:
      - apiGroups: [""]
        resources: ["nodes", "nodes/proxy", "nodes/metrics", "services", "endpoints", "pods", "ingresses", "configmaps"]
        verbs: ["describe", "get", "list", "watch"]
      - apiGroups: ["extensions", "networking.k8s.io"]
        resources: ["ingresses/status", "ingresses"]
        verbs: ["describe", "get", "list", "watch"]
      - nonResourceURLs: ["/metrics"]
        verbs: ["get"]
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: aps-collector-user-role-binding
    subjects:
    - kind: User
      name: aps-collector-user
      apiGroup: rbac.authorization.k8s.io
    roleRef:
      kind: ClusterRole
      name: aps-collector-role
      apiGroup: rbac.authorization.k8s.io
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    保存为clusterrole-binding.yml文件。应用上述文件:

    kubectl apply -f clusterrole-binding.yml
    
    • 1

    创建的集群角色aps-collector-role和用户aps-collector-user成功后,我们找到之前一步创建抓取程序时得到的roleArn,具体页面如下:
    抓取程序角色
    记住这个抓取程序的IAM角色,然后,将这个IAM角色映射到之前在k8s中创建的aps-collector-user用户。映射命令如下:

    eksctl create iamidentitymapping --cluster cluster-name --region region-id --arn roleArn --username aps-collector-user
    
    • 1

    注意:复制到的抓取程序roleArn,需要去掉aws-service-role/scraper.aps.amazonaws.com/这一段,才能用eksctl命令创建映射。
    具体了例子如下:

    eksctl create iamidentitymapping --cluster uat --region us-east-1 --arn arn:aws:iam::xxxxxxxxxxx:role/AWSServiceRoleForAmazonPrometheusScraper_xxxxxx --username aps-collector-user
    2024-04-16 16:50:15 []  checking arn arn:aws:iam::xxxxxxxxxxx:role/AWSServiceRoleForAmazonPrometheusScraper_xxxxxx against entries in the auth ConfigMap
    2024-04-16 16:50:15 []  adding identity "arn:aws:iam::xxxxxxxxxxx:role/AWSServiceRoleForAmazonPrometheusScraper_xxxxxx" to auth ConfigMap
    
    • 1
    • 2
    • 3

    查看ConfigMap映射,如下命令:

    eksctl get iamidentitymapping --cluster uat --region=us-east-1
    
    • 1

    IAM Identity Center

    因为我们使用IAM Identity Center中的用户,登录Grafana Web页面。所以,我们先要用管理账号登录aws,在IAM Identity Center中创建用户和用户组。如果用成员账号登录IAM Identity Center中创建用户和用户组,在后面的AMG(AWS云 grafana)中会看不到的,所以,我们需要使用管理账号在IAM Identity Center中创建用户和用户组。在下面界面,使用管理账号创建用户和用户组,下面是具体页面入口:
    IAM Identity Center入口

    AMG(AWS云 grafana)

    按上述方式创建完用户和用户组之后,我们开始创建grafana工作区。开始创建grafana工作区,如下图:
    grafana工作区
    设置grafana工作区,如下图:
    AWG主要设置
    设置数据源,设置访问权限,如下图:

    设置使用idp方式访问
    最后审计一片,如果没问题,就直接创建工作区,如下图:
    创建工作区

    等待一段时间,可能这里等待时间有点长。

    配置IAM Identity Center用户组访问权限

    最后,在grafana工作区配置IAM Identity Center用户组访问权限,具体如下图:
    点击分配新用户或组
    添加admin用户组
    设置admin用户组为管理员权限,如下图:
    设置管理员权限
    效果如下:
    管理员组

    打开grafana web页面

    grafana页面地址
    使用IAM Identity Center中admin用户组的成员登录,这个grafana页面。效果如下:
    主页效果

    设置grafana的数据源

    在grafana控制台直接点击“在Grafana中配置”,如下图:
    在Grafana中配置
    使用IAM Identity Center中admin用户组的成员登录,选择AMP所在云区,就可以看到之前,我们创建的AMP工作区,如下图:
    添加数据源
    添加完数据源之后,就是一些常规的prometheus操作了。
    到这里就差不多完成了AMP+AMG对EKS的监控了。

    然后,进入仪表盘倒入页面,如下图:
    导入仪表盘
    导入315仪表盘。如下图:
    导入315仪表盘
    最终效果,如下图:
    效果图

    总结

    AMP+AMG监控EKS这一套,在AWS云上面,在2024年4月这个时间点,感觉还是不很成熟,不过,比之前预览版本的prometheus好多了,之前预览版本的AMP,还得在EKS集群安装一个prometheus服务器。感觉有点画蛇添足。现在这个版本AMP,只需要在集群安装一个抓取程序就可以了。不过,页面新建的抓取程序在现在这个时间点,还不能设置安全组,有点小问题。得使用CLI建抓取程序才行。整体来说AWS云托管Prometheus,托管Grafana,来监控k8s集群,总比没有要好。

    参考

  • 相关阅读:
    MySQL之基础语句
    苍穹外卖--实现公共字段自动填充
    弘辽科技:玩转店铺标签,能让你首页流量快速起爆
    redis性能测试
    M1通讯层的校验-尾块
    向上生长笔记
    vue 学习笔记
    Scala面向对象的特征
    Fiddler代理远程网络请求到本地
    vue2+elTree 实现右键菜单
  • 原文地址:https://blog.csdn.net/fxtxz2/article/details/137827521