View Source FLAMEK8sBackend (flame_k8s_backend v0.2.0)

Kubernetes Backend implementation. In order for this to work, your application needs to meet some requirements.

Usage

Configure the flame backend in our configuration.

# config.exs
if config_env() == :prod do
  config :flame, :backend, FLAMEK8sBackend
  config :flame, FLAMEK8sBackend, log: :debug
end

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: flame-test

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: flame_test@$(POD_IP)