How to Install Prometheus on Kubernetes Cluster | AWS | Ubuntu 16.04|

Step1: Create AMI instance of type Ubuntu Server 16.04 LTS using your AWS login

Image for post
Image for post

Step 2: Choose an Instance Type

Image for post
Image for post

Step 3: Configure Instance Details

Step 4: Add Storage

Image for post
Image for post

Step 5: Add Tags

Image for post
Image for post

Step 6: Configure Security Group

Image for post
Image for post

Step 7: Create a key pair

Image for post
Image for post

Step 8: Launch instance by using git bash terminal

Image for post
Image for post
sudo -i

Step 8: Set up Prometheus server in the cluster to run Kubernetes

apt-get update && apt-get install -y apt-transport-httpscurl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -cat <<EOF >/etc/apt/sources.list.d/kubernetes.listdeb http://apt.kubernetes.io/ kubernetes-xenial mainEOFapt-get updateapt-get install -y kubelet=1.15.4-00 kubeadm=1.15.4-00 kubectl=1.15.4-00 docker.io

Step 9: Setup the Kubernetes Master

kubeadm init

Step 10: To start using your cluster, you need to run the following as a regular user:

mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/config

Step 11: Update the yum package repositories.

sudo apt-get install yum*

Step 12: Create a Prometheus user, required directories, and make prometheus user as the owner of those directories.

sudo useradd --no-create-home --shell /bin/false prometheus
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
sudo chown prometheus:prometheus /etc/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus

Step 13: Download the source using curl, untar it and rename the extracted folder to prometheus-files.

wget https://github.com/prometheus/prometh...
tar -xvf prometheus-2.20.1.linux-amd64.tar.gz
mv prometheus-2.20.1.linux-amd64 prometheus-files

Note: Get the latest download of Prometheus from Prometheus home page

Step 14: Copy prometheus and promtool binary from prometheus-files folder to /usr/local/bin and change the ownership to prometheus user.

sudo cp prometheus-files/prometheus /usr/local/bin/
sudo cp prometheus-files/promtool /usr/local/bin/
sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool

Step 15: Move the consoles and console_libraries directories from prometheus-files to /etc/prometheus folder and change the ownership to prometheus user.


sudo cp -r prometheus-files/consoles /etc/prometheus
sudo cp -r prometheus-files/console_libraries /etc/prometheus
sudo chown -R prometheus:prometheus /etc/prometheus/consoles
sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries

Setup Prometheus Configuration. All the prometheus configurations should be present in /etc/prometheus/prometheus.yml file.

Step 16: Create the prometheus.yml file.

sudo vi /etc/prometheus/prometheus.yml

Paste the following content in the prometheus.yml

global:
scrape_interval: 10s
scrape_configs:
— job_name: ‘prometheus’
scrape_interval: 5s
static_configs:
— targets: [‘localhost:9090’]

Note: Replace localhost here with public ip of your system

Step 17: Change the ownership of the file to prometheus user.

sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml

Step 18: Setup Prometheus Service File to start automatically


sudo vi /etc/systemd/system/prometheus.service

Copy the following content to the file.

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
— config.file /etc/prometheus/prometheus.yml \
— storage.tsdb.path /var/lib/prometheus/ \
— web.console.templates=/etc/prometheus/consoles \
— web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target

Step 19: Reload the systemd service to register the prometheus service and start the prometheus service.

sudo systemctl daemon-reload sudo systemctl start prometheus

Check the status by using the following command

sudo systemctl status prometheus
Image for post
Image for post

Step 20: Before accessing the Web UI, you need to change the security group settings in the AWS by editing inbound rules and open the port 9090 where prometheus will be running

Image for post
Image for post

Step 21: Using your public ip and paste in the browser using the following command

http://localhost:9090/graph

Note: In the above local host is your public IP address

Image for post
Image for post

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store