要解决AWS EKS(Elastic Kubernetes Service)K8s集群使用Weave CNI(Container Network Interface)插件无法使用自定义指标的问题,可以按照以下步骤进行操作:
kubectl get pods -n kube-system | grep weave
如果没有找到与weave相关的Pod,则需要使用以下命令来部署Weave CNI插件:
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.39/example/prometheus-operator-crd/alertmanager.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.39/example/prometheus-operator-crd/prometheus.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.39/example/prometheus-operator-crd/prometheusrule.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.39/example/prometheus-operator-crd/servicemonitor.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.39/example/prometheus-operator-crd/podmonitor.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.39/example/prometheus-operator-crd/thanosruler.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.39/example/prometheus-operator-crd/prometheusrules.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.39/example/prometheus-operator-deployment.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: my-service-monitor
labels:
app: my-app
namespace: default
spec:
selector:
matchLabels:
app: my-app
endpoints:
- port: metrics
path: /metrics
将上述代码保存为service-monitor.yaml
文件,并使用以下命令进行部署:
kubectl apply -f service-monitor.yaml
kubectl get pods -n kube-system -l 'name in (weave, prometheus-operator)'
如果它们不在同一个命名空间中,请将它们放置在相同的命名空间中。
kubectl get pods -n kube-system -l 'name in (weave, prometheus-operator)'
如果它们的状态不是Running
,请查看相关的日志以排除问题。
kubectl describe pod -n kube-system | grep -A 4 "Mounts"
kubectl describe pod -n kube-system | grep -A 4 "Mounts"
如果它们的权限不正确,请为它们分配适当的RBAC权限。
完成上述步骤后,Weave CNI插件应该可以使用自定义指标。您可以使用Prometheus查询这些指标并进行监控。