Skip to main content

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.

Youtube Tutorial

Tutorial: Add Logging to an existing Zarf Cluster with Zarf Init

Installing the Logging Component

  1. Run the zarf init command on your cluster.
$ zarf init
  1. When prompted to deploy the package select y for Yes, then hit the enter key.
    When prompted to deploy the logging component select y for Yes, then hit the enter key.
  1. 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

  1. 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

  1. If you haven't already in the prerequisites, deploy the Retro Arcade Tutorial.

Check the logs

note

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.

zarf user logging into Loki

Once you've successfully logged in go to:

  1. The "Explore" page (Button on the left that looks like a compass)
  2. Select Loki in the dropdown, and then
  3. Enter {app="game"} into the Log Browser query input field

zarf user typing {app='game'} into the Loki Log Browser

Submit that query and you'll get back a dump of all the game pod logs that Loki has collected.

Loki query results

Removal

  1. 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.
  1. Use the zarf package remove command to remove the logging 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.

Remediation

If you receive this error, either you don't have a Kubernetes cluster, your cluster is down, or your cluster is unreachable.

  1. 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.

  1. Deploy a Kubernetes cluster with the Creating a K8s Cluster with Zarf tutorial.
  2. Perform the Initialize a cluster tutorial.

After that you can try deploying the package again.