This repository has been archived and is no longer actively maintained.
If you have questions or need information about this project, please contact: tim@kartoza.com
This directory sets up a simple Kubernetes environment using Minikube with Podman, featuring a Flask server that serves a "Hello World" page. This setup uses Nix and Direnv to automatically activate the environment.
Ensure you have Nix, Direnv, and Podman installed on your system.
-
Edit your
configuration.nixto include the following settings:{ # Note mutually exclusive with the docker service environment.systemPackages = with pkgs; [ podman docker-compose ]; virtualisation = { podman = { enable = true; # Create a `docker` alias for podman, to use it as a drop-in replacement dockerCompat = true; # Required for containers under podman-compose to be able to talk to each other. defaultNetwork.settings = { dns_enabled = true; }; }; }; # Other configuration settings... # Set kernel parameters boot.kernelParams = ["unprivileged_userns_clone=1"]; # Set sysctl settings boot.kernel.sysctl."kernel.unprivileged_userns_clone" = true; # Enable Podman socket for rootless mode systemd.user.services.podman = { description = "Podman API Socket"; serviceConfig = { ExecStart = "${pkgs.podman}/bin/podman system service --time=0"; Restart = "always"; ExecStartPost = "-${pkgs.podman}/bin/podman info"; }; wantedBy = ["default.target"]; }; # Add Polkit rule to allow users in the wheel group to manage services environment.etc."polkit-1/rules.d/10-wheel-group.rules".text = '' polkit.addRule(function(action, subject) { if (action.id == "org.freedesktop.systemd1.manage-units" && subject.isInGroup("wheel")) { return polkit.Result.YES; } }); ''; }
-
Apply the configuration:
sudo nixos-rebuild switch
-
Clone the repository and navigate into the directory:
git clone <your-repo-url> cd <your-repo-directory>
-
Allow Direnv to load the environment:
direnv allow
-
Enter the directory:
Simply entering the directory will automatically start the Nix shell, Podman, Minikube, and deploy the Flask Helm chart.
To check the status of the pods:
kubectl get pods -AThis command lists all the pods running in your cluster, along with their status. It helps you verify if your application pods are running correctly.
To scale the Flask deployment to 3 replicas:
kubectl scale deployment flask-app --replicas=3This command scales the number of replicas (instances) of the Flask application. Scaling up increases the application's availability and load capacity.
To add more nodes to the Minikube cluster:
minikube node addThis command adds an additional node to your Minikube cluster, which can help distribute the workload and improve the cluster's resilience and capacity.
To restart the Flask service:
kubectl rollout restart deployment flask-appThis command restarts the deployment by rolling out a new version of the pods. It's useful for applying configuration changes or recovering from errors.
To check the logs of the Flask pod:
kubectl logs <flask-app-pod-name>Replace <flask-app-pod-name> with the actual name of the Flask pod. This command fetches the logs from a specific pod, which helps in debugging and monitoring the application.
To describe the Flask service and check its health:
kubectl describe service flask-appThis command provides detailed information about the Flask service, including its configuration, status, and events. It's useful for diagnosing issues with the service.
To stop the Minikube cluster:
minikube stopThis command stops all nodes in the Minikube cluster. It's useful for conserving resources when the cluster is not needed.
To delete the Flask deployment:
helm uninstall flask-appThis command removes the Flask application deployed via Helm. It cleans up all associated resources like pods, services, and configuration.
Forward a local port to the Flask application's service port:
kubectl port-forward svc/flask-app 8080:80You should now be able to access the Flask application at http://localhost:8080.
Alternatively, you can use Minikube's tunnel to expose the service:
minikube tunnel- Ensure Podman is running on your machine, as Minikube requires a container runtime to function properly.
- The Flask application runs on port 8080 by default. Adjust the configuration if needed.
- Use the
kubectlcommands provided to manage and monitor your Kubernetes cluster effectively.
shell.nix: Nix shell configuration to set up the environment..envrc: Direnv configuration to automatically activate the Nix shell.values.yaml: Helm values file for the Flask application.flask_app/app.py: Simple Flask application.flask_app/Dockerfile: Dockerfile to build the Flask application image.
This README.md file provides comprehensive instructions on setting up and managing the Kubernetes cluster with the Flask application, including detailed explanations of each management action.