| name | kubekey |
| description | KubeKey (kk) Usage Guide. For Kubernetes cluster lifecycle management including creation, scaling and deletion.
Use this skill whenever the user mentions kubekey, kk commands, cluster setup, cluster management, adding nodes,
deleting nodes, creating inventory files, configuring clusters, installing Kubernetes, or deploying K8s.
Also use this skill when the user asks about inventory.yaml, config.yaml formats, CNI configuration, container runtime setup,
offline installation, or artifact operations. Provides detailed guidance on kk subcommand usage, config file formats, inventory structure and common workflows.
|
KubeKey Skill
KubeKey is a lightweight Kubernetes cluster lifecycle management tool for creating, scaling and deleting clusters.
Installation
Binary Installation
curl -sfL https://get-kk.kubesphere.io | KK_ONLY=true sh -
curl -sfL https://github.com/kubesphere/kubekey/releases/download/v4.0.5/downloadKubekey.sh | KK_ONLY=true sh -
curl -sfL https://get-kk.kubesphere.io | KK_ONLY=true KKZONE=cn sh -
Windows: Use WSL or download from GitHub Releases
The script downloads kk binary to current directory. Move it to a directory in your $PATH:
sudo mv kk /usr/local/bin/
kk version
Quick Start
1. Basic Cluster Creation Flow
kk create inventory -o inventory.yaml
kk create config --with-kubernetes v1.33.7 -o config.yaml
kk create cluster -i inventory.yaml -c config.yaml
kk create cluster -i inventory.yaml --with-kubernetes v1.33.7
kk create config Command
Generates default config.yaml with cluster software configuration (K8s version, network, storage, etc.).
Common Parameters:
| Parameter | Description | Example |
|---|
--with-kubernetes | Specify Kubernetes version | --with-kubernetes v1.33.7 |
-o, --output | Output file path | -o config.yaml |
Generated Config Structure:
kubernetes: K8s version, cluster name, API Server, etc.
cni: CNI plugin, Pod/Service CIDR
cri: Container runtime configuration
storage: Storage class configuration
image_registry: Image registry configuration
kk create inventory Command
Generates default inventory.yaml file.
Parameters:
| Parameter | Description | Example |
|---|
-o, --output | Output file path | -o inventory.yaml |
The generated inventory contains template nodes that need to be edited with actual node information.
kk create cluster Command
Creates cluster based on inventory and config.
Two methods:
kk create cluster -i inventory.yaml -c config.yaml - Use config file
kk create cluster -i inventory.yaml --with-kubernetes v1.33.7 - Use default config for K8s version (no file generated)
Common Parameters:
| Parameter | Description |
|---|
-i, --inventory | Inventory file path |
-c, --config | Config file path |
--with-kubernetes | Specify K8s version directly (uses default config, no file generated) |
-f, --force | Force execution (overwrite existing config) |
-v | Log level (klog mechanism, higher number = more verbose) |
Inventory File
For detailed format and examples, see: references/inventory.md
Includes:
- Complete inventory examples
- SSH/local connector configuration
- Host variables (IP, labels, taints)
- Group definitions
- HA cluster multi-node examples
Complete Config Reference
For detailed configuration, see: references/config.md
Includes:
- Basic structure (cluster_require, certs, image_registry, native)
- Kubernetes configuration (apiserver, controller-manager, scheduler, kubelet, kube-proxy)
- CNI network configuration (calico, cilium, flannel, kubeovn)
- CRI container runtime configuration
- etcd configuration (internal/external)
- DNS configuration (CoreDNS, NodeLocalDNS)
- Storage class configuration (local, nfs)
- Image registry configuration (harbor, docker-registry)
- Complete configuration examples
Command Reference
Generate Config
kk create inventory -o inventory.yaml
kk create config --with-kubernetes v1.33.7 -o config.yaml
Init (optional, can be merged into create cluster)
kk init os -i inventory.yaml -c config.yaml
kk init registry -i inventory.yaml -c config.yaml
kk precheck -i inventory.yaml -c config.yaml
kk precheck etcd os network cri nfs -i inventory.yaml -c config.yaml
Create Cluster
kk create cluster -i inventory.yaml -c config.yaml
kk create cluster -i inventory.yaml --with-kubernetes v1.33.7
Add Nodes
Step 1: Define new node in inventory.yaml hosts section
Step 2: Add to corresponding groups
kk add nodes -i inventory.yaml -c config.yaml
kk add nodes -i inventory.yaml -c config.yaml --control-plane node2,node3 --worker node4,node5
Delete Nodes
kk delete nodes node1 node2 -i inventory.yaml -c config.yaml
Update Certificates
kk certs renew -i inventory.yaml -c config.yaml
Delete Cluster
kk delete cluster -i inventory.yaml -c config.yaml
Offline Installation (Artifact)
For air-gapped environments, use artifact commands to manage offline packages:
kk artifact export --with-kubernetes v1.33.7 -c config.yaml
kk artifact images -i inventory.yaml -c config.yaml --push
kk artifact images -i inventory.yaml -c config.yaml --pull
How to Help Users
When a user asks about KubeKey or cluster operations, follow this approach:
- Identify the goal: Determine if they want to create, scale, delete or configure a cluster.
- Check prerequisites: Ask for node information (IPs, SSH credentials, roles) if creating or scaling a cluster.
- Guide step by step: Direct them to generate templates first (
kk create inventory/config), edit files, then execute.
- Point to references: For specific config options (CNI, CRI, storage), direct them to
references/config.md.
- Verify with precheck: Recommend running
kk precheck before cluster creation to avoid failures.
Common Workflows
Cluster Creation Process
Important: Collect node information first before starting.
Step 1: Collect Node Information
Prepare the following information:
| Field | Description | Example |
|---|
| Node Name | Unique identifier | node1, master1, worker1 |
| IP Address | Node network address | 192.168.1.10 |
| SSH Port | Default 22 | 22 |
| SSH User | Login username | root |
| Auth Method | Password or private key path | password: "xxx" or private_key: ~/.ssh/id_rsa |
| Node Role | control_plane/worker/etcd | Choose based on requirements |
Step 2: Generate Inventory Template
kk create inventory -o inventory.yaml
Step 3: Edit inventory.yaml
Fill in node information into inventory.yaml, refer to format in references/inventory.md.
Step 4: Generate Config
Generate config.yaml based on your desired configuration.
For specific configuration examples tailored to your Kubernetes version, CNI plugin, storage type, etc., refer to references/config.md.
kk create config --with-kubernetes v1.33.7 -o config.yaml
Step 5: Create Cluster
kk create cluster -i inventory.yaml -c config.yaml
kk create cluster -i inventory.yaml --with-kubernetes v1.33.7
Create HA Cluster
inventory.yaml needs to contain:
- 3 etcd nodes
- 3 control plane nodes
- Multiple worker nodes
Troubleshooting
Common Issues
- SSH connection failed: Check SSH configuration in inventory
- Node does not meet requirements: Run
kk precheck for details
Debug Mode
Use -v parameter to specify log level (klog mechanism, higher number = more verbose):
kk create cluster -i inventory.yaml -c config.yaml -v 5
macOS Compatibility
When running kk on macOS, you may encounter the following issues due to the default zsh shell and macOS sudo configuration:
1. zsh: no matches found: *.sh
Symptom: Playbook fails with glob pattern errors like:
zsh:1: no matches found: /etc/kubekey/scripts/pre_install_*.sh
Root Cause: macOS default shell is zsh, which has different glob behavior from bash.
Fix: Set SHELL to bash before running kk commands:
export SHELL=/bin/bash
kk create cluster -i inventory.yaml -c config.yaml
2. command not found: mkdir
Symptom: Commands like mkdir or rm fail on localhost with:
zsh:4: command not found: mkdir
Root Cause: macOS sudo's secure_path is /usr/local/bin by default, which does not include /bin where mkdir is located.
Fix: Update sudo secure_path to include standard directories. On macOS, visudo is at /usr/sbin/visudo:
sudo /usr/sbin/visudo
Note: The sudoers change takes effect immediately and persists across reboots. Revert after use if desired.
Get Help
kk --help
kk create cluster --help
kk add nodes --help
kk version