Github: Hake Hardware
Like all things that last, we need a good foundation to work with before we start deploying nodes. So lets jump right in to it. Its expected that you have installed Ubuntu Server or Ubuntu Desktop already. There are tons of guides and YT videos on this so I won’t go over that here.
Ubuntu Server
The first step after a linux installation is always to update the system. So let’s do that:
sudo apt update && sudo apt upgrade -y
And it’s a good idea to set your timezone. Ubuntu Desktop might set that during installation, but Ubuntu Server does not. You can use this Timezone List to find yours. Then just run
sudo timedatectl set-timezone <Your Timezone>
That is really it. Linux is easy right?
Docker
Installing Docker is pretty easy too. I mostly just follow the directions here: Docker Installation but I’m going to list them out here. If you run into issues feel free to reference the official documentation. Just copy each of these one-by-one and run them in your terminal.
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Everything should now be installed. We can test it with this command:
sudo docker run hello-world
You should see something like this:
Lastly, we are going to add the current user to the ‘docker’ group. This step is optional, and just allows you to run Docker commands without ‘sudo’. We honestly won’t be running many more docker commands so it’s not totally necessary.
sudo usermod -aG docker $USER
Portainer
Yes I am a fan of the CLI. But I’m also a fan of really dang cool things like Portainer. Portainer has A LOT of features, and honestly we are just going to use a small fraction of them. Future videos we will dive into some other cool things we can do, but right now we are focused on getting our nodes running!
Turns out, Portainer is just a Docker container… I know the joke is cliche at this point… but containerception! We are going to control our containers from inside a container. Fancy. As always, it’s good to have the Official Documenation on hand, but I’ll walk you through the steps.
First we need to create a container volume (remember that thing about sudo? If you didn’t do the optional step make sure you add sudo here):
docker volume create portainer_data
Then run Docker with the container paramaters:
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
And that its. You are official a Portainer user. So what now? Well there are a few options here. If you are running Ubuntu Desktop, you can actually just visit:
https://localhost:9443
And you should see the Portainer login screen. If you are like me, and you want to access Portainer from another computer, then you need to forward the port that Portainer uses with:
sudo ufw allow 9443/tcp
Then make sure you have your IP address for the host. If not you can find it with a fancy little command:
hostname -I | awk '{print $1}'
Alright now open up the browser on your remote computer and enter:
https://[host-ip]:9443
You should see the default Portainer screen where you can create a Username and Password. Complete that step and make sure you save the info!
You’re in! And, if you go to “Containers” you should see the ‘hello-world’ container we ran earlier. Yours is probably named something else though. Go ahead and click the little checkbox and delete it. We don’t need that thing anymore.
Prometheus
We are cruising! It’s always cool to see the fruits of our labor. But let’s make it useful! Information on Prometheus can be found here. But don’t worry, I’ll go over exactly how to get it set up.
First, we need to make a new directory where we will create a ‘prometheus.yml’ file. So let’s do that:
sudo mkdir /etc/prometheus
Then lets create the file with nano and add some text:
sudo nano /etc/prometheus/prometheus.yml
Now we are going to copy over some information. I will mention that there are a few ways you can set up these yml files for Prometheus. If you have done this before that’s amazing, feel free to switch it up where it makes sense. If you are new to this I recommend trying to stick as close to possible as what I put here. So with nano open, copy and paste this:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['172.18.0.100:9090']
Now this isn’t much yet. We are setting a global scrape interval of 15 seconds. This means for the jobs we add, if we don’t specify a scrape interval it will scrape every 15 seconds. Next, in the ‘scrape_configs’ section we add a new job called ‘prometheus’. Then we set a target of ‘172.18.0.100:9090’. Now you may be saying ‘hey this isn’t my IP’, and that’s fine. In Docker, we are going to create our own bridge network and statically assign IP addresses. The one listed here we will specify in Docker, because Prometheus runs as a Docker container. Pretty cool right?
Alright now to make things even cooler, we are going to create our first stack. A stack is just a Docker Compose file in Portainer. So open up Portainer, and on the left side click ‘Stacks’
Then click “Add Stack” (yes I drew that red circle myself)
Now enter a name for your stack. Something simple is usually best.
Okay now find the “Web Editor” section, we are going to paste some code in there. We are basically creating a Docker Compose file, and as such, spacing is very important, so make sure to maintain the proper spacing when you copy and paste:
version: '3'
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
command: "--config.file=/etc/prometheus/prometheus.yml"
user: root
volumes:
- /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
ports:
- 9090:9090
networks:
spacenet:
ipv4_address: 172.18.0.100
volumes:
prometheus_data:
networks:
spacenet:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.18.0.0/16 # Define the desired subnet
gateway: 172.18.0.1 # Define the desired gateway
I know, that was a lot. Lets go over it really quick. The first line just specifies the version. We are version 3. Next we have a ‘services’ section where we specify the name of our service. We are loading the latest ‘image’ of prometheus. Our container will be named ‘prometheus’. We are executing a command when the container runs, which includes the location of the prometheus.yml file we created earlier. We are running this as root. It will use 2 volumes:
- /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
This is a bind mount, which means we are moving a folder location on our root file system into our container. the ‘:ro’ makes this read only.
- prometheus_data:/prometheus
This is a volume mount. Below you can see in the volumes section we create a volume called ‘prometheus_data’. Here we are pointing this volume to ‘/prometheus’. This allows for persistent data if we ever stop the container.
Next is the ‘volumes’ section. As noted above we are creating a ‘prometheus_data’ volume to store persistent data.
Last is the “networks’ section. We are creating our very own bridge network using the default driver. This will have the listed subnet and gateway.
That was a bit of work but we are finally done. From here you can just click ‘Deploy the Stack’:
It may take a few minutes as the image is downloaded and the container is deployed. Once done you should be able to see your Prometheus container running:
And like that Prometheus is running. We are one step closer to dashboards! So ‘where’ is Prometheus? Well it’s actually running on port 9090. So open up a browser and just like with Portainer, type in localhost or your ip and then 9090. You may get some notice about the certificate, just ignore that and continue. Now, click the ‘Status’ tab, then ‘Targets’ to see everything Prometheus is reporting on.
You should see just ‘prometheus’ listed there. Eventually you will have all nodes + cAdvisor and Node Exporter like you see in the below image.
And that is it for the foundation. We have have everything we need to start adding metrics and creating dashboards. Which just so happens to be the next article, so see you there!