How to attach the storage
The platform offers several methods to attach different types of storage to the applications. Mainly you can either setup storage using the options already included in the Component definitions, or attach the storage with traits.
Setting storage using the component properties
Default component types such as webservice or worker offer a set of parameters to configure the component storage. As an example, to attach storage with the most common components use:
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: my-app
spec:
components:
- name: backend # Name of the component
type: webservice # Set to webservice
properties:
image: my-app-image:v1.0.0 # (Required) Container image
volumeMounts: # (Optional) Definition of the volumes to be mounted
pvc: # Using a Persistent Volume Claim
- name: data
mountPath: "/var/lib/db"
claimName: "db-pvc"
configMap: # Using a Config Map
- name: cm-data
mountPath: "/config"
cmName: "db-config"
secret: # Using a Secret
- name: cert-data
mountPath: "/certs"
secretName: "db-certs"
emptyDir: # Using an ephemeral mount
- name: temp-data
mountPath: "/var/lib/tmp"
For other component types, check the specific component documentation.
Setting storage using a trait
Similarly to the component types, some traits such as the storage one offer a method to attach volumes to a component. As an example, to attach storage using the previous trait use:
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: my-app
spec:
components:
- name: my-comp
type: worker
properties:
image: my-app-image:v1.0.0
traits:
- type: storage # Set to storage
properties:
emptyDir: # EmptyDir type storage
- name: empty-name # (Required) the name of the volume
mountPath: /mount/emptydir # (Required) mount path
For more information, check the specific trait documentation.