Member-only story
How to Deploy a Discord Bot on Kubernetes
Scope: Covers deployment of an existing Discord bot to Kubernetes. Does not cover bot development nor Kubernetes cluster setup.
Once you have several Discord bots launched, you might be in a position to colocate them in a Kubernetes (k8s) cluster to save on server costs. Or maybe, a bot you created is seeing a lot of growth and you need to horizontally scale it. Luckily, deploying a Discord bot to k8s is a straightforward process.
Namespace
The first thing you’ll want to do is create a namespace for your Discord bot. I like to use a different namespace for each bot’s environment, and in this article I’ll be using the canary
environment as an example. Ideally, once the canary deployment is up and running, you’d repeat these steps in a production
environment.
Let’s make a new file ./k8s/canary/namespace.yml
.
apiVersion: v1
kind: Namespace
metadata:
name: discord-bot-canary
And then apply it with kubectl apply -f k8s/canary/namespace.yml
.
Secrets
Next, we’ll need to store secrets so the bot can properly register with Discord’s websocket API. Go to the Discord Developer Portal and grab your bot’s “Discord Bot Token”.