<p>My Prometheus instance is currently deployed outside to the K8s cluster.
I went through the below article :
<a href="https://www.linkedin.com/pulse/monitoring-kubernetes-prometheus-outside-cluster-steven-acreman" rel="nofollow noreferrer">https://www.linkedin.com/pulse/monitoring-kubernetes-prometheus-outside-cluster-steven-acreman</a></p>

<p>and this gives a very good idea about accessing the K8s services via the api server. I am still trying to make it work (stuck with certificates issue).</p>

<p>However, my question is can't we use Prometheus to scape the ingress-controller hostname to scrape metrics endpoint. 
Or is that even a standard approach?</p>

<p>I could not find a single document or implementation around the same.
Please suggest if anyone has implemented the above scenario or has any docs on it.</p>

swetad90
<p>I would use <a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config" rel="nofollow noreferrer">Kubernetes SD configurations</a>, and take adventage of roles to discover targets.</p>

<blockquote>
  <p>Kubernetes SD configurations allow retrieving scrape targets from <a href="https://kubernetes.io/" rel="nofollow noreferrer">Kubernetes'</a> REST API and always staying synchronized with the cluster state.</p>
</blockquote>

<p>You could use role type <code>endpoints</code>:</p>

<blockquote>
  <p>The <code>endpoints</code> role discovers targets from listed endpoints of a service. For each endpoint address one target is discovered per port. If the endpoint is backed by a pod, all additional container ports of the pod, not bound to an endpoint port, are discovered as targets as well.</p>
  
  <p>Available meta labels:</p>
  
  <ul>
  <li><code>__meta_kubernetes_namespace</code>: The namespace of the endpoints object.</li>
  <li><code>__meta_kubernetes_endpoints_name</code>: The names of the endpoints object.</li>
  <li>For all targets discovered directly from the endpoints list (those not additionally inferred from underlying pods), the following labels are attached:
  
  <ul>
  <li><code>__meta_kubernetes_endpoint_hostname</code>: Hostname of the endpoint.</li>
  <li><code>__meta_kubernetes_endpoint_node_name</code>: Name of the node hosting the endpoint.</li>
  <li><code>__meta_kubernetes_endpoint_ready</code>: Set to  <code>true</code>  or  <code>false</code>  for the endpoint's ready state.</li>
  <li><code>__meta_kubernetes_endpoint_port_name</code>: Name of the endpoint port.</li>
  <li><code>__meta_kubernetes_endpoint_port_protocol</code>: Protocol of the endpoint port.</li>
  <li><code>__meta_kubernetes_endpoint_address_target_kind</code>: Kind of the endpoint address target.</li>
  <li><code>__meta_kubernetes_endpoint_address_target_name</code>: Name of the endpoint address target.</li>
  </ul></li>
  <li>If the endpoints belong to a service, all labels of the  <code>role: service</code>  discovery are attached.</li>
  <li>For all targets backed by a pod, all labels of the  <code>role: pod</code>  discovery are attached.</li>
  </ul>
</blockquote>

<p>Or role type <code>ingress</code>:</p>

<blockquote>
  <p>The  <code>ingress</code>  role discovers a target for each path of each ingress. This is generally useful for blackbox monitoring of an ingress. The address will be set to the host specified in the ingress spec.</p>
  
  <p>Available meta labels:</p>
  
  <ul>
  <li><code>__meta_kubernetes_namespace</code>: The namespace of the ingress object.</li>
  <li><code>__meta_kubernetes_ingress_name</code>: The name of the ingress object.</li>
  <li><code>__meta_kubernetes_ingress_label_&lt;labelname&gt;</code>: Each label from the ingress object.</li>
  <li><code>__meta_kubernetes_ingress_labelpresent_&lt;labelname&gt;</code>:  <code>true</code>  for each label from the ingress object.</li>
  <li><code>__meta_kubernetes_ingress_annotation_&lt;annotationname&gt;</code>: Each annotation from the ingress object.</li>
  <li><code>__meta_kubernetes_ingress_annotationpresent_&lt;annotationname&gt;</code>:  <code>true</code>  for each annotation from the ingress object.</li>
  <li><code>__meta_kubernetes_ingress_scheme</code>: Protocol scheme of ingress,  <code>https</code>  if TLS config is set. Defaults to  <code>http</code>.</li>
  <li><code>__meta_kubernetes_ingress_path</code>: Path from ingress spec. Defaults to  <code>/</code>.</li>
  </ul>
</blockquote>

<p>If you wish to check detailed example of configuring Prometheus for Kubernetes please see <a href="https://github.com/prometheus/prometheus/blob/release-2.11/documentation/examples/prometheus-kubernetes.yml" rel="nofollow noreferrer">this file</a>.</p>

<p>Also you might be interested in 3rd party <a href="https://github.com/coreos/prometheus-operator" rel="nofollow noreferrer">Prometheus Operator</a>, which automates the setup of Peometheus on top of Kubernetes.</p>
