How kubesphere/kubekey works
KubeKey is a task-flow automation tool, with Kubernetes installation and lifecycle management as a major use case. A user can invoke a built-in cluster workflow from the CLI; task templates and playbooks are executed through the task engine, which uses modules, variables, and node connectors to perform work. The repository also provides Kubernetes controllers for cloud-native batch management and a Web API/UI. Several subsystem links below are documented rather than source-verified: unsampled implementation details are not inferred as call relationships.
Main entry points: controller_manager.go Controller Manager · playbook_controller.go Playbook Controller · file_storage.go Resource Storage · task_executor.go Task Execution
Components 23
User Interfaces
- KK CLI
cmd/kk/app/root.go - Cluster Workflows
cmd/kk/app/builtin - Web API and UI
pkg/web/service.go
Task Workflow
- Task Projects
pkg/project/project.go - Playbook Model
api/project/v1/playbook.go - Task Converter
pkg/converter/converter.go
Execution Runtime
- Task Execution
pkg/executor/task_executor.go - Task Modules
pkg/modules/module.go - Variables
pkg/variable/variable.go - Node Connectors
pkg/connector/connector.go
Cluster Management
- Playbook Controller
pkg/controllers/core/playbook_controller.go - Inventory Controller
pkg/controllers/infrastructure/inventory_controller.go - KKCluster Controller
pkg/controllers/infrastructure/kkcluster_controller.go - KKMachine Controller
pkg/controllers/infrastructure/kkmachine_controller.go - Controller Manager
cmd/controller-manager/controller_manager.go
API and Storage
- Web Handlers
pkg/web/handler/resources.go - Resource Proxy
pkg/proxy/router.go - Resource Storage
pkg/proxy/internal/file_storage.go - Playbook Storage
pkg/proxy/resources/playbook/storage.go - Inventory Storage
pkg/proxy/resources/inventory/storage.go - Task Storage
pkg/proxy/resources/task/storage.go
Other components
- Operator
- Kubernetes API
Connections 22
- Operator → KK CLI: invokes
README.md - KK CLI → Cluster Workflows: selects workflow
- Operator → Web API and UI: uses UI
README.md - Cluster Workflows → Task Projects: loads templates
- Task Projects → Playbook Model: uses model
pkg/project/project.go - Task Execution → Task Converter: converts tasks
pkg/executor/task_executor.go - Task Execution → Task Modules: runs modules
pkg/executor/task_executor.go - Task Execution → Variables: resolves variables
pkg/executor/task_executor.go - Web API and UI → Web Handlers: routes requests
pkg/web/service.go - Web Handlers → Node Connectors: uses connectors
pkg/web/handler/resources.go - Controller Manager → Playbook Controller: registers
cmd/controller-manager/controller_manager.go - Controller Manager → Inventory Controller: registers
cmd/controller-manager/controller_manager.go - Controller Manager → KKCluster Controller: registers
cmd/controller-manager/controller_manager.go - Controller Manager → KKMachine Controller: registers
cmd/controller-manager/controller_manager.go - Playbook Controller → Kubernetes API: creates pods
pkg/controllers/core/playbook_controller.go - Inventory Controller → Playbook Controller: creates playbooks
pkg/controllers/infrastructure/inventory_controller.go - KKCluster Controller → Inventory Controller: manages inventory
pkg/controllers/infrastructure/kkcluster_controller.go - KKMachine Controller → Playbook Controller: creates playbooks
pkg/controllers/infrastructure/kkmachine_controller.go - Resource Proxy → Resource Storage: uses file storage
- Playbook Storage → Resource Storage: may persist locally
- Inventory Storage → Resource Storage: may persist locally
- Task Storage → Resource Storage: stores tasks locally