Google Home Action to manage your Kubernetes cluster
Alex Pliutau
Posted on September 2, 2019
I always wanted to find a good use case of Google Home to make some DevOps tasks funnier. For example voice deployments, system metrics, etc. Since I use Kubernetes a lot, I thought it would be fun to control it via voice commands.
So I decided to develop this Action with the following goals in mind:
- Action should be able to work with any Kubernetes cluster: GKE, EKS, etc.
- Extensible commands
- Intuitive voice UX
- Easy installation
I already published this project on Github (google-home-k8s), and here I'll show you how to deploy it.
How it all works
The diagram below shows the flow from the user device to Dialogflow to our API deployed to App Engine (could be deployed somewhere else) to our Kubernetes cluster.
Let's review some of the components:
- Dialogflow is a development suite for creating conversational interfaces. Here we will set up the user flow and specify all available voice commands, intents, and entities.
- Voice commands will call our API deployed to App Engine.
- Depends on the command, API will call Kubernetes API.
Installation
kubeconfig
I assume that you already have a Kubernetes cluster running somewhere. I will use my GKE cluster for the demo purpose.
First of all, we have to generate a valid kubeconfig
configuration file which will be used by our API for authentication.
Let's clone our project and use a script I prepared to generate the kubeconfig
. Before doing this make sure that your kubectl
points to right config and you have necessary permissions in this cluster.
git clone git@github.com:plutov/google-home-k8s.git
cd google-home-k8s
./generate-kubeconfig.sh
It will generate a ./build/kubeconfig
file which will be used by API later, this configuration never expires.
Deploy API
Now you can deploy the API somewhere, I will use Google App Engine for this purpose. API requires few env. variables to be set such as NAMESPACE
, API_KEY
and LOG_LEVEL
.
cp env.sample.yaml env.yaml
API is protected by static API Key which should be set in env.yaml
. To access API, the client should send Authorization: Bearer ${API_KEY}
header.
gcloud app deploy
Copy the URL of your API.
Dialogflow
google-home-k8s already contains a Dialogflow configuration which can be easily imported.
- Go to Dialogflow Console
- Select or create a new agent
- Go to Settings -> Export and Import
- Select Import From Zip (import this file google-home-k8s.zip)
- Go to Fulfillment
- Enable Webhook
- Paste URL to API deployed to App Engine
- Add Header. Key:
Authorization
, Value:Bearer API_KEY
(replaceAPI_KEY
with the value fromenv.yaml
)
Test
Go to Google Assistant, give your Action a name "Kubernetes Manager" and click "Test" which will open a Simulator.
If everything was done correctly you'll be able to reproduce the following conversation:
Example conversation:
[you] Hey Google, talk to Kubernetes Manager
[assistant] Welcome to Kubernetes Manager. How can I help you?
[you] Scale statefulset "redis"
[assistant] Got it. Currently, there are 3 replicas of the "redis" statefulset. To how many replicas do you want to scale?
[you] 5
[assistant] Statefulset has been updated. Anything else?
If you have Google Home device you can do same conversation there.
Conclusion
I don't suggest to publish this Google Home Action, but rather use it from the single device authenticated with the same user as in Google Assistant. Unless you want to make your Kubernetes cluster public :)
Also, feel free to contribute to the project on Github to add more commands.
Posted on September 2, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.