<p>I have a minikube installation on my windows machine. My application exposes a custom metric 'http_requests_total'. I installed Prometheus operator first and configured it scrape the custom metrics. I can see the custom metric appear in Prometheus dashboard.</p>
<p>Trouble arises when I install Prometheus Adapter. I use following helm command to install the adapter:</p>
<pre><code>helm install my-release prometheus-community/prometheus-adapter
</code></pre>
<p>Then I run following command to edit the configmap and add rule for my custom metric:</p>
<pre><code>kubectl edit cm my-release-prometheus-adapter
</code></pre>
<p>I add following section in this configmap:</p>
<pre><code>- seriesQuery: 'http_requests_total{kubernetes_namespace!=&quot;&quot;,kubernetes_pod_name!=&quot;&quot;}'
      resources:
        overrides:
          kubernetes_namespace: {resource: &quot;namespace&quot;}
          kubernetes_pod_name: {resource: &quot;pod&quot;}
      name:
        matches: &quot;^(.*)_total&quot;
        as: &quot;${1}_per_second&quot;
      metricsQuery: sum(rate(&lt;&lt;.Series&gt;&gt;{&lt;&lt;.LabelMatchers&gt;&gt;}[2m])) by (&lt;&lt;.GroupBy&gt;&gt;)
</code></pre>
<p>Having done this, when I execute the following command:</p>
<pre><code>kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1
</code></pre>
<p>I do not see my custom resource being read:</p>
<pre><code>{&quot;kind&quot;:&quot;APIResourceList&quot;,&quot;apiVersion&quot;:&quot;v1&quot;,&quot;groupVersion&quot;:&quot;custom.metrics.k8s.io/v1beta1&quot;,&quot;resources&quot;:[]}
</code></pre>
<p>I have read multiple similar questions posted on stackoverflow but none seems to have the working answer. I tried to change the prometheus url for my adapter but didn't succeed with that. What am I missing? Following is the log from the adapter pod:</p>
<pre><code>I0706 22:41:15.240788       1 adapter.go:101] successfully using in-cluster auth
E0706 22:41:15.274396       1 provider.go:227] unable to update list of all metrics: unable to fetch metrics for query &quot;{namespace!=\&quot;\&quot;,__name__!~\&quot;^container_.*\&quot;}&quot;: Get &quot;http://prometheus-kube-prometheus-prometheus.prom.svc.cluster.local:9090/api/v1/series?match%5B%5D=%7Bnamespace%21%3D%22%22%2C__name__%21~%22%5Econtainer_.%2A%22%7D&amp;start=1625611215.271&quot;: dial tcp: lookup prometheus-kube-prometheus-prometheus.prom.svc.cluster.local on 10.96.0.10:53: no such host
I0706 22:41:15.636300       1 serving.go:325] Generated self-signed cert (/tmp/cert/apiserver.crt, /tmp/cert/apiserver.key)
I0706 22:41:15.637101       1 dynamic_serving_content.go:111] Loaded a new cert/key pair for &quot;serving-cert::/tmp/cert/apiserver.crt::/tmp/cert/apiserver.key&quot;
I0706 22:41:16.192597       1 requestheader_controller.go:244] Loaded a new request header values for RequestHeaderAuthRequestController
I0706 22:41:16.193884       1 config.go:655] Not requested to run hook priority-and-fairness-config-consumer
I0706 22:41:16.249643       1 requestheader_controller.go:169] Starting RequestHeaderAuthRequestController
I0706 22:41:16.249689       1 shared_informer.go:240] Waiting for caches to sync for RequestHeaderAuthRequestController
I0706 22:41:16.249807       1 configmap_cafile_content.go:202] Starting client-ca::kube-system::extension-apiserver-authentication::requestheader-client-ca-file
I0706 22:41:16.249829       1 shared_informer.go:240] Waiting for caches to sync for client-ca::kube-system::extension-apiserver-authentication::requestheader-client-ca-file
I0706 22:41:16.249928       1 configmap_cafile_content.go:202] Starting client-ca::kube-system::extension-apiserver-authentication::client-ca-file
I0706 22:41:16.249977       1 shared_informer.go:240] Waiting for caches to sync for client-ca::kube-system::extension-apiserver-authentication::client-ca-file
I0706 22:41:16.250288       1 dynamic_serving_content.go:130] Starting serving-cert::/tmp/cert/apiserver.crt::/tmp/cert/apiserver.key
I0706 22:41:16.250322       1 reflector.go:219] Starting reflector *v1.ConfigMap (12h0m0s) from k8s.io/apiserver/pkg/authentication/request/headerrequest/requestheader_controller.go:172
I0706 22:41:16.250390       1 reflector.go:255] Listing and watching *v1.ConfigMap from k8s.io/apiserver/pkg/authentication/request/headerrequest/requestheader_controller.go:172
I0706 22:41:16.250322       1 reflector.go:219] Starting reflector *v1.ConfigMap (12h0m0s) from k8s.io/apiserver/pkg/server/dynamiccertificates/configmap_cafile_content.go:206
I0706 22:41:16.250536       1 reflector.go:255] Listing and watching *v1.ConfigMap from k8s.io/apiserver/pkg/server/dynamiccertificates/configmap_cafile_content.go:206
I0706 22:41:16.250555       1 reflector.go:219] Starting reflector *v1.ConfigMap (12h0m0s) from k8s.io/apiserver/pkg/server/dynamiccertificates/configmap_cafile_content.go:206
I0706 22:41:16.250608       1 reflector.go:255] Listing and watching *v1.ConfigMap from k8s.io/apiserver/pkg/server/dynamiccertificates/configmap_cafile_content.go:206
I0706 22:41:16.250577       1 tlsconfig.go:200] loaded serving cert [&quot;serving-cert::/tmp/cert/apiserver.crt::/tmp/cert/apiserver.key&quot;]: &quot;localhost@1625611275&quot; [serving] validServingFor=[127.0.0.1,localhost,localhost] issuer=&quot;localhost-ca@1625611275&quot; (2021-07-06 21:41:15 +0000 UTC to 2022-07-06 21:41:15 +0000 UTC (now=2021-07-06 22:41:16.2505337 +0000 UTC))
I0706 22:41:16.250950       1 named_certificates.go:53] loaded SNI cert [0/&quot;self-signed loopback&quot;]: &quot;apiserver-loopback-client@1625611276&quot; [serving] validServingFor=[apiserver-loopback-client] issuer=&quot;apiserver-loopback-client-ca@1625611275&quot; (2021-07-06 21:41:15 +0000 UTC to 2022-07-06 21:41:15 +0000 UTC (now=2021-07-06 22:41:16.2509375 +0000 UTC))
I0706 22:41:16.251003       1 secure_serving.go:197] Serving securely on [::]:6443
I0706 22:41:16.251321       1 tlsconfig.go:240] Starting DynamicServingCertificateController
I0706 22:41:16.349970       1 shared_informer.go:270] caches populated
I0706 22:41:16.350023       1 shared_informer.go:247] Caches are synced for RequestHeaderAuthRequestController 
I0706 22:41:16.350129       1 shared_informer.go:270] caches populated
I0706 22:41:16.350142       1 shared_informer.go:247] Caches are synced for client-ca::kube-system::extension-apiserver-authentication::client-ca-file 
I0706 22:41:16.350164       1 shared_informer.go:270] caches populated
I0706 22:41:16.350186       1 shared_informer.go:247] Caches are synced for client-ca::kube-system::extension-apiserver-authentication::requestheader-client-ca-file 
I0706 22:41:16.350698       1 tlsconfig.go:178] loaded client CA [0/&quot;client-ca::kube-system::extension-apiserver-authentication::client-ca-file,client-ca::kube-system::extension-apiserver-authentication::requestheader-client-ca-file&quot;]: &quot;minikubeCA&quot; [client,serving] issuer=&quot;&lt;self&gt;&quot; (2021-06-07 20:39:52 +0000 UTC to 2031-06-06 20:39:52 +0000 UTC (now=2021-07-06 22:41:16.3506808 +0000 UTC))
I0706 22:41:16.350796       1 tlsconfig.go:178] loaded client CA [1/&quot;client-ca::kube-system::extension-apiserver-authentication::client-ca-file,client-ca::kube-system::extension-apiserver-authentication::requestheader-client-ca-file&quot;]: &quot;front-proxy-ca&quot; [] issuer=&quot;&lt;self&gt;&quot; (2021-06-08 20:39:52 +0000 UTC to 2031-06-06 20:39:52 +0000 UTC (now=2021-07-06 22:41:16.3507595 +0000 UTC))
I0706 22:41:16.351138       1 tlsconfig.go:200] loaded serving cert [&quot;serving-cert::/tmp/cert/apiserver.crt::/tmp/cert/apiserver.key&quot;]: &quot;localhost@1625611275&quot; [serving] validServingFor=[127.0.0.1,localhost,localhost] issuer=&quot;localhost-ca@1625611275&quot; (2021-07-06 21:41:15 +0000 UTC to 2022-07-06 21:41:15 +0000 UTC (now=2021-07-06 22:41:16.3511272 +0000 UTC))
I0706 22:41:16.351349       1 named_certificates.go:53] loaded SNI cert [0/&quot;self-signed loopback&quot;]: &quot;apiserver-loopback-client@1625611276&quot; [serving] validServingFor=[apiserver-loopback-client] issuer=&quot;apiserver-loopback-client-ca@1625611275&quot; (2021-07-06 21:41:15 +0000 UTC to 2022-07-06 21:41:15 +0000 UTC (now=2021-07-06 22:41:16.3513364 +0000 UTC))
I0706 22:41:26.255679       1 reflector.go:530] k8s.io/apiserver/pkg/authentication/request/headerrequest/requestheader_controller.go:172: Watch close - *v1.ConfigMap total 0 items received
I0706 22:41:26.256047       1 reflector.go:530] k8s.io/apiserver/pkg/server/dynamiccertificates/configmap_cafile_content.go:206: Watch close - *v1.ConfigMap total 0 items received
I0706 22:41:26.257735       1 reflector.go:530] k8s.io/apiserver/pkg/server/dynamiccertificates/configmap_cafile_content.go:206: Watch close - *v1.ConfigMap total 0 items received
</code></pre>
<p>Following are the arguments in the deployment for the adapter:</p>
<pre><code>Args:
      /adapter
      --secure-port=6443
      --cert-dir=/tmp/cert
      --logtostderr=true
      --prometheus-url=http://prometheus.default.svc:9090
      --metrics-relist-interval=1m
      --v=6
      --config=/etc/adapter/config.yaml
</code></pre>
<p>Following are various services present on my local cluster:</p>
<pre><code>NAME                                      TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
alertmanager-operated                     ClusterIP   None             &lt;none&gt;        9093/TCP,9094/TCP,9094/UDP   2d6h
kubernetes                                ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP                      28d
my-release-prometheus-adapter             ClusterIP   10.106.147.10    &lt;none&gt;        443/TCP                      23m
prometheus-grafana                        ClusterIP   10.108.144.246   &lt;none&gt;        80/TCP                       2d6h
prometheus-kube-prometheus-alertmanager   ClusterIP   10.108.19.130    &lt;none&gt;        9093/TCP                     2d6h
prometheus-kube-prometheus-operator       ClusterIP   10.108.170.84    &lt;none&gt;        443/TCP                      2d6h
prometheus-kube-prometheus-prometheus     ClusterIP   10.98.67.168     &lt;none&gt;        9090/TCP                     2d6h
prometheus-kube-state-metrics             ClusterIP   10.97.252.48     &lt;none&gt;        8080/TCP                     2d6h
prometheus-operated                       ClusterIP   None             &lt;none&gt;        9090/TCP                     2d6h
prometheus-prometheus-node-exporter       ClusterIP   10.107.194.240   &lt;none&gt;        9100/TCP                     2d6h
sample-app                                ClusterIP   10.97.86.241     &lt;none&gt;        80/TCP                       4h10m
</code></pre>
<p>In the beginning of logs for the adapter pod, I see following line of error:</p>
<pre><code>unable to update list of all metrics: unable to fetch metrics for query &quot;{__name__=~\&quot;^container_.*\&quot;,container!=\&quot;POD\&quot;,namespace!=\&quot;\&quot;,pod!=\&quot;\&quot;}&quot;: Get &quot;http://prometheus.default.svc:9090/api/v1/series?match%5B%5D=%7B__name__%3D~%22%5Econtainer_.%2A%22%2Ccontainer%21%3D%22POD%22%2Cnamespace%21%3D%22%22%2Cpod%21%3D%22%22%7D&amp;start=1625614091.754&quot;: dial tcp: lookup prometheus.default.svc on 10.96.0.10:53: no such host
</code></pre>

Vaibhav Raj
<p>The prometheus-adapter is not able to connect to your prometheus instance, this line in the log indicates as much:</p>
<pre><code>E0706 22:41:15.274396       1 provider.go:227] unable to update list of all metrics: unable to fetch metrics for query &quot;{namespace!=\&quot;\&quot;,__name__!~\&quot;^container_.*\&quot;}&quot;: Get &quot;http://prometheus-kube-prometheus-prometheus.prom.svc.cluster.local:9090/api/v1/series?match%5B%5D=%7Bnamespace%21%3D%22%22%2C__name__%21~%22%5Econtainer_.%2A%22%7D&amp;start=1625611215.271&quot;: dial tcp: lookup prometheus-kube-prometheus-prometheus.prom.svc.cluster.local on 10.96.0.10:53: no such host
</code></pre>
<p>Although you have a service called <code>prometheus-kube-prometheus-prometheus</code>, the url is expecting that service to live in the <code>prom</code> namespace.  You should edit the prometheus url (in the same way you added the series query) to have the proper url.  If this service is in the default namespace you can specify <code>prometheus-kube-prometheus-prometheus.svc.cluster.local</code> otherwise it would be <code>prometheus-kube-prometheus-prometheus.&lt;NAMESPACE&gt;.svc.cluster.local</code></p>
