You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kubernetes新手求助:如何查找已创建的Service Monitor

Troubleshooting: Can't Find Your ServiceMonitor with kubectl get services

Hey there! I get it, starting out with Kubernetes and Prometheus Operator can throw up little gotchas like this—let's sort this out right away.

Why kubectl get services doesn't work

The key thing to remember here is that ServiceMonitor is not a standard Kubernetes Service resource. It's a Custom Resource Definition (CRD) provided by the Prometheus Operator, built specifically to tell Prometheus which services to scrape metrics from. So commands meant for built-in resources like services won't pick it up.

How to actually find your ServiceMonitor

Here are the exact commands you need to use:

  1. First, confirm the ServiceMonitor CRD exists (this ensures the Prometheus Operator is installed correctly):

    kubectl get crd servicemonitors.monitoring.coreos.com
    

    If this returns a valid result, the CRD is installed—perfect, move to the next step. If not, you'll need to install the Prometheus Operator first before your ServiceMonitor can be recognized.

  2. List all ServiceMonitors across all namespaces:

    kubectl get servicemonitors -A
    

    The -A flag pulls resources from every namespace, which is handy if you're not 100% sure where you created the ServiceMonitor.

  3. List ServiceMonitors in a specific namespace:
    If you know the namespace where you deployed the resource, narrow it down to save time:

    kubectl get servicemonitors -n your-target-namespace
    
  4. Use a shorter alias for quicker access:
    Most Kubernetes users use sm as a shorthand for servicemonitors, so you can also run:

    kubectl get sm -A
    

Bonus: Dig into your ServiceMonitor's details

To verify if your ServiceMonitor is configured correctly (like which services it's targeting, scrape ports, or any configuration issues), use the describe command:

kubectl describe servicemonitor your-sm-name -n your-target-namespace

This will show you full details about the resource, including events or misconfigurations that might be preventing it from working as expected.

内容的提问来源于stack exchange,提问作者kevin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 17:38:15