Setting up Minikube to simulate your own Kubernetes cluster locally

Rationale

Minikube is a good way to learn Kubernetes using your local machine. Most of the time, you only have to learn Kubernetes when you’re working on large-scale projects that requires more complex deployment strategies. In this guide, I’ll walk you through on how to set up Minikube and Kubectl for a more hands-on approach in exploring concepts in Kubernetes.

Initial Installations

First is to follow the instructions on installing Docker, Minikube and Kubectl, so you can interact with your clusters and pods using the terminal or command line (CLI). If you’re a beginner like me then you might be looking for a Graphical User Interface (GUI) to manage these clusters, but we won’t be doing that because learning how to interact with systems in terminal is an ideal skill to have.

Setting-up your pods and clusters

One of the first problems I faced when setting up my Windows computer is Docker’s configurations. Make sure that Docker is running, and enter the following to the terminal.

docker context use default

After doing so, you can start Minikube with the following command. This will create a container locally that will allow you to run your images later on.

minikube start

If you are using Windows, you have to enter the following so that it will allow your CLI to ssh inside Minikube when needed.

minikube -p minikube docker-env --shell powershell | Invoke-Expression

To build the three images, the databases and the flask app, simply enter this command where it will look into the docker-compose.yaml

docker build -t merchantextras-minikube-2 .

To check if your images after building it, you can ssh inside Minikube

minikube ssh

and enter this once your in the root to check if the images are present

docker images

Once the images are present, you can exit the ssh session by typing ‘exit’. The following command will apply your deployments which will generate the deployment, service and configs.

kubectl apply -f main-deployment.yaml

view if configmap was created

kubectl get configmap

To restart, delete the active pod

kubectl delete pod <pod-name>
kubectl apply -f merchant-extras-deployment.yaml

Connecting to localhost db

minikube ssh

Use Putty to start database connections, then check in minikube if the connections are available

nc -vz host.minikube.internal 9093

Get the pod name

kubectl get pod

View configmap in yaml form

kubectl get configmap <configmap-name> -o yaml

Expose pod for services

kubectl expose pod <pod-name>

View if the service is available, and take not of the name

kubectl get service

Edit the service yaml

kubectl edit service <service-name>

View the service and take note of the ports

kubectl get service

To get the accessible URL to make requests get the URL

minikube service <service-name> --url
docker-compose build

And you're done!