k8spacket有助于了解 Kubernetes 集群中的 TCP 数据包流量:
- 显示群集中工作负载之间的流量
- 通知流量在群集外部路由的位置
- 显示有关通过连接关闭套接字的信息
- 显示工作负载发送/接收的字节数
- 计算建立连接的时间长度
- 显示整个集群中工作负载之间的连接网络
安装helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
使用helm安装k8spacket (需要0.5个cpu以及1g的内存)
helm repo add k8spacket https://k8spacket.github.io/k8spacket-helm-chart
helm repo update k8spacket
helm install k8spacket --namespace k8spacket k8spacket/k8spacket --create-namespace
安装完成提示
[root@k8s-master ~]# helm install k8spacket --namespace k8spacket k8spacket/k8spacket --create-namespace
NAME: k8spacket
LAST DEPLOYED: Mon Aug 21 23:27:23 2023
NAMESPACE: k8spacket
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
1. Get the application URL by running these commands:
export NODE_PORT=$(kubectl get --namespace k8spacket -o jsonpath="{.spec.ports[0].nodePort}" services k8spacket)
export NODE_IP=$(kubectl get nodes --namespace k8spacket -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
这里主机模式无法输出NODE_PORT 那么检查 kubectl get service -n k8spacket
Endpoints: 192.168.26.55:6676 获取 Endpoints 浏览器试了一下是可以的
添加普罗米修斯监控
- job_name: "k8spacket-metrics"
metrics_path: /metrics
scrape_interval: 25s
static_configs:
- targets: [k8spacket.k8spacket.svc.cluster.local:8080]
安装grafana
sudo yum install -y https://dl.grafana.com/oss/release/grafana-10.0.2-1.x86_64.rpm
安装grafana插件
[root@k8s-master kube-prometheus]# grafana-cli plugins install marcusolsson-json-datasource
✔ Downloaded and extracted marcusolsson-json-datasource v1.3.6 zip successfully to /var/lib/grafana/plugins/marcusolsson-json-datasource
Please restart Grafana after installing or removing plugins. Refer to Grafana documentation for instructions if necessary.
---------------------------------------
[root@k8s-master kube-prometheus]# grafana-cli plugins install hamedkarbasi93-nodegraphapi-datasource
✔ Downloaded and extracted hamedkarbasi93-nodegraphapi-datasource v1.0.1 zip successfully to /var/lib/grafana/plugins/hamedkarbasi93-nodegraphapi-datasource
Please restart Grafana after installing or removing plugins. Refer to Grafana documentation for instructions if necessary.
启动
systemctl restart grafana-server.service
暴露k8spacket 端口
kubectl port-forward --address 0.0.0.0 service/k8spacket -n k8spacket 8080:8080
添加grafana数据源具体api接口参照下面
grafana:
env:
GF_INSTALL_PLUGINS: hamedkarbasi93-nodegraphapi-datasource,marcusolsson-json-datasource
datasources:
nodegraphapi-plugin-datasource.yaml:
apiVersion: 1
datasources:
- name: "Node Graph API"
jsonData:
### url: "http://k8spacket.k8spacket.svc.cluster.local:8080/nodegraph" ###
access: "proxy"
basicAuth: false
isDefault: false
readOnly: false
type: "hamedkarbasi93-nodegraphapi-datasource"
typeLogoUrl: "public/plugins/hamedkarbasi93-nodegraphapi-datasource/img/logo.svg"
typeName: "node-graph-plugin"
orgId: 1
version: 1
marcusolsson-json-datasource.yaml:
apiVersion: 1
datasources:
- name: "JSON API"
### url: "http://k8spacket.k8spacket.svc.cluster.local:8080/tlsparser/api/data" ###
access: "proxy"
basicAuth: false
isDefault: false
readOnly: false
type: "marcusolsson-json-datasource"
typeLogoUrl: "public/plugins/marcusolsson-json-datasource/img/logo.svg"
typeName: "json-api-plugin"
orgId: 1
version: 1
导入k8spacket数据
把文件复制一下存储到json后缀就行了下面效果图