Introduction
In the previous post, the Minikube cluster and the GitLab CI-pipeline were configured. The application has been chosen as the object around which the architecture will be built. Before making the application publicly vailable, I would like to test it locally first.
I followed the instructions from the official Minikube website, but ran into a bit of difficulty at the very end (see below).
So the cluster is already working, ArgoCD is working, and now I need to create a local domain for the application and configure additional functionality.
Updating the application
In order to expose application Dockerfile and app.py have to be modified.
Contents of Dockerfile (port 5000 exposed):
# Base image
FROM python:3.12-slim-bullseye
# Set the working directory
WORKDIR /usr/src/app
# Copy the requirements file
COPY requirements.txt .
RUN pip install -r requirements.txt
# Copy the application code
COPY . .
# Expose the application port
EXPOSE 5000
# Start the application
CMD ["python", "frontend/app.py"]
The contents of app.py:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def entry():
"""
Main path
"""
return "PerceptiView"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000, debug=True)
If the application is opened now, it should display only the word PerceptiView.
The application has two logical parts – the frontend with the Flask server and the backend with the object detection scripts:
Updated workflow from .gitlab-ci.yaml:
workflow:
rules:
- changes:
- frontend/**/*
- backend/**/*
Additional manifests for the program
In order to expose the application one has to add three Helm manifests of ingress and two services (example taken from here).
Contents of ingress.yaml (host perceptiview.test):
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: perceptiview
namespace: {{ .Values.namespace }}
spec:
ingressClassName: nginx
rules:
- host: perceptiview.test
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: perceptiview
port:
number: 80
Contents of service.yaml (targetport 5000, the same as in the Dockerfile):
apiVersion: v1
kind: Service
metadata:
name: perceptiview
namespace: {{ .Values.namespace }}
spec:
ports:
- name: http
port: 80
targetPort: 5000
protocol: TCP
type: NodePort
selector:
app: {{ .Values.label }}
Contents of service-external.yaml:
apiVersion: v1
kind: Service
metadata:
name: perceptiview
namespace: kube-system
spec:
type: ExternalName
externalName: perceptiview.default.svc.cluster.local
These manifests are added to existing templates already in place for the application.
After adding the manifests to the GitLab repository, the application in ArgoCD can be synchronized:
As one can see, new objects have appeared. 1
The application itself is ready and and is accessible on a different port 2:
Activating of DNS service on Minikube cluster
Now DNS service has to be activated.
Enable the addons:
minikube addons enable ingress
minikube addons enable ingress-dns
The output must be similar to:
I am using Linux and my domain name resolver configuration is systemd-resolved:
sudo mkdir -p /etc/systemd/resolved.conf.d
Adding .test domain to /etc/systemd/resolved.conf.d/minikube.conf:
[Resolve]
DNS=$(minikube ip)
Domains=~test
Restarting systemd-resolved:
sudo systemctl restart systemd-resolved
Editing CoreDNS config:
kubectl edit configmap coredns -n kube-system
Adding block for .test local domain:
test:53 {
errors
cache 30
forward . 192.168.59.100
}
Additional steps:
In the Minikube documentation, there is a testing phase where I only had the following command working:
nslookup perceptiview.test $(minikube ip)
Server: 192.168.59.100
Address: 192.168.59.100#53
Non-authoritative answer:
Name: perceptiview.test
Address: 192.168.59.100
Name: perceptiview.test
Address: 192.168.59.100
Initially the curl and ping commands did not produce the desired result. There is no further advice in the documentation on what to do if the address is not resolved.
I realized that depending on the driver the Minikube is initially started with, the cluster requires different settings. The steps suggested here didn’t work for me and the application still was not available at perceptiview.test
The solution was found in the article of official Kubernetes documentation:
Add the line to the bottom etc-hosts3 file on your computer (you will need administrator access):
Look up the external IP address as reported by minikube
minikube ip
172.17.0.15 hello-world.example
By adding the line 192.168.59.100 perceptiview.test to etc-hosts, the app became available:
Now the ping and curl commands are also working:
- By the time this screenshot was taken, addons were already activated, so ingress is shown here in green. Without addons it should be in pending mode ↩︎
- The application is available at MinikubeIP:NodePort as soon as a service with the NodePort type is added and the port is exposed in the Dockerfile. ↩︎
- I ran into issue here – by writing the path etc-hosts with slashes, this article cannot be saved. It might be a security mechanisum on WordPress. ↩︎