View Source FLAMEK8sBackend (flame_k8s_backend v0.5.7)
Kubernetes Backend implementation.
Usage
Configure the flame backend in our configuration or application setup:
# application.ex
children = [
{FLAME.Pool,
name: MyApp.SamplePool,
backend: FLAMEK8sBackend,
min: 0,
max: 10,
max_concurrency: 5,
idle_shutdown_after: 30_000}
]
Options
The following backend options are supported:
:app_container_name
- If your application pod runs multiple containers (initContainers excluded), use this option to pass the name of the container running this application. If not given, the first container in the list of containers is used to lookup the contaienr image, env vars and resources to be used for the runner pods.:omit_owner_reference
- If true, no ownerReferences are configured on the runner pods. Defaults tofalse
:runner_pod_tpl
- If given, controls how the runner pod manifest is generated. Can be a function of typeFLAMEK8sBackend.RunnerPodTemplate.callback/0
or a struct of typeFLAMEK8sBackend.RunnerPodTemplate.t/0
. A callback receives the manifest of the parent pod as a map and should return the runner pod's manifest as a map(). If a struct is given, the runner pod's manifest will be generated with values from the struct if given or from the parent pod if omitted. If this option is omitted, the parent pod'senv
andresources
are used for the runner pod. SeeFLAMEK8sBackend.RunnerPodTemplate
for more infos.:log
- The log level to use for verbose logging. Defaults tofalse
.
Prerequisites
In order for this to work, your application needs to meet some requirements.
Env Variables
In order for the backend to be able to get informations from your pod and use
them for the runner pods (e.g. env variables), you have to define POD_NAME
and POD_NAMESPACE
environment variables on your pod.
apiVersion: apps/v1
kind: Deployment
spec:
selector:
matchLabels:
app: myapp
template:
spec:
containers:
- env:
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
RBAC
Your application needs run as a service account with permissions to manage pods. This is a simple
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: myapp
namespace: app-namespace
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: app-namespace
name: pod-mgr
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["create", "get", "list", "delete", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: myapp-pod-mgr
namespace: app-namespace
subjects:
- kind: ServiceAccount
name: myapp
namespace: app-namespace
roleRef:
kind: Role
name: pod-mgr
apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
serviceAccountName: my-app
Clustering
Your application needs to be able to form a cluster with your runners. Define
POD_IP
, RELEASE_DISTRIBUTION
and RELEASE_NODE
environment variables on
your pods as follows:
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- env:
- name: POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: RELEASE_DISTRIBUTION
value: name
- name: RELEASE_NODE
value: my_app@$(POD_IP)