use prometheus with external ip address

2/5/2019

we have k8s cluster and I’ve application which is running there. Now I try to add https://prometheus.io/ and I use the command

helm install stable/prometheus --version 6.7.4 --name my-prometheus

this command works and I got this

NAME: my-prometheus LAST DEPLOYED: Tue Feb 5 15:21:46 2019 NAMESPACE: default STATUS: DEPLOYED ... when I run command

kubectl get services

I got this

kubernetes                         ClusterIP   100.64.0.1       <none>        443/TCP    2d4h
my-prometheus-alertmanager         ClusterIP   100.75.244.55   <none>        80/TCP     8m44s
my-prometheus-kube-state-metrics   ClusterIP   None             <none>        80/TCP     8m43s
my-prometheus-node-exporter        ClusterIP   None             <none>        9100/TCP   8m43s
my-prometheus-pushgateway          ClusterIP   100.75.24.67     <none>        9091/TCP   8m43s
my-prometheus-server               ClusterIP   100.33.26.206   <none>        80/TCP     8m43s

I didnt get any externalIP

Does someone knows how to add it ? via service? any example for this

update

i’ve added the following yml

apiVersion: v1
kind: Service
metadata:
  name: prometheus-service
spec:
  selector:
    app: prometheus-server
  type: LoadBalancer
  ports:
    - port: 8080
      targetPort: 9090
      nodePort: 30001

which created successfully

now I see the external ip like when running kubectl get services

my-prometheus-server               LoadBalancer   100.33.26.206   8080:30001/TCP     80/TCP     8m43s

And I use in the browser 100.33.26.206:30001 and nothing happen, any idea?

-- Jenny M
google-cloud-platform
kubernetes
kubernetes-helm
prometheus

2 Answers

12/5/2019

The Prometheus helm chart does support configuration for service, see the documentation

To configure Prometheus server on a local cluster, follow the steps:

Create values.yaml:

server:
  service:
    servicePort: 31000
    type: LoadBalancer
    loadBalancerIP: localhost

or

server:
  service:
    nodePort: 31000
    type: NodePort 

Add stable repo to helm (if missing):

helm repo add stable "https://kubernetes-charts.storage.googleapis.com/"

Install Prometheus:

helm install prometheus-demo stable/prometheus --values .\values.yaml

Wait for 1-2mins. Prometheus should be available: http://localhost:31000/

-- Adam Bartha
Source: StackOverflow

2/5/2019

I think what you are trying to do is to create a service with a type LoadBalancer, those have an internal and external IP.

You can create one like any other service but you should precise those two fields:

externalTrafficPolicy: Local
type: LoadBalancer

Updated:

There seems to be some confusion, you don't need an external ip to monitor your apps, it will only be used to access prometheus UI.

The UI is accessible on port 9090 but prometheus is never accessed by the exporter as it will be prometheus wich will be scrapping the exporters.

Now to access a service from the internet you should have a google ip, but it seems that what you have is still an internal IP, it's in the same subnet as the other clusterIP, and it should not. For now in place of an external ip it's showing a port redirect wich is also wrong as the prometheus UI is on port 9090 (if you didn't modify your configuration it should still be). You should try to remove the "nodePort" and leave the port redirect to kubernetes.

-- night-gold
Source: StackOverflow