<file_sep>FROM grafana/grafana:4.4.2

RUN apt-get update && apt-get install -y curl gettext-base telnet supervisor nginx openssl && rm -rf /var/lib/apt/lists/*

WORKDIR /etc/grafana
COPY datasources ./datasources

WORKDIR /etc/grafana
COPY grafana.ini ./grafana.ini

WORKDIR /etc/grafana
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/cert.key -out /etc/nginx/cert.crt -subj "/C=IN/ST=Karnataka/L=Bangalore/O=Grafana/OU=IT Department/CN=localhost"

RUN mkdir -p mkdir /opt/template/logs
ADD https://releases.hashicorp.com/consul-template/0.19.5/consul-template_0.19.5_linux_amd64.tgz /tmp/consul-template.tgz
RUN cd /tmp && tar xvfz /tmp/consul-template.tgz && mv consul-template /bin/consul-template 

WORKDIR /etc/nginx/sites-enabled
COPY default ./default

WORKDIR /etc/grafana
COPY grafana.ini.ctmpl ./grafana.ini.ctmpl

WORKDIR /etc/grafana
COPY config.hcl ./config.hcl
COPY start.sh ./start.sh
RUN chmod u+x start.sh
RUN mkdir -p /etc/supervisor/conf.d/
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

WORKDIR /app
COPY entrypoint.sh ./
RUN chmod u+x entrypoint.sh

WORKDIR /app
COPY dashboard.json ./
COPY add_dashboard.sh ./
RUN chmod u+x add_dashboard.sh

ENTRYPOINT ["/usr/bin/supervisord"]


<file_sep>version: '3.2'

services:
  myvault:
    image: vault
    container_name: myvault
    ports:
      - "127.0.0.1:8200:8200"
    env_file: configuration.env
    volumes:
      - ./vault/file:/vault/file:rw
      - ./vault/config:/vault/config:rw
    cap_add:
      - IPC_LOCK
    entrypoint: vault server -config=/vault/config/vault.json
  influxdb:
    build: influxdb
    env_file: configuration.env
    ports:
      - '8086:8086'
    volumes:
      - influxdb_data:/var/lib/influxdb
  consul:
    image: "consul"
    hostname: "consul"
    command: agent -server -bind 0.0.0.0 -client 0.0.0.0 -bootstrap-expect=1 
    ports:
      - "8400:8400"
      - "8500:8500"
      - "8600:53/udp"
    volumes:
      - ./consul/config:/consul/config
  grafana:
    build: grafana
    env_file: configuration.env
    links:
      - influxdb
    ports:
      - '3000:3000'
      - '80:80'
      - '443:443'
    volumes:
      - grafana_data:/var/lib/grafana
  git2consul:
    image: cimpress/git2consul
    depends_on:
      - consul
    container_name: git2consul
    volumes:
      - ./config/git2consul:/config
    command: --endpoint consul --config-file /config/git2consul.json
volumes:
  grafana_data: {}
  influxdb_data: {}
<file_sep>
Docker – Grafana – InfluxDB – Consul-Template – Consul – Git2Consul – Vault

The above application are experimented in Mac Docker engine

Docker Code Repo: https://github.com/vimalkrish/GICV-Version-2

Git2consul Repo: https://github.com/vimalkrish/git2consul_data


*Enabled Https for Grafana

*disabled grafana Signup

*Created dashboard via JSON file

*Manage Grafana Configuration in Consul using Consul-template

*Manage Consul Key/Value in git2consul 

*store the secret keys in Vault


Grafana login stored in Vault

Grafana Login:

https://127.0.0.1

user: admin

password: <PASSWORD>

-----------------

InfluxDB database

Database: influx

User: admin

Password: <PASSWORD>

------------------

To start the docker containers

Clone the git repository

#git clone <EMAIL>:vimalkrish/GICV-Version-2.git

#cd GICV-Version-2/grafana

#docker compose up -d

Now you can see 5 container running
1 – Consul
2 – Grafana, consul-template
3 – Vault
4 – influxdb
5 – git2consul

Check all the services are started

#docker ps

Applications:
Grafana: https://127.0.0.1
InfluxDB Server: 127.0.0.1 Port: 8086
Consul Server: http://127.0.0.1:8500
Vault Server: 127.0.0.1 port: 8200

Vault key and Token

Unseal Key 1: <KEY>

Unseal Key 2: <KEY>

Unseal Key 3: <KEY>

Unseal Key 4: <KEY>

Unseal Key 5: <KEY>

Initial Root Token: <PASSWORD>

Login to vault container and initialize it

#vault init

Unseal Vault using 3 keys

#vault operator unseal

#vault operator unseal

#vault operator unseal

Init the root token

#vault login

From the host environment (i.e. outside of the docker image):

#alias vault='docker exec -it CONTAINER-ID vault "$@"'

#vault read secret/grafana



--------------------------------------------------------------------
Telegraf

Install telegraf in local laptop and send the metrics to InfluxDB

Command to Install in MAC

brew install telegraf

update the configuration file /usr/local/etc/telegraf.conf

add the url “http://localhost:8086” and Read metrics, cpu, memory and disk

once the influxdb container is up, start the telegraf service

#telegraf -config /usr/local/etc/telegraf.conf

--------------------------------------------------------------------

Consul

Consul is a distributed service mesh to connect, secure, and configure services across any runtime platform and public or private cloud

In this project consul container is used for configuration management and KV

Create the directory /consul/config/

Create the configuration file /consul/config/config.json

--------------------------------------------------------------------

Vault:

It is to store secures, stores, and tightly controls access to tokens, passwords, certificates, API keys

Our Grafana secrets are stored in vault container

Used file backed storage /vault/file

Configuration File /vault/config/vault.json

Update the configuration file 

--------------------------------------------------------------------

Grafana:

Data visualization & Monitoring with support for Graphite, InfluxDB, Prometheus, Elasticsearch and many more databases.

In our project Grafana and consul template running in same container

Grafana conf file /etc/Grafana/“grafana.ini”

Template file /etc/Grafana/“grafana.ini.ctmpl”

Used Nginx for SSL 

/etc/nginx

/etc/nginx/sites-enabled/default

Certificates stored in 

/ etc/nginx/cert.crt
/etc/nginx/cert.key

Supervisor -
Used supervisor to run the services

Configuration file -> /etc/supervisor/conf.d/supervisord.conf


Consul-template command

#/bin/consul-template -consul-addr 'consul:8500' -template '/etc/grafana/grafana.ini.ctmpl:/etc/grafana/grafana.ini'

--------------------------------------------------------------------

InfluxDB

InfluxDB is an open-source time series database developed written in Go by InfluxData. InfluxDB is optimized for fast, high-availability storage and retrieval of time series data for metrics analysis

Created a Database and user

user=admin
password=<PASSWORD>
database=influx


--------------------------------------------------------------------

Troubleshooting:

If the git2consul container is not up, please run "docker-compose up -d" once again to bring it up

I have tried this task in Mac Laptop Docker engine, please use "localhost" for all configurations


--------------------------------------------------------------------

 



<file_sep>#!/usr/bin/env sh
/bin/consul-template -consul-addr 'consul:8500' -template '/etc/grafana/grafana.ini.ctmpl:/etc/grafana/grafana.ini' 
