edgefarm.applications Examples¶
This section contains examples of how to use the edgefarm.applications API.
Application properties¶
All options are member of Application.spec.components[index].properties.
Scheduling¶
nodepoolSelector¶
The nodePoolSelector is a standard Kubernetes LabelSelector.
tolerations¶
Tolerations are default Kubernetes tolerations. Follow the Kubernetes documentation to learn more about tolerations.
tolerations:
- key: "key"
operator: "Equal"
value: "value"
effect: "NoSchedule"
- operator: "Exists"
effect: "NoExecute"
Image¶
image¶
Follow the Kubernetes documentation to learn more about image names.
imagePullPolicy¶
Follow the Kubernetes documentation to learn more about imagePullPolicy.
imagePullSecrets¶
Follow the Kubernetes documentation on how to use imagePullSecrets.
Entrypoint¶
command¶
Overrides the container image's ENTRYPOINT. Not executed within a shell.
args¶
Arguments to the container image's ENTRYPOINT. The container image's CMD is used if this is not provided.
Environment variables¶
Define environment variables for the container by value or referencing a ConfigMap or a Secret.
envs:
- name: MY_ENV
value: "my value"
- name: MY_ENV_FROM_SECRET
valueFrom:
secretKeyRef:
name: mysecret
key: mykey
- name: MY_ENV_FROM_CONFIGMAP
valueFrom:
configMapKeyRef:
name: myconfigmap
key: mykey
Security context¶
securityContext¶
The securityContext is a subset of the Kubernetes SecurityContext.
securityContext:
allowPrivilegedEscalation: false
capabilities:
add:
- "NET_ADMIN"
drop:
- "NET_RAW"
privileged: true
readOnlyRootFilesystem: true
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 1000
Ports¶
ports¶
ports:
- name: http
containerPort: 80
protocol: TCP
hostPort: 8080
- containerPort: 9090
hostPort: 12345
Resources¶
The notation for cpu and memory resources is the same as in Kubernetes. Follow the Kubernetes docs for more information.
cpu¶
Used for requests.cpu and limits.cpu if bot are not specified.
memory¶
Used for requests.memory and limits.memory if bot are not specified.
requests¶
limits¶
Traits¶
edgefarm-network¶
By adding the edgefarm-network
trait, you can connect your application to a edgefarm.network
.
edgefarm-storage¶
You can define multiple storages for a component. Supported storages are hostPath
, emptyDir
, configMap
and secret
. Define multiple if you need to mount multiple storages.
traits:
- type: edgefarm-storage
properties:
hostPath:
- name: myhostpath
type: DirectoryOrCreate #(1)!
mountPath: /in-container/mypath
path: /on-host/mypath
emptyDir:
- name: myemptydir
mountPath: /in-container-/emptydir
configMap: #(2)!
- name: myconfigmap
mountPath: /in-container/myconfigmap
items:
- key: foo
path: foo
secret: #(3)!
- name: mysecret
mountPath: /in-container/mysecret
- If you specify the optional
type
and the path or file to mount does not match the type, the application will fail to start. - Let's mount the item
foo
from the ConfigMapmyconfigmap
to/in-container/myconfigmap/foo
. - Let's mount all items from the Secret
mysecret
to/in-container/mysecret
inside the container.
You can even create ConfigMaps and Secrets with pre-populated data.
traits:
- type: edgefarm-storage
properties:
configMap:
- name: myconfigmap
mountPath: /in-container/myconfigmap
mountOnly: false #(1)!
data: #(2)!
foo: bar
secret:
- name: myconfigmap
mountPath: /in-container/myconfigmap
mountOnly: false
data: #(3)!
base64encoded: YmFyCg== #(4)!
stringData: #(5)!
foo: bar
- Let's express that the ConfigMap shall be created by setting
mountOnly
tofalse
- Let's pre-populate the ConfigMap with the key
foo
and the valuebar
. - Secrets's
data
field is a map of keys and base64 encoded values. YmFyCg==
is base64 encoded forbar
.- Secrets's
stringData
field is a map of keys and values as strings.
Full example appliations¶
Basic stress test¶
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: stress
spec:
components:
- name: stress
type: edgefarm-applications
properties:
image: alexeiled/stress-ng
nodepoolSelector:
matchLabels:
app/stress: "" #(1)!
name: stress
command: #(2)!
- "/stress-ng"
- "--cpu"
- "4"
- "--io"
- "2"
- "--vm-bytes"
- "1G"
- "timeout"
- "600s"
- This label is used to select the nodepool to deploy the application to. All nodepools that have the label
app/stress=
will be selected. Keep in mind that the values for label selectors can be unset. - To run the stress test we'll override the command of the container.
Application with network and storage¶
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: myapp
spec:
components:
- name: myapp
type: edgefarm-applications
properties:
image: natsio/nats-box:latest
nodepoolSelector:
matchLabels:
mynetwork-big: "" #(1)!
name: myapp
command: #(2)!
- sh
- "-c"
- "sleep infinity"
traits:
- type: edgefarm-network #(3)!
properties:
network: #(4)!
name: mynetwork
subnetwork: big
user: bigonly
- type: edgefarm-storage #(5)!
properties:
configMap: #(6)!
- name: mycm
data:
foo: bar
mountPath: /mypath
emptyDir: #(7)!
- name: test1
mountPath: /test/mount/emptydir
- This application will be deployed to all nodes that have the label
mynetwork-big=
. Keep in mind that the values for label selectors can be unset. - Override the command of the container.
- A trait
edgefarm-network
is added allowing the application to connect to a network. - By configuring the
name
,subnetwork
anduser
the application will be able to connect to the network. Note, that the network must exist in order to connect to it. In fact, without the network, the application won't be able to start. - A trait
edgefarm-storage
is added allowing the application to mount volumes. - We'll set-up a ConfigMap called
mycm
and mount it to/mypath
inside the container. There is also some data pre-populated in the ConfigMap that can be used by the application with the keyfoo
and the valuebar
. - We'll set-up an emptyDir called
test1
and mount it to/test/mount/emptydir
inside the container. The emptyDir will be created on the node where the application is deployed. The emptyDir will be deleted when the application is deleted.