Space Template
Space templates can be used to create predefined space configurations that have certain applications already deployed inside them or other predefined configuration applied. They are a powerful tool to create new predefined environments on demand.
Example Space Template
An example Space Template:
apiVersion: management.loft.sh/v1
kind: SpaceTemplate
metadata:
creationTimestamp: null
name: my-space-template
spec:
access:
- users:
- '*'
verbs:
- get
description: This space templates deploys an isolated space
displayName: Isolated Space Template
template:
metadata:
labels:
policy.loft.sh/pod-security: baseline
objects: |-
apiVersion: v1
kind: ResourceQuota
metadata:
name: loft-resource-quota
spec:
hard:
count/configmaps: '100'
count/endpoints: '40'
count/persistentvolumeclaims: '20'
count/pods: '20'
count/secrets: '100'
count/services: '20'
limits.cpu: '20'
limits.ephemeral-storage: 160Gi
limits.memory: 40Gi
requests.cpu: '10'
requests.ephemeral-storage: 60Gi
requests.memory: 20Gi
requests.storage: 100Gi
services.loadbalancers: '1'
services.nodeports: '0'
status: {}
Space 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: Space Templates
You can either use curl or kubectl to retrieve Space Templates.
- kubectl
- curl
Retrieve a list of Space Templates
Run the following command to list all Space Templates:
kubectl get spacetemplates.management.loft.sh -o yaml
Retrieve a single Space Template by name
Run the following kubectl command to get Space Template my-space-template
:
kubectl get spacetemplates.management.loft.sh my-space-template -o yaml
Retrieve a list of Space Templates
Run the following curl command to list all Space Templates:
curl -s "https://$LOFT_DOMAIN/kubernetes/management/apis/management.loft.sh/v1/spacetemplates" \
-X GET --insecure \
-H "Authorization: Bearer $ACCESS_KEY"
Get a single Space Template by name
Run the following curl command to get Space Template my-space-template
:
# Exchange my-space-template in the url below with the name of the Space Template
curl -s "https://$LOFT_DOMAIN/kubernetes/management/apis/management.loft.sh/v1/spacetemplates/my-space-template" \
-X GET --insecure \
-H "Authorization: Bearer $ACCESS_KEY"
Create: Space Template
You can either use curl or kubectl to create a new Space Template.
- kubectl
- curl
Create a file object.yaml
with the following contents:
apiVersion: management.loft.sh/v1
kind: SpaceTemplate
metadata:
creationTimestamp: null
name: my-space-template
spec:
access:
- users:
- '*'
verbs:
- get
description: This space templates deploys an isolated space
displayName: Isolated Space Template
template:
metadata:
labels:
policy.loft.sh/pod-security: baseline
objects: |-
apiVersion: v1
kind: ResourceQuota
metadata:
name: loft-resource-quota
spec:
hard:
count/configmaps: '100'
count/endpoints: '40'
count/persistentvolumeclaims: '20'
count/pods: '20'
count/secrets: '100'
count/services: '20'
limits.cpu: '20'
limits.ephemeral-storage: 160Gi
limits.memory: 40Gi
requests.cpu: '10'
requests.ephemeral-storage: 60Gi
requests.memory: 20Gi
requests.storage: 100Gi
services.loadbalancers: '1'
services.nodeports: '0'
status: {}
Then create the Space Template my-space-template
with:
kubectl create -f object.yaml
Create a file object.yaml
with the following contents:
apiVersion: management.loft.sh/v1
kind: SpaceTemplate
metadata:
creationTimestamp: null
name: my-space-template
spec:
access:
- users:
- '*'
verbs:
- get
description: This space templates deploys an isolated space
displayName: Isolated Space Template
template:
metadata:
labels:
policy.loft.sh/pod-security: baseline
objects: |-
apiVersion: v1
kind: ResourceQuota
metadata:
name: loft-resource-quota
spec:
hard:
count/configmaps: '100'
count/endpoints: '40'
count/persistentvolumeclaims: '20'
count/pods: '20'
count/secrets: '100'
count/services: '20'
limits.cpu: '20'
limits.ephemeral-storage: 160Gi
limits.memory: 40Gi
requests.cpu: '10'
requests.ephemeral-storage: 60Gi
requests.memory: 20Gi
requests.storage: 100Gi
services.loadbalancers: '1'
services.nodeports: '0'
status: {}
Run the following curl command to create a new Space Template my-space-template
:
curl -s -X POST --insecure \
"https://$LOFT_DOMAIN/kuberentes/management/apis/management.loft.sh/v1/spacetemplates" \
--data-binary "$(cat object.yaml)" \
-H "Content-Type: application/yaml" \
-H "Authorization: Bearer $ACCESS_KEY"
Update: Space Template
You can either use curl or kubectl to update Space Templates.
- kubectl
- curl
Update Space Template
Run the following command to update Space Template my-space-template
:
kubectl edit spacetemplates.management.loft.sh my-space-template
Then edit the object and upon save, kubectl will update the resource.
Patch Space 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 Space Template my-space-template
via a patch:
kubectl patch spacetemplates.management.loft.sh my-space-template \
--type json \
-p '[{"op": "add", "path": "/metadata/annotations/my-annotation", "value": "my-value"}]'
Update Space Template
First retrieve the current object into a file object.yaml
. This could look like:
apiVersion: management.loft.sh/v1
kind: SpaceTemplate
metadata:
creationTimestamp: "2023-04-03T00:00:00Z"
generation: 12
name: my-space-template
resourceVersion: "66325905"
uid: af5f9f0f-8ab9-4b4b-a595-a95a5921f3c2
spec:
access:
- users:
- '*'
verbs:
- get
description: This space templates deploys an isolated space
displayName: Isolated Space Template
template:
metadata:
labels:
policy.loft.sh/pod-security: baseline
objects: |-
apiVersion: v1
kind: ResourceQuota
metadata:
name: loft-resource-quota
spec:
hard:
count/configmaps: '100'
count/endpoints: '40'
count/persistentvolumeclaims: '20'
count/pods: '20'
count/secrets: '100'
count/services: '20'
limits.cpu: '20'
limits.ephemeral-storage: 160Gi
limits.memory: 40Gi
requests.cpu: '10'
requests.ephemeral-storage: 60Gi
requests.memory: 20Gi
requests.storage: 100Gi
services.loadbalancers: '1'
services.nodeports: '0'
status: {}
Run the following curl command to update a single Space Template my-space-template
:
# Replace the my-space-template in the url below with the name of the Space Template you want to update
curl -s "https://$LOFT_DOMAIN/kubernetes/management/apis/management.loft.sh/v1/spacetemplates/my-space-template" \
-X PUT --insecure \
-H "Content-Type: application/yaml" \
-H "Authorization: Bearer $ACCESS_KEY" \
--data-binary "$(cat object.yaml)"
Patch Space 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 Space Template my-space-template
via a patch:
# Replace the my-space-template in the url below with the name of the Space Template you want to update
curl -s "https://$LOFT_DOMAIN/kubernetes/management/apis/management.loft.sh/v1/spacetemplates/my-space-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: Space Template
You can either use curl or kubectl to delete Space Templates.
- kubectl
- curl
Run the following command to delete Space Template my-space-template
:
kubectl delete spacetemplates.management.loft.sh my-space-template
Run the following curl command to delete Space Template my-space-template
:
# Replace the my-space-template in the url below with the name of the Space Template you want to delete
curl -s "https://$LOFT_DOMAIN/kubernetes/management/apis/management.loft.sh/v1/spacetemplates/my-space-template" \
-X DELETE --insecure \
-H "Authorization: Bearer $ACCESS_KEY"