阅读量:1
在Ubuntu上监控Kubernetes(k8s)集群状态,可以通过多种方式实现。以下是一些常用的方法:
1. 使用kubectl命令行工具
kubectl 是Kubernetes的命令行工具,可以用来查询和操作Kubernetes集群。
基本监控命令
- 查看所有命名空间中的Pods:
kubectl get pods --all-namespaces - 查看特定命名空间中的Pods:
kubectl get pods -n - 查看节点状态:
kubectl get nodes - 查看集群事件:
kubectl get events --all-namespaces
高级监控命令
- 查看Pods的详细信息:
kubectl describe pod-n - 查看节点的详细信息:
kubectl describe node
2. 使用Kubernetes Dashboard
Kubernetes Dashboard 是一个基于Web的UI,可以用来监控和管理Kubernetes集群。
安装Kubernetes Dashboard
- 下载Dashboard的YAML文件:
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml - 应用YAML文件:
kubectl apply -f recommended.yaml - 获取Dashboard的访问令牌:
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') - 打开Dashboard:
然后在浏览器中访问kubectl proxyhttp://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
3. 使用Prometheus和Grafana
Prometheus 是一个开源的监控系统和时间序列数据库,Grafana 是一个开源的分析和监控平台。两者结合可以提供强大的Kubernetes集群监控能力。
安装Prometheus和Grafana
- 安装Prometheus:
kubectl apply -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/master/bundle.yaml - 安装Grafana:
kubectl apply -f https://raw.githubusercontent.com/grafana/loki/v3.0.5/clients/manifests/kubernetes/grafana-crd.yaml kubectl apply -f https://raw.githubusercontent.com/grafana/loki/v3.0.5/clients/manifests/kubernetes/grafana.yaml
配置Prometheus监控Kubernetes
- 创建Prometheus配置文件
prometheus-configmap.yaml:apiVersion: v1 kind: ConfigMap metadata: name: prometheus-config namespace: monitoring data: prometheus.yml: | global: scrape_interval: 15s scrape_configs: - job_name: 'kubernetes-pods' kubernetes_sd_configs: - role: pod relabel_configs: - source_labels: [__meta_kubernetes_pod_label_app] action: keep regex: your-app-name - 应用配置文件:
kubectl apply -f prometheus-configmap.yaml - 创建Prometheus服务监控器
prometheus-service-monitor.yaml:apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: prometheus namespace: monitoring spec: selector: matchLabels: app: prometheus endpoints: - port: web - 应用服务监控器:
kubectl apply -f prometheus-service-monitor.yaml
配置Grafana显示Prometheus数据
- 打开Grafana界面(通常是
http://)。:3000 - 添加Prometheus数据源:
- 点击左侧菜单的齿轮图标,选择“Data Sources”。
- 点击“Add data source”,选择“Prometheus”。
- 输入Prometheus服务的URL(例如
http://prometheus.monitoring.svc:9090),然后点击“Save & Test”。
通过以上方法,你可以在Ubuntu上有效地监控Kubernetes集群的状态。
以上就是关于“ubuntu如何监控k8s集群状态”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm