Add Logging to a Cluster
Introduction
In this tutorial, we are going to show how you can use a Zarf component to inject zero-config, centralized logging into your Zarf cluster.
More specifically, you'll be adding a Promtail / Loki / Grafana (PLG) stack to the Retro Arcade Tutorial by installing Zarf's "logging" component.
System Requirements
- You'll need an internet connection to grab the Zarf Init Package if it's not already on your machine.
Prerequisites
Prior to this tutorial you'll want to have a working cluster with Zarf initialized.
- Zarf binary installed on your $PATH: (Installing Zarf)
- Initialize a cluster.
- Perform the Retro Arcade Tutorial.
Youtube Tutorial
Installing the Logging Component
- Run the
zarf init
command on your cluster.
$ zarf init
- When prompted to deploy the package select
y
for Yes, then hit theenter
key.
When prompted to deploy the logging component selecty
for Yes, then hit theenter
key.
- You can automatically accept the logging component, and confirm the package using the
--confirm
and--components
flags.
Connecting to the Logging Component
Note the Credentials
- Review the
zarf init
command output for the following:
You should see a section for Logging
. You will need these credentials later on.
Deploy the Retro Arcade Tutorial
- If you haven't already in the prerequisites, deploy the Retro Arcade Tutorial.
Check the logs
Because Doom may be freshly installed it is recommended to refresh the page a few times to generate more log traffic to view in Grafana
Log into Grafana
To open Grafana you can use the zarf connect logging
command.
You'll be redirected the /login
page where you have to sign in with the Grafana credentials you saved in a previous step.
Once you've successfully logged in go to:
- The "Explore" page (Button on the left that looks like a compass)
- Select
Loki
in the dropdown, and then - Enter
{app="game"}
into the Log Browser query input field
Submit that query and you'll get back a dump of all the game pod logs that Loki has collected.
Removal
- Use the
zarf package list
command to get a list of the installed packages and their components. This will give you the name of the init package and the logging component to remove it.
- Use the
zarf package remove
command to remove thelogging
component from the init package. Don't forget the--confirm
flag. Otherwise you'll receive an error.
Troubleshooting
Unable to connect to the Kubernetes cluster.
If you receive this error, either you don't have a Kubernetes cluster, your cluster is down, or your cluster is unreachable.
- Check your kubectl configuration, then try again. For more information about kubectl configuration see Configure Access to Multiple Clusters from the Kubernetes documentation.
If you need to setup a cluster, you can perform the following.
- Deploy a Kubernetes cluster with the Creating a K8s Cluster with Zarf tutorial.
- Perform the Initialize a cluster tutorial.
After that you can try deploying the package again.