Getting started overview

To begin using Juju, the process generally involves installing the Juju command-line interface (CLI), bootstrapping a Juju controller, and then deploying your first application using an operator. Juju abstracts away the underlying infrastructure complexities, allowing you to focus on the application's operational lifecycle. This guide covers the initial setup required to get a basic Juju environment operational and deploy a simple application.

Juju supports various cloud providers, including AWS, Google Cloud, Azure, and Kubernetes. The choice of backing infrastructure will influence specific setup steps, particularly when bootstrapping the controller. For the purpose of this guide, we will focus on a local microk8s environment for simplicity, which is often recommended for initial exploration and development due to its minimal resource requirements and ease of setup on a local machine (Juju installation instructions).

Quick-reference setup table

Step What to do Where
1. Install Juju CLI Install the Juju command-line tool on your local machine. Local development machine
2. Install a backend (e.g., MicroK8s) Set up a local Kubernetes environment for the Juju controller and applications. Local development machine
3. Bootstrap Juju Controller Initialize a Juju controller on your chosen backend. Local terminal (via Juju CLI)
4. Add a model Create an application deployment space within your controller. Local terminal (via Juju CLI)
5. Deploy an application Deploy a charm/operator to your model. Local terminal (via Juju CLI)

Create an account and get keys

Juju itself is an open-source project, and using the self-hosted version does not require a commercial account or API keys in the traditional sense for initial setup. The Juju CLI interacts directly with your chosen cloud or Kubernetes environment. However, you will need an account and corresponding credentials for the underlying infrastructure where you intend to deploy Juju.

  • For Kubernetes (e.g., MicroK8s): No explicit account is needed beyond installing MicroK8s locally. Ensure your kubectl context is correctly configured (MicroK8s official documentation).
  • For Cloud Providers (AWS, GCP, Azure): You will need an active account with the respective cloud provider. Juju will use credentials configured for your CLI (e.g., AWS CLI profile, Google Cloud SDK authentication, Azure CLI login) to interact with the cloud resources. For example, to use Juju with AWS, you would typically configure your AWS credentials using the AWS CLI configuration files.

Installing the Juju CLI

The Juju CLI is the primary interface for managing Juju and its deployed applications. It is available for various operating systems.

Linux (snap):

sudo snap install juju --classic

macOS (Homebrew):

brew install juju

Windows (Chocolatey):

choco install juju

After installation, verify Juju is correctly installed by checking the version:

juju version

This command should output the installed Juju CLI version (Juju CLI installation guide).

Your first request

This section guides you through bootstrapping a Juju controller on a local MicroK8s environment and deploying a simple application. This setup is ideal for development and testing without incurring cloud costs.

Step 1: Install MicroK8s (if not already present)

MicroK8s provides a lightweight, local Kubernetes environment. Install it via snap and enable necessary addons:

sudo snap install microk8s --classic
sudo microk8s status --wait-ready
sudo microk8s enable dns storage ingress

You may need to add your user to the microk8s group to avoid using sudo for microk8s commands:

sudo usermod -a -G microk8s $USER
sudo chown -f -R $USER ~/.kube
newgrp microk8s

Verify MicroK8s is running and accessible (MicroK8s installation steps).

Step 2: Bootstrap a Juju controller

The Juju controller manages all your Juju models and applications. For MicroK8s, bootstrap it as follows:

juju bootstrap microk8s my-controller

Replace my-controller with a name for your controller. This command connects Juju to your local MicroK8s instance and deploys the Juju controller. This process can take a few minutes. You can check the status:

juju controllers

It should show my-controller with a CA Cert and API Endpoint (Juju bootstrap documentation).

Step 3: Add a Juju model

A model is a workspace where you deploy and manage applications. You can have multiple models under a single controller.

juju add-model development

This creates a model named development. You can list your models:

juju models

The current model will be marked with an asterisk (Juju models overview).

Step 4: Deploy your first application (Grafana)

Let's deploy Grafana, a popular open source analytics and interactive visualization web application, using its Juju operator (charm).

juju deploy grafana

This command deploys the Grafana operator from the Charmhub. Juju handles retrieving the operator and deploying it to your MicroK8s cluster within the development model.

Monitor the deployment status:

juju status --watch 1s

Wait until the grafana application shows a status of active and ready. This indicates the application has been successfully deployed and is running (deploying applications with Juju).

Step 5: Expose the application and access it

To access Grafana from your browser, you need to expose it:

juju expose grafana

To find the IP address and port for Grafana:

juju status grafana --format json | jq -r '.[].endpoints[].exposed[].ingress[].ip'

This command attempts to extract the IP address using jq, which needs to be installed (e.g., sudo snap install jq). Alternatively, inspect the output of juju status manually. The default port for Grafana is 3000. Navigate to http://<IP_ADDRESS>:3000 in your web browser. You should see the Grafana login page.

Common next steps

Once you have successfully deployed your first application with Juju, consider these common next steps to expand your usage:

  • Relating applications: Juju's strength lies in its ability to manage relationships between applications. For example, you could deploy Prometheus and relate it to Grafana for a complete monitoring stack (Juju relationships documentation).
  • Deploying more complex bundles: Explore Juju bundles, which are collections of related applications and their configurations, allowing for one-command deployment of entire solutions.
  • Exploring Juju with other clouds: Experiment with bootstrapping Juju controllers on public cloud providers like AWS, GCP, or Azure, or on a bare-metal environment.
  • Developing custom operators: For advanced users, learning to develop your own Juju operators (charms) allows you to encapsulate operational knowledge for any application, automating its lifecycle management (Juju Operator SDK overview). This typically involves using the Go programming language to define the operator's logic.
  • Monitoring and logging: Integrate monitoring and logging solutions within your Juju models to gain insights into your deployed applications.

Troubleshooting the first call

Encountering issues during the initial Juju setup is not uncommon. Here are some troubleshooting tips for common problems:

  • juju bootstrap fails:
    • Provider credentials: Ensure your cloud provider credentials (e.g., AWS CLI profile, Azure CLI login, Google Cloud SDK authentication) are correctly configured and have sufficient permissions if you are bootstrapping to a cloud.
    • Network access: Verify that your machine has outbound network access to the cloud provider's API endpoints.
    • MicroK8s readiness: If using MicroK8s, confirm it's fully ready and all necessary addons (like DNS, storage) are enabled by running microk8s status --wait-ready.
  • Application stuck in pending or waiting state:
    • Resource availability: Check if the underlying infrastructure (Kubernetes cluster, cloud region) has enough resources (CPU, memory, disk) to deploy the application.
    • Network issues: Ensure pods can communicate within the Kubernetes cluster. Use microk8s kubectl get pods -A to check pod statuses.
    • Charm errors: Sometimes, the operator itself might have issues. Check the application logs using juju debug-log --replay to look for errors.
  • Cannot access exposed application:
    • juju expose: Confirm you ran juju expose <application-name>.
    • Firewall rules: If deploying to a cloud, ensure security groups or network ACLs allow inbound traffic on the exposed port. For MicroK8s, this is less common but can be an issue if custom firewall rules are in place on your host.
    • IP address and port: Double-check the IP address and port obtained from juju status. If using MicroK8s, the IP might be your local machine's IP, or an IP assigned by MicroK8s.
  • juju status shows errors:
    • Controller health: Verify the Juju controller itself is healthy by running juju controllers.
    • Model issues: Switch to the correct model using juju switch <model-name> if you have multiple models.
    • Debug logs: Use juju debug-log to view detailed logs from the Juju controller and deployed applications, which can provide specific error messages.