Deployment Overview of MicroK8s on Server¶
Prerequisites and Basic Requirements¶
The deployment requires a server running an Ubuntu-based operating system. The following conditions must be met before proceeding:
- The server must have
sudoprivileges or root access. - The
snapdpackage must be installed to manage MicroK8s. - The user executing the installation must be added to the
microk8sgroup to access cluster commands. - Network connectivity is required for downloading the MicroK8s snap package and enabling addons.
- Port
10443must be available on the host for accessing the Kubernetes Dashboard.
File and Directory Structure¶
The application utilizes the following directory structure for configuration and data storage:
/data/nginx/user_conf.d: Stores custom Nginx configuration files./etc/letsencrypt: Stores SSL certificates managed by Certbot (mounted from thenginx_secretsvolume)./snap/bin: Contains the MicroK8s binaries and thekubectlalias.
Application Installation Process¶
MicroK8s is installed as a snap package. The installation process involves the following steps:
- Update the
aptpackage index. - Install the
snapdpackage. - Install MicroK8s using the snap command with the
classicconfinement. - Add the current user to the
microk8sgroup to grant necessary permissions. - Enable the following MicroK8s addons:
dnshostpath-storagedashboard- Wait for the MicroK8s cluster to become ready.
- Create an alias for
microk8s.kubectltokubectlfor simplified command usage.
The specific command to install MicroK8s is:
Access Rights and Security¶
Access to the MicroK8s cluster is restricted to users within the microk8s group. The following security measures are implemented:
- The user is explicitly added to the
microk8sgroup using theusercommand. - The Kubernetes Dashboard is accessed via a port-forwarding mechanism on port
10443. - Access to the Dashboard requires a generated token. The token is created using the command:
- The Dashboard is exposed locally by forwarding the
kubernetes-dashboardservice from thekube-systemnamespace:
Docker Containers and Their Deployment¶
A Docker container for Nginx is deployed using Docker Compose. The container is configured with the following specifications:
- Image:
jonasal/nginx-certbot:latest - Restart Policy:
unless-stopped - Network Mode:
host - Environment Variables:
CERTBOT_EMAIL: Set to[email protected]- Additional variables are loaded from the file
/data/nginx/nginx-certbot.env. - Volumes:
nginx_secrets: An external volume mounted to/etc/letsencryptfor SSL certificate storage./data/nginx/user_conf.d: Mounted to/etc/nginx/user_conf.dfor custom configurations.
The deployment is managed via the compose.yml file located in the project directory.
Proxy Servers¶
The Nginx container acts as a reverse proxy and handles SSL certificate management via Certbot. The configuration includes:
- SSL Certificates: Managed by Certbot and stored in the
nginx_secretsvolume at/etc/letsencrypt. - Custom Domains: Configured within the files located in
/data/nginx/user_conf.d. - Email Notification: Certificate renewal notifications are sent to
[email protected].
Starting, Stopping, and Updating¶
MicroK8s services are managed using the microk8s command-line interface. The following commands are used for cluster management:
- Check Cluster Status:
- Enable Addons:
- Manage Kubernetes Resources: Use the
kubectlalias (linked tomicrok8s.kubectl) for standard Kubernetes operations. - Docker Container Management: The Nginx container is managed via Docker Compose commands (e.g.,
docker compose up,docker compose down) based on thecompose.ymlconfiguration.