How to: Create a Virtual Cluster
This guide walks through the various ways to create and manage virtual clusters in K3K. We’ll cover common use cases using both the Custom Resource Definitions (CRDs) and the K3K CLI, so you can choose the method that fits your workflow.
For full reference: * xref:/references/crds.adoc[CRD Reference Documentation] * xref:/references/k3kcli.adoc[CLI Reference Documentation] * xref:/advanced-usage.adoc[Full example]
| Some features are available only via the CRD interface. |
Use Case: Create and Expose a Basic Virtual Cluster
CRD Method
apiVersion: k3k.io/v1alpha1
kind: Cluster
metadata:
name: k3kcluster-ingress
spec:
tlsSANs:
- my-cluster.example.com
expose:
ingress:
ingressClassName: nginx
annotations:
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
nginx.ingress.kubernetes.io/ssl-redirect: "HTTPS"
This will create a virtual cluster in shared mode and expose it via an ingress with the specified hostname.
Use Case: Create a Virtual Cluster with Persistent Storage (Default)
CRD Method
apiVersion: k3k.io/v1alpha1
kind: Cluster
metadata:
name: k3kcluster-persistent
spec:
persistence:
type: dynamic
storageClassName: local-path
storageRequestSize: 30Gi
This ensures that the virtual cluster stores its state persistently with a 30Gi volume.
If storageClassName is not set it will default to the default StorageClass.
If storageRequestSize is not set it will request a 1Gi volume by default.
Use Case: Create a Highly Available Virtual Cluster in virtual mode
Use Case: Create a Virtual Cluster with a Custom Kubernetes Version
CRD Method
apiVersion: k3k.io/v1alpha1
kind: Cluster
metadata:
name: k3kcluster-custom-k8s
spec:
version: "v1.33.1-k3s1"
This sets the virtual cluster’s Kubernetes version explicitly.
| Only K3s distributions are supported. You can find compatible versions on the K3s GitHub release page. |
Use Case: Create a Virtual Cluster on specific host nodes
Use Case: Create a Virtual Cluster with a Rancher Host Cluster Kubeconfig
When using a kubeconfig generated with Rancher, you need to specify with the CLI the desired host for the virtual cluster kubeconfig.
By default, k3kcli uses the current host kubeconfig to determine the target cluster.
Use Case: Create a Virtual Cluster Behind an HTTP Proxy
CRD Method
apiVersion: k3k.io/v1alpha1
kind: Cluster
metadata:
name: k3kcluster-http-proxy
spec:
serverEnvs:
- name: HTTP_PROXY
value: "http://abc.xyz"
agentEnvs:
- name: HTTP_PROXY
value: "http://abc.xyz"
This configures an HTTP proxy for both servers and agents in the virtual cluster.
| This can be leveraged to pass any custom environment variables to the servers and agents, not just proxy settings. |