This is unreleased documentation for SUSE® Virtual Clusters v1.3.0 (Dev).

How to: Create a Virtual Cluster

This guide provides instructions on creating and managing virtual clusters in K3k and covers 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/v1beta1
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 creates a virtual cluster in shared mode and expose it via an ingress with the specified host name.

Use Case: Create a Virtual Cluster with Persistent Storage (Default)

CRD Method

apiVersion: k3k.io/v1beta1
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.

CLI Method

k3kcli cluster create \
  --persistence-type dynamic \
  --storage-class-name local-path \
  --storage-request-size 30Gi \
  k3kcluster-persistent

Use Case: Create a Highly Available Virtual Cluster in shared mode

CRD Method

apiVersion: k3k.io/v1beta1
kind: Cluster
metadata:
  name: k3kcluster-ha
spec:
  servers: 3

This will create a virtual cluster with 3 servers and a default 1Gi volume for persistence.

CLI Method

k3kcli cluster create \
  --servers 3 \
  k3kcluster-ha

Use Case: Create a Highly Available Virtual Cluster in virtual mode

CRD Method

apiVersion: k3k.io/v1beta1
kind: Cluster
metadata:
  name: k3kcluster-virtual
spec:
  mode: virtual
  servers: 3
  agents: 3

This will create a virtual cluster with 3 servers and 3 agents and a default 1Gi volume for persistence.

Agents exist ONLY for virtual mode.

CLI Method

k3kcli cluster create \
  --agents 3 \
  --servers 3 \
  --mode virtual \
  k3kcluster-virtual

Use Case: Create a Virtual Cluster in hcp (Hosted Control Plane) mode

In hcp mode the K3k controller runs an agentless K3s control plane in the host cluster, and you join your own external worker nodes via the standard K3s installer. See the full walkthrough — including how to fetch the join token and run the installer on workers — in Creating an HCP Virtual Cluster.

CRD Method

apiVersion: k3k.io/v1beta1
kind: Cluster
metadata:
  name: k3kcluster-hcp
spec:
  mode: hcp
  tlsSANs:
    - "<externally-reachable-node-ip-or-dns>"
  expose:
    nodePort: {}

An externally reachable endpoint (expose.nodePort, expose.loadBalancer, or expose.ingress) and a non-loopback entry in tlsSANs are required so that external workers can reach the apiserver.

CLI Method

k3kcli cluster create \
  --mode hcp \
  --tls-sans <externally-reachable-node-ip-or-dns> \
  k3kcluster-hcp

Use Case: Create an Ephemeral Virtual Cluster

CRD Method

apiVersion: k3k.io/v1beta1
kind: Cluster
metadata:
  name: k3kcluster-ephemeral
spec:
  persistence:
    type: ephemeral

This will create an ephemeral virtual cluster with no persistence and a single server.

CLI Method

k3kcli cluster create \
  --persistence-type ephemeral \
  k3kcluster-ephemeral

Use Case: Create a Virtual Cluster with a Custom Kubernetes Version

CRD Method

apiVersion: k3k.io/v1beta1
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.

CLI Method

k3kcli cluster create \
  --version v1.33.1-k3s1 \
  k3kcluster-custom-k8s

Use Case: Create a Virtual Cluster with Custom Resource Limits

CRD Method

apiVersion: k3k.io/v1beta1
kind: Cluster
metadata:
  name: k3kcluster-resourced
spec:
  mode: virtual
  serverLimit:
    cpu: "1"
    memory: "2Gi"
  workerLimit:
    cpu: "1"
    memory: "2Gi"

This configures the CPU and memory limit for the virtual cluster.

CLI Method

No CLI method available yet

Use Case: Create a Virtual Cluster with a specific server node affinity

CRD Method

apiVersion: k3k.io/v1beta1
kind: Cluster
metadata:
  name: k3kcluster-server-affinity
spec:
  mode: virtual
  serverAffinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: topology.kubernetes.io/zone
            operator: In
            values:
            - antarctica-east1
            - antarctica-west1
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: another-node-label-key
            operator: In
            values:
            - another-node-label-value

CLI Method

No CLI method available yet

Use Case: Create a Virtual Cluster with a specific agent pod affinity

CRD Method

apiVersion: k3k.io/v1beta1
kind: Cluster
metadata:
  name: k3kcluster-agent-affinity
spec:
  mode: virtual
  agentAffinity:
    podAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: security
            operator: In
            values:
            - S1
        topologyKey: topology.kubernetes.io/zone
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 100
        podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: security
              operator: In
              values:
              - S2
          topologyKey: topology.kubernetes.io/zone

CLI Method

No CLI method available yet

Use Case: Create a Virtual Cluster on specific host nodes

CRD Method

apiVersion: k3k.io/v1beta1
kind: Cluster
metadata:
  name: k3kcluster-node-placed
spec:
  nodeSelector:
    disktype: ssd

This places the virtual cluster on nodes with the label disktype: ssd.

In shared mode, workloads are also scheduled on the selected nodes.

CLI Method

No CLI method available yet

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.

CRD Method

Not applicable

CLI Method

k3kcli cluster create \
  --kubeconfig-server https://abc.xyz \
  k3kcluster-host-rancher

Use Case: Create a Virtual Cluster Behind an HTTP Proxy

CRD Method

apiVersion: k3k.io/v1beta1
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.

CLI Method

k3kcli cluster create  \
  --server-envs HTTP_PROXY=http://abc.xyz \
  --agent-envs HTTP_PROXY=http://abc.xyz \
  k3kcluster-http-proxy

How to: Connect to a Virtual Cluster

Once the virtual cluster is running, you can connect to it using the CLI:

CLI Method

k3kcli cluster create adds the virtual cluster to your current kubeconfig as a context named <namespace>/<name>. Switch to this context to access the virtual cluster with kubectl:

kubectl config use-context k3k-mycluster/mycluster
kubectl get nodes

If the context is missing, for example because you created the cluster with a Cluster resource, add it with k3kcli kubeconfig generate:

k3kcli kubeconfig generate --no-out k3k-mycluster/mycluster

If you need a standalone kubeconfig file, for example to share access to the virtual cluster, add --out <path> to the command. For more information, see Managing kubeconfig contexts.