How to use Google GKE with Juju
Running through this guide will ensure that you’re ready to deploy and manage Kubernetes workloads on Google Kubernetes Engine (GKE) with Juju. Juju provides built-in support for GKE. That means, once you’ve registered your cluster, you’ll be able to deploy workloads straight away.
- Provision a Kubernetes cluster on GKE
- Connect Juju to your Kubernetes cluster
- Deploy workloads
Using Juju to drive Kubernetes workloads on GKE requires installing some prerequisite software:
Google Cloud SDK
You will need to install. If you’re on Linux, we recommend using
sudo snap install juju --classic
We also provide other installation methods as described in our detailed installation documentation.
To install the Google Cloud SDK and
gcloud command-line interface, follow Google’s documentation for using the interactive installer.
gcloud is installed, you now have to install the required auth plugin and set the
USE_GKE_GCLOUD_AUTH_PLUGIN environment variable:
gcloud components install gke-gcloud-auth-plugin export USE_GKE_GCLOUD_AUTH_PLUGIN=True # or place in .bashrc
There is a
google-cloud-sdk Snap for installing the Google Cloud SDK and CLI as a snap, but it doesn’t work with the
gke-gcloud-auth-plugin that’s now required. So it’s best to use the “interactive installer” approach described above.
kubectl is the command-line client for directly interacting with a Kubernetes cluster. Visit the Kubernetes documentation for manual
kubectl installation instructions.
You will need to have a GKE cluster available before Juju can connect to it. It’s easy to do that via the cloud console.
When creating the default node pool, make sure to request a machine type that provides at least 6 GB memory. This provides sufficient resources to enable Juju to be deployed alongside your workloads. The default guided install on the GKE console for ‘my-first-cluster’ does not provide sufficient RAM unless you edit it.
The Google Cloud SDK will configure
kubectl on your behalf via the
gcloud container clusters get-credential command. Once executed,
kubectl will be able to control your cluster directly.
Before getting the credentials, you need to log in to your Google Cloud account with:
gcloud auth login
And then get your credentials:
gcloud container clusters get-credentials <k8s-cluster> --zone <zone> --project <project>
To check that you have configured
kubectl correctly, execute a command:
kubectl get nodes
There are three distinct stages to configuring your GKE cluster for management with Juju:
- Register the cluster as a Kubernetes cloud
- Deploy a Juju controller to the cluster
- Create a model to house your applications
Additionally, we will also show you how to:
- Clean up the controller
In Juju’s vocabulary, a “cloud” is any space that can host deployed workloads. Juju will automatically detect locally configured Kubernetes contexts, see here for more information.
Alternatively, to register a Kubernetes cluster with Juju, execute the
juju add-k8s command. The
<cloud> will be used by Juju to refer to the cluster later on.
juju add-k8s --gke <cloud>
This command is interactive and will request that you provide details of the cloud account, project, and whether to register this on the current client only or an external controller.
Juju, as an active agent system, requires a controller to get started. Controllers are created with the
juju bootstrap command that takes a cloud’s name and our intended name for the controller.
juju bootstrap <cloud>
(Optional) Specify a controller name
You can specify the name of your Juju controller if you wish:
juju bootstrap <cloud> <controller-name>
If you do not, Juju will generate the name using the name of the cloud.
A model is a workspace for inter-related applications. They correspond (roughly) to a Kubernetes namespace. To create one, use
juju add-model with a name of your choice:
juju add-model <model>
To cleanup a bootstrapped Juju controller the following can be run to have the Juju controller destroyed and cleaned up.
juju destroy-controller <controller-name>
You’re now able to deploy workloads into your model. Workloads are provided by charms (and sets of charms called bundles). You can find a list of Kubernetes charms on Charmhub.
For testing that things are working, you can deploy the snappass-test charm and watch it deploy:
juju deploy snappass-test watch juju status
Last updated a month ago.