Docker and Kubernetes Deployment
Relevant source files
The following files were used as context for generating this wiki page:
Casdoor provides robust containerization support to facilitate streamlined deployment across various environments. The project includes configurations for Docker, Docker Compose, and Kubernetes, enabling developers to package the application with its dependencies and orchestrate its execution in production-grade clusters.
This deployment framework ensures that the IAM gateway and authentication server can be initialized consistently, whether using local container runtimes or managed cloud platforms. It handles critical aspects such as service discovery, persistent storage via volume mounts, and environment configuration through shell scripting and YAML manifests.
Docker Deployment Architecture
The Docker deployment strategy centers around a multi-service architecture typically managed via Docker Compose. The primary application container runs the Casdoor binary, which is configured to interact with backend services like databases (e.g., MySQL).
Container Initialization Flow
When a Casdoor container starts, it utilizes an entrypoint script to verify the runtime environment and prepare the application.
The entrypoint script ensures that if the application is running in a Docker environment, it attempts to populate the /conf directory with necessary configuration files if they are missing.
Sources: docker-entrypoint.sh:1-12
Service Configuration
The project utilizes docker-compose.yml to define the relationship between the application and its database.
| Service | Image | Ports | Dependencies |
|---|---|---|---|
db | mysql:8.0 | 3306:3306 | None |
casdoor | casbin/casdoor-all-in-one | 8000:8000 | db |
Sources: docker-compose.yml:4-28
Kubernetes Orchestration
Casdoor supports deployment in Kubernetes clusters using standard resource manifests. This allows for scaling, automated rollouts, and integration with cluster-native features like LoadBalancers or NodePorts.
Core Kubernetes Components
The deployment is structured into two primary Kubernetes objects: a Service for networking and a Deployment for workload management.
The Kubernetes configuration defines a NodePort service to expose the application on port 8000. The deployment is configured with a single replica by default unless a distributed cache like Redis is utilized.
Sources: k8s.yaml:4-19, k8s.yaml:26-36
Storage and Environment
Persistent configuration is managed through hostPath volumes, mapping the container's /conf directory to the host's /conf path.
- Environment Variables: The container is flagged with
RUNNING_IN_DOCKER="true"to trigger Docker-specific logic within the application. - Image Policy: Set to
Alwaysto ensure thelatesttag ofcasbin/casdooris consistently pulled.
Sources: k8s.yaml:44-59
Build and Initialization Scripts
The deployment process is supported by utility scripts that automate the creation of artifacts and the preparation of the container filesystem.
Artifact Generation
The build.sh script automates the compilation of the application for containerization. It performs the following steps:
- Navigates to the
web/directory. - Executes
yarn installandyarn build. - Navigates back to the root to compile the Go backend into an executable named
server.
Sources: build.sh:1-10
Entrypoint Logic
The docker-entrypoint.sh script acts as a safeguard for volume-mounted configurations.
if [ "$RUNNING_IN_DOCKER" = "true" ]; then
if [ -d "/conf" ]; then
if [ ! -f "/conf/app.conf" ]; then
cp /conf_default/* /conf
fi
fi
fi
exec ./server
This logic ensures that if a user mounts an empty volume to /conf, the default configuration files are copied into it before the server starts, preventing initialization failures.
Sources: docker-entrypoint.sh:4-12
Deployment Summary Paragraph
Deploying Casdoor involves leveraging containerization tools to maintain environmental parity. Through Docker Compose, the system orchestrates a multi-container environment with automated database provisioning. In Kubernetes, the application is defined via declarative YAML manifests that handle port exposure through NodePort services and configuration persistence through volume mounts. The combination of shell-based entrypoints and build scripts ensures that the compiled frontend and backend are correctly integrated and configured for cloud-native operation.
Sources: README.md:83-85, k8s.yaml:1-62, docker-compose.yml:1-35