How to deploy an application with a MongoDB database in Kubernetes

Read on Russian

Recently, CodeX hosted a Kubernetes meetup. Unfortunately, it's difficult to master the technology on the run. So, I decided to take a close to reality task and gain experience on my own.

Problem details

CodeX team has a Codex.Bot project – this is our smart assistant that reports in Telegram chat about new GitHub commits, reminds about open tasks, sends website visit statistics and notifications about new errors.

The project has been running for 5 years without significant code changes. But recently our team finally wrapped it in a Docker image.

Now our task is to run it in a Kubernetes cluster.

We will deploy the core of the bot. It uses the following services:

Software installation

Let's download the following software:

By default, this article provides commands and instructions for MacOS.

Minikube

First of all, we need Kubernetes itself. For the first experience, it is enough to install a local minikube.

curl -LO <https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64> sudo install minikube-darwin-amd64 /usr/local/bin/minikube minikube start

Commands for installation on Linux:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo install minikube-linux-amd64 /usr/local/bin/minikube

In the console you will see something like:

😄 minikube v1.25.1 на Darwin 12.0.1 ✨ Automatically selected the docker driver. Other choices: hyperkit, virtualbox, ssh 👍 The control plane starts a minikube node in a minikube cluster 🚜 Downloading base image... 🔥 Creating docker container (CPUs=2, Memory=2200MB) ... 🐳 Preparing Kubernetes v1.23.1 on Docker 20.10.12 ... ▪ kubelet.housekeeping-interval=5m ▪ Generating certificates and keys ... ▪ Booting up control plane ...

Kubectl

Next, we need kubectl to execute commands in Kubernetes:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl" chmod +x ./kubectl sudo mv ./kubectl /usr/local/bin/kubectl sudo chown root: /usr/local/bin/kubectl

Commands for installation on Linux and another OS:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

Let's run the kubectl get nodes command and check that it picked up the node running in minikube.

NAME STATUS ROLES AGE VERSION minikube Ready control-plane,master 106m v1.23.1

Lens

We often need to look inside the cluster. In order not to suffer with various kubernetes-dashboards, let's download a much more convenient tool: Lens. It will allow us:

Lens interface

After installation, it will be enough to run the program and find the minikube cluster there. For convenience, you can pin it in the left menu.