Virtual Cluster Template
Virtual Cluster templates can be used to create virtual clusters that have already certain applications deployed inside them or other predefined configuration applied. They are a powerful tool to create new predefined environments on demand.
Example Virtual Cluster Template
An example Virtual Cluster Template:
apiVersion: management.loft.sh/v1
kind: VirtualClusterTemplate
metadata:
creationTimestamp: null
name: my-virtual-cluster-template
spec:
access:
- users:
- '*'
verbs:
- get
description: This virtual cluster template deploys an isolated virtual cluster
displayName: Isolated Virtual Cluster Template
template:
accessPoint:
ingress: {}
helmRelease:
chart: {}
values: |-
# Below you can configure the virtual cluster
isolation:
enabled: true
# Checkout https://vcluster.com/docs for more config options
instanceTemplate:
metadata: {}
metadata: {}
pro: {}
spaceTemplate:
metadata: {}
status: {}
Virtual Cluster Template Reference
kind
required string
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
kind
required string apiVersion
required string
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
apiVersion
required string metadata
required object
metadata
required object spec
required object
spec
required object status
required object
status
required object Retrieve: Virtual Cluster Templates
You can either use curl or kubectl to retrieve Virtual Cluster Templates.
- kubectl
- curl
Retrieve a list of Virtual Cluster Templates
Run the following command to list all Virtual Cluster Templates:
kubectl get virtualclustertemplates.management.loft.sh -o yaml
Retrieve a single Virtual Cluster Template by name
Run the following kubectl command to get Virtual Cluster Template my-virtual-cluster-template
:
kubectl get virtualclustertemplates.management.loft.sh my-virtual-cluster-template -o yaml
Retrieve a list of Virtual Cluster Templates
Run the following curl command to list all Virtual Cluster Templates:
curl -s "https://$LOFT_DOMAIN/kubernetes/management/apis/management.loft.sh/v1/virtualclustertemplates" \
-X GET --insecure \
-H "Authorization: Bearer $ACCESS_KEY"
Get a single Virtual Cluster Template by name
Run the following curl command to get Virtual Cluster Template my-virtual-cluster-template
:
# Exchange my-virtual-cluster-template in the url below with the name of the Virtual Cluster Template
curl -s "https://$LOFT_DOMAIN/kubernetes/management/apis/management.loft.sh/v1/virtualclustertemplates/my-virtual-cluster-template" \
-X GET --insecure \
-H "Authorization: Bearer $ACCESS_KEY"
Create: Virtual Cluster Template
You can either use curl or kubectl to create a new Virtual Cluster Template.
- kubectl
- curl
Create a file object.yaml
with the following contents:
apiVersion: management.loft.sh/v1
kind: VirtualClusterTemplate
metadata:
creationTimestamp: null
name: my-virtual-cluster-template
spec:
access:
- users:
- '*'
verbs:
- get
description: This virtual cluster template deploys an isolated virtual cluster
displayName: Isolated Virtual Cluster Template
template:
accessPoint:
ingress: {}
helmRelease:
chart: {}
values: |-
# Below you can configure the virtual cluster
isolation:
enabled: true
# Checkout https://vcluster.com/docs for more config options
instanceTemplate:
metadata: {}
metadata: {}
pro: {}
spaceTemplate:
metadata: {}
status: {}
Then create the Virtual Cluster Template my-virtual-cluster-template
with:
kubectl create -f object.yaml
Create a file object.yaml
with the following contents:
apiVersion: management.loft.sh/v1
kind: VirtualClusterTemplate
metadata:
creationTimestamp: null
name: my-virtual-cluster-template
spec:
access:
- users:
- '*'
verbs:
- get
description: This virtual cluster template deploys an isolated virtual cluster
displayName: Isolated Virtual Cluster Template
template:
accessPoint:
ingress: {}
helmRelease:
chart: {}
values: |-
# Below you can configure the virtual cluster
isolation:
enabled: true
# Checkout https://vcluster.com/docs for more config options
instanceTemplate:
metadata: {}
metadata: {}
pro: {}
spaceTemplate:
metadata: {}
status: {}
Run the following curl command to create a new Virtual Cluster Template my-virtual-cluster-template
:
curl -s -X POST --insecure \
"https://$LOFT_DOMAIN/kubernetes/management/apis/management.loft.sh/v1/virtualclustertemplates" \
--data-binary "$(cat object.yaml)" \
-H "Content-Type: application/yaml" \
-H "Authorization: Bearer $ACCESS_KEY"
Update: Virtual Cluster Template
You can either use curl or kubectl to update Virtual Cluster Templates.
- kubectl
- curl
Update Virtual Cluster Template
Run the following command to update Virtual Cluster Template my-virtual-cluster-template
:
kubectl edit virtualclustertemplates.management.loft.sh my-virtual-cluster-template
Then edit the object and upon save, kubectl will update the resource.
Patch Virtual Cluster Template
Patching a resource is useful if you want to generically exchange only a small portion of the object instead of retrieving the whole object first and then modifying it. To learn more about patches in Kubernetes, please take a look at the official docs.
Run the following kubectl command to add a new annotation my-annotation: my-value
to the Virtual Cluster Template my-virtual-cluster-template
via a patch:
kubectl patch virtualclustertemplates.management.loft.sh my-virtual-cluster-template \
--type json \
-p '[{"op": "add", "path": "/metadata/annotations/my-annotation", "value": "my-value"}]'
Update Virtual Cluster Template
First retrieve the current object into a file object.yaml
. This could look like:
apiVersion: management.loft.sh/v1
kind: VirtualClusterTemplate
metadata:
creationTimestamp: "2023-04-03T00:00:00Z"
generation: 12
name: my-virtual-cluster-template
resourceVersion: "66325905"
uid: af5f9f0f-8ab9-4b4b-a595-a95a5921f3c2
spec:
access:
- users:
- '*'
verbs:
- get
description: This virtual cluster template deploys an isolated virtual cluster
displayName: Isolated Virtual Cluster Template
template:
accessPoint:
ingress: {}
helmRelease:
chart: {}
values: |-
# Below you can configure the virtual cluster
isolation:
enabled: true
# Checkout https://vcluster.com/docs for more config options
instanceTemplate:
metadata: {}
metadata: {}
pro: {}
spaceTemplate:
metadata: {}
status: {}
Run the following curl command to update a single Virtual Cluster Template my-virtual-cluster-template
:
# Replace the my-virtual-cluster-template in the url below with the name of the Virtual Cluster Template you want to update
curl -s "https://$LOFT_DOMAIN/kubernetes/management/apis/management.loft.sh/v1/virtualclustertemplates/my-virtual-cluster-template" \
-X PUT --insecure \
-H "Content-Type: application/yaml" \
-H "Authorization: Bearer $ACCESS_KEY" \
--data-binary "$(cat object.yaml)"
Patch Virtual Cluster Template
Patching a resource is useful if you want to generically exchange only a small portion of the object instead of retrieving the whole object first and then modifying it. To learn more about patches in Kubernetes, please take a look at the official docs.
Run the following curl command to add a new annotation my-annotation: my-value
to the Virtual Cluster Template my-virtual-cluster-template
via a patch:
# Replace the my-virtual-cluster-template in the url below with the name of the Virtual Cluster Template you want to update
curl -s "https://$LOFT_DOMAIN/kubernetes/management/apis/management.loft.sh/v1/virtualclustertemplates/my-virtual-cluster-template" \
-X PATCH --insecure \
-H "Content-Type: application/json-patch+json" \
-H "Authorization: Bearer $ACCESS_KEY" \
--data '[{"op": "add", "path": "/metadata/annotations/my-annotation", "value": "my-value"}]'
Delete: Virtual Cluster Template
You can either use curl or kubectl to delete Virtual Cluster Templates.
- kubectl
- curl
Run the following command to delete Virtual Cluster Template my-virtual-cluster-template
:
kubectl delete virtualclustertemplates.management.loft.sh my-virtual-cluster-template
Run the following curl command to delete Virtual Cluster Template my-virtual-cluster-template
:
# Replace the my-virtual-cluster-template in the url below with the name of the Virtual Cluster Template you want to delete
curl -s "https://$LOFT_DOMAIN/kubernetes/management/apis/management.loft.sh/v1/virtualclustertemplates/my-virtual-cluster-template" \
-X DELETE --insecure \
-H "Authorization: Bearer $ACCESS_KEY"