<p>I am new to Prometheus and relatively new to kubernetes so bear with me, please. I am trying to test Prometheus out and have tried two different approaches. </p>

<ol>
<li><p>Run Prometheus as a docker container outside of kubernetes. To accomplish this I have created this Dockerfile:</p>

<pre><code>FROM prom/prometheus
ADD prometheus.yml /etc/prometheus/
</code></pre>

<p>and this yaml file:</p>

<pre><code>global:
  scrape_interval: 15s
  external_labels:
    monitor: 'codelab-monitor'
scrape_configs:
- job_name: 'kubernetes-apiservers'
  scheme: http
  tls_config:
    ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
  kubernetes_sd_configs:
  - role: endpoints
    api_server: localhost:443
</code></pre>

<p>When I run this I get:</p>

<pre><code>Failed to list *v1.Pod: Get http://localhost:443/api/v1/pods?limit=500&amp;resourceVersion=0: dial tcp 127.0.0.1:443: connect: connection refused"
Failed to list *v1.Service: Get http://localhost:443/api/v1/pods?limit=500&amp;resourceVersion=0: dial tcp 127.0.0.1:443: connect: connection refused"
Failed to list *v1.Endpoints: Get http://localhost:443/api/v1/pods?limit=500&amp;resourceVersion=0: dial tcp 127.0.0.1:443: connect: connection refused"
</code></pre>

<p>on a loop. Prometheus will load when I go to localhost:9090 but there is no data.</p></li>
<li><p>I thought deploying Prometheus as a Kubernetes deployment may help, so I made this yaml and deployed it.</p>

<pre><code>kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: prometheus-monitor
spec:
  selector:
    matchLabels:
      app: prometheus
  template:
    metadata:
      labels:
        app: prometheus
    spec:
      containers:
      - name: prometheus-monitor
        image: prom/prometheus
        # args:
        #   - '-config.file=/etc/prometheus/prometheus.yaml'
        imagePullPolicy: IfNotPresent
        ports:
        - name: webui
          containerPort: 9090
</code></pre>

<p>The deployment was successful, but if I go to localhost:9090 I get 'ERR_SOCKET_NOT_CONNECTED'. (my port is forwarded)</p></li>
</ol>

<p>Can anyone tell me the advantage of in vs out of Kubernetes and how to fix at least one of these issues?</p>

<p>Also, my config file is suppressed because it was giving an error, and I will look into that once I am able to get Prometheus loaded.</p>

beanwa
<p>Kubernetes does not map the port outside it's cluster when you deploy your container.</p>

<p>You also have to create a service (can be inside the same file) to make it available from your workstation (append this to your prometheus yaml):</p>

<pre><code>---
apiVersion: v1
kind: Service
metadata:
    name: prometheus-web
    labels:
        app: prometheus
spec:
    type: NodePort
    ports:
        - port: 9090
          protocol: TCP
          targetPort: 9090
          nodePort: 30090
          name: webui
    selector:
        app: prometheus
</code></pre>

<p>NodePort opens the given port on all nodes you have. You should be able to see the frontend with <a href="http://localhost:30090/" rel="nofollow noreferrer">http://localhost:30090/</a></p>

<p>Per default, kubernetes allow ports 30000 to 32767 for NodePort type (<a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/#nodeport</a>).</p>

<p>Please consider reading the documentation in general for more information on services in kubernetes: <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/</a></p>
