This page shows you how to use Pub/Sub to receive notifications about your Google Kubernetes Engine (GKE) clusters.
Overview
When certain events occur that are relevant to your GKE clusters, such as important scheduled upgrades or available security bulletins, GKE publishes notifications about those events as messages to Pub/Sub topics that you configure. You can receive these notifications on a Pub/Sub subscription, integrate with third-party services, and filter for the notification types you want to receive.
To learn more about the benefits of cluster notifications, how notifications work, and why filtering is important, refer to Cluster notifications.
Before you begin
Before you start, make sure you have performed the following tasks:
- Ensure that you have enabled the Google Kubernetes Engine API. Enable Google Kubernetes Engine API
- Ensure that you have installed the Google Cloud CLI.
- Set up default Google Cloud CLI settings for your project by using one of the following methods:
- Use
gcloud init
, if you want to be walked through setting project defaults. - Use
gcloud config
, to individually set your project ID, zone, and region. -
Run
gcloud init
and follow the directions:gcloud init
If you are using SSH on a remote server, use the
--console-only
flag to prevent the command from launching a browser:gcloud init --console-only
- Follow the instructions to authorize the gcloud CLI to use your Google Cloud account.
- Create a new configuration or select an existing one.
- Choose a Google Cloud project.
- Choose a default Compute Engine zone.
- Choose a default Compute Engine region.
- Set your default project ID:
gcloud config set project PROJECT_ID
- Set your default Compute Engine region (for example,
us-central1
):gcloud config set compute/region COMPUTE_REGION
- Set your default Compute Engine zone (for example,
us-central1-c
):gcloud config set compute/zone COMPUTE_ZONE
- Update
gcloud
to the latest version:gcloud components update
gcloud init
gcloud config
By setting default locations, you can avoid errors in gcloud CLI like the
following: One of [--zone, --region] must be supplied: Please specify location
.
- Create a Pub/Sub topic in your project.
Enable cluster notifications on a new cluster
You can enable GKE cluster notifications on a new cluster using the Google Cloud CLI or Google Cloud console.
gcloud
To enable cluster notifications on a new cluster, run the following command:
gcloud container clusters create CLUSTER_NAME \
--region=COMPUTE_REGION \
--notification-config=pubsub=ENABLED,pubsub-topic=projects/PROJECT_ID/topics/TOPIC_NAME,filter=NOTIFICATION_TYPE
Replace the following:
CLUSTER_NAME
: the name of your new cluster.COMPUTE_REGION
: the compute region for your new cluster. For zonal clusters, use--zone=COMPUTE_ZONE
.PROJECT_ID
: your Google Cloud project ID.TOPIC_NAME
: the name of your Pub/Sub topic.NOTIFICATION_TYPE
: a pipe (|) delimited list of the notification types you want to receive. For example,filter="UpgradeEvent|SecurityBulletinEvent"
only sendsUpgradeEvent
andSecurityBulletinEvent
notifications, ignoring all other types.
Console
To enable cluster notifications on a new cluster, perform the following:
1. Go to the **Google Kubernetes Engine** page in the Google Cloud console. Go to Google Kubernetes Engine 1. Click add_box **Create**.- On the Create cluster dialog, next to GKE Standard, click Configure.
- In the navigation pane, in the Cluster section, click Automation.
- Select the Enable notifications checkbox.
- From the drop-down list, select the Pub/Sub topic you created.
To filter notifications, select the Filter notification types checkbox, and then select the notification types you want to receive.
Continue to configure the cluster as desired.
Click Create.
After enabling notifications, create a Pub/Sub subscription for your topic.
Enable cluster notifications on an existing cluster
You can enable GKE cluster notifications on an existing cluster using the Google Cloud CLI or Google Cloud console.
gcloud
To enable cluster notifications on an existing cluster, run the following command:
gcloud container clusters update CLUSTER_NAME \
--region=COMPUTE_REGION \
--notification-config=pubsub=ENABLED,pubsub-topic=projects/PROJECT_ID/topics/TOPIC_NAME,filter=NOTIFICATION_TYPE
Replace the following:
CLUSTER_NAME
: the name of your cluster.COMPUTE_REGION
: the compute region for your new cluster. For zonal clusters, use--zone=COMPUTE_ZONE
..PROJECT_ID
: your Google Cloud project ID.TOPIC_NAME
: the name of your Pub/Sub topic.NOTIFICATION_TYPE
: a pipe (|) delimited list of the notification types you want to receive. For example,filter="UpgradeEvent|SecurityBulletinEvent"
only sendsUpgradeEvent
andSecurityBulletinEvent
notifications, ignoring all other types.
Console
To enable cluster notifications on an existing cluster, perform the following:
Go to the Google Kubernetes Engine page in Google Cloud console.
Click the name of the cluster you want to modify.
In the Automation section, next to Notifications, click
Edit notifications.In the Edit notifications dialog, select the Enable notifications checkbox.
From the drop-down list, select the Pub/Sub topic you created.
To filter notifications, select the Filter notification types checkbox, and then select the notification types you want to receive.
Click Save changes.
After enabling notifications, create a Pub/Sub subscription for your topic.
Filter cluster notifications
You can filter notifications by notification type to ensure that you receive notifications that you want.
You can choose to filter notifications using the following methods:
- GKE: Specify values for
filter
in the--notification-config
flag, as shown in the previous examples for enabling cluster notifications. - Pub/Sub: Configure your Pub/Sub subscription to filter messages when you create a subscription.
Modify existing filters in GKE
To modify your existing GKE cluster notification filters, follow the
instructions in Enable notifications on an existing cluster
and specify the new notification types to filter in the gcloud
command
or select the new types in Google Cloud console.
Disable filters in GKE
You can disable your GKE notification filters and receive all notification types applicable to your cluster using the gcloud CLI or Google Cloud console.
gcloud
To disable filters using the gcloud CLI, run the following command:
gcloud container clusters update CLUSTER_NAME \
--region=COMPUTE_REGION \
--notification-config=pubsub=ENABLED,pubsub-topic=projects/PROJECT_ID/topics/TOPIC_NAME
Console
To disable filters using Google Cloud console, perform the following:
Go to the Google Kubernetes Engine page in Google Cloud console.
Click the name of the cluster you want to modify.
In the Automation section, next to Notifications, click
Edit notifications.In the Edit notifications dialog, clear the Filter notification types checkbox.
Click Save changes.
Verify setup for cluster notifications
To verify that notifications are set up correctly for your cluster, you can
initiate a node pool upgrade to see if an UpgradeEvent
message is sent. You
can only manually verify setup for the UpgradeEvent
notification type. If your
filters are configured to ignore this type, you won't see a message.
You can manually upgrade a specific node pool using the gcloud CLI or Google Cloud console. For instructions, refer to Manually upgrading a cluster or node pool. If you don't want to change the GKE version on your nodes, you can upgrade to the same version currently on the nodes.
After initiating the upgrade, check your Pub/Sub subscription for a notification message.
Disable cluster notifications
You can disable cluster notifications using the gcloud CLI or Google Cloud console.
gcloud
To disable notifications using the gcloud CLI, run the following command:
gcloud container clusters update CLUSTER_NAME \
--region=COMPUTE_REGION \
--notification-config=pubsub=DISABLED
Console
To disable notifications using Google Cloud console, perform the following:
Go to the Google Kubernetes Engine page in Google Cloud console.
Click the name of the cluster you want to modify.
In the Automation section, next to Notifications, click
Edit notifications.In the Edit notifications dialog, clear the Enable notifications checkbox.
Click Save changes.
Optionally, delete the Pub/Sub topic you created for notifications.
What's next
- Learn more about cluster notifications.
- Learn about configuring Pub/Sub notifications.
- Learn how to configure cluster notifications for third-party services.