温馨提示×

如何在centos上监控k8s状态

小樊
39
2025-03-17 21:50:43
栏目: 智能运维
Centos服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在CentOS上监控Kubernetes(k8s)状态有多种方法,以下是一些常用的工具和步骤:

使用Cockpit

Cockpit是CentOS 8(CentOS 7也可以使用)内置的一款基于Web的可视化管理工具,可以监控服务器资源、网络配置、用户管理、防火墙管理等。

安装步骤:

  1. 安装Cockpit:
yum install cockpit
systemctl start cockpit
systemctl enable cockpit
  1. 开放Cockpit的端口(如果防火墙启用):
firewall-cmd --permanent --zone=public --add-service=cockpit
firewall-cmd --reload
  1. 登录Cockpit:使用系统用户root和对应的root密码,访问http://<your-server-ip>:9090

使用Prometheus和Grafana

Prometheus是一个开源的监控系统,具有多维数据收集和查询功能,而Grafana则用于数据的可视化展示。

安装步骤:

  1. 部署Prometheus Operator
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/master/bundle.yaml
  1. 配置Prometheus

创建prometheus.yaml文件,内容如下:

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
  name: my-prometheus
spec:
  replicas: 2
  serviceAccountName: prometheus-k8s
  serviceMonitorSelector: {}
  resources:
    requests:
      memory: 400Mi
  ruleSelector:
    matchLabels:
      prometheus: k8s
  alerting:
    alertmanagers:
    - namespace: monitoring
      name: alertmanager-main
      port: web
  storage:
    storageClassName: default
    volumeClaimTemplate:
      spec:
        resources:
          requests:
            storage: 10Gi
  ingress:
    enabled: false

应用配置:

kubectl apply -f prometheus.yaml
  1. 部署Grafana
kubectl apply -f https://raw.githubusercontent.com/coreos/kube-prometheus/master/manifests/grafana/grafana.yaml
  1. 配置Grafana连接Prometheus:在Grafana界面中添加Prometheus数据源,填入Prometheus的服务地址(如http://my-prometheus.monitoring.svc.cluster.local)。

  2. 部署Grafana Dashboard:导入现成的Grafana仪表盘来展示K8S监控数据,如Node监控、Pod监控、服务监控等。

使用Kindling和Grafana

Kindling是一个用于观测Kubernetes应用网络连接状态的工具,可以与Grafana结合使用。

安装步骤:

  1. 确保内核版本大于4.14。
  2. 下载并安装Kindling的YAML文件。
  3. 应用Kindling的配置:
kubectl apply -f ./kindling.yaml
  1. 查看Pod状态:
kubectl -n kindling get pod
  1. 安装Grafana插件并导入面板。

使用NVIDIA设备插件

对于需要监控NVIDIA GPU设备的用户,可以安装NVIDIA设备插件。

安装步骤:

  1. 安装NVIDIA驱动程序。
  2. 安装nvidia-container-toolkit。
  3. 配置containerd以使用nvidia-container-toolkit。

以上方法可以帮助您在CentOS上有效地监控Kubernetes集群的状态和性能。根据您的具体需求,可以选择适合的工具进行监控。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:centos k8s如何监控状态

0