### Configure FLAMEK8sBackend in Application Setup Source: https://hexdocs.pm/flame_k8s_backend/FLAMEK8sBackend.html Configure the FLAME backend in your application's setup. This example shows how to integrate FLAMEK8sBackend with FLAME.Pool. ```elixir children = [ {FLAME.Pool, name: MyApp.SamplePool, backend: FLAMEK8sBackend, min: 0, max: 10, max_concurrency: 5, idle_shutdown_after: 30_000} ] ``` -------------------------------- ### Configure FLAME Pool with K8s Backend Source: https://hexdocs.pm/flame_k8s_backend/index.html Configure the FLAME pool in your application's setup to use the FLAMEK8sBackend. This example shows basic pool configuration with logging enabled. ```elixir children = [ {FLAME.Pool, name: MyApp.SamplePool, backend: FLAMEK8sBackend, min: 0, max: 10, max_concurrency: 5, idle_shutdown_after: 30_000, log: :debug} ] ``` -------------------------------- ### Add flame_k8s_backend to Dependencies Source: https://hexdocs.pm/flame_k8s_backend/index.html Add the flame_k8s_backend dependency to your project's `deps.ex` file to install it. ```elixir def deps do [ {:flame_k8s_backend, ">= 0.6.0"} ] end ``` -------------------------------- ### Configure FLAME Pool with FLAMEK8sBackend Source: https://hexdocs.pm/flame_k8s_backend/readme.html Configure the FLAME Pool in your application's `application.ex` file to use FLAMEK8sBackend. Ensure you set appropriate values for `min`, `max`, `max_concurrency`, `idle_shutdown_after`, and `log`. ```elixir # application.ex children = [ {FLAME.Pool, name: MyApp.SamplePool, backend: FLAMEK8sBackend, min: 0, max: 10, max_concurrency: 5, idle_shutdown_after: 30_000, log: :debug} ] ``` -------------------------------- ### Define POD_NAME and POD_NAMESPACE Environment Variables Source: https://hexdocs.pm/flame_k8s_backend/FLAMEK8sBackend.html Configure your deployment to set POD_NAME and POD_NAMESPACE environment variables. These are crucial for the backend to gather information from your pod. ```yaml 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 ``` -------------------------------- ### Configure Clustering Environment Variables Source: https://hexdocs.pm/flame_k8s_backend/readme.html Set `POD_IP`, `RELEASE_DISTRIBUTION`, and `RELEASE_NODE` environment variables for your pods to enable clustering with runners. The `RELEASE_NODE` should dynamically include the pod's IP address. ```yaml 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) ``` -------------------------------- ### Configure Runner Pod Manifest with Map Source: https://hexdocs.pm/flame_k8s_backend/changelog.html Use this when migrating from :runner_pod_tpl to the new :manifest option. Pass a map to define the runner pod's manifest, including environment variables and resource limits. ```elixir manifest = %{ "spec" => %{ "containers" => [ %{ "env" => [ %{"name" => "FOO", "value" => "bar"} ], "resources" => %{ "requests" => %{"memory" => "256Mi", "cpu" => "100m"}, "limits" => %{"memory" => "256Mi", "cpu" => "400m"} } } ] } } {FLAME.Pool, name: MyApp.SamplePool, backend: {FLAMEK8sBackend, manifest: manifest}} ``` -------------------------------- ### Dynamically Build Runner Pod Manifest with Function Source: https://hexdocs.pm/flame_k8s_backend/FLAMEK8sBackend.html Construct the runner pod manifest dynamically by passing a function to the backend. This allows copying configuration from the parent pod. ```elixir manifest_fun = fn parent_pod_manifest, app_container -> %{"metadata" => %{ # ... }, "spec" => %{"containers" => [ %{ # Copy all env vars and resources from the parent container definition. "env" => app_container["env"] || [], "envFrom" => app_container["envFrom"] || [], "resources" => app_container["resources"] || %{} } ]}} end FLAME.Pool, name: MyApp.SamplePool, backend: {FLAMEK8sBackend, manifest: manifest_fun}} ``` -------------------------------- ### Configure RBAC for Pod Management Source: https://hexdocs.pm/flame_k8s_backend/FLAMEK8sBackend.html Set up a ServiceAccount, Role, and RoleBinding to grant your application the necessary permissions to manage pods. Ensure the service account name matches the one specified in the deployment. ```yaml --- 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 ``` -------------------------------- ### Add FLAMEK8sBackend to Dependencies Source: https://hexdocs.pm/flame_k8s_backend/readme.html Add the flame_k8s_backend dependency to your project's `deps.ex` file. ```elixir def deps do [ {:flame_k8s_backend, "~> 0.6.0"} ] end ``` -------------------------------- ### Define Clustering Environment Variables Source: https://hexdocs.pm/flame_k8s_backend/FLAMEK8sBackend.html Configure POD_IP, RELEASE_DISTRIBUTION, and RELEASE_NODE environment variables for your pods to enable clustering with runners. The RELEASE_NODE is dynamically set using the pod's IP. ```yaml 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) ``` -------------------------------- ### Configure Runner Pod Manifest with Function Source: https://hexdocs.pm/flame_k8s_backend/changelog.html Use this to maintain the behavior of copying envs and resources from the parent pod when using the :manifest option. The function receives the parent pod manifest and app container definition. ```elixir manifest_fun = fn parent_pod_manifest, app_container -> %{ "spec" => %{ "containers" => [ %{ # Copy env vars and resources from the parent container definition. # For fields that you don't want to copy, you can specify the desired # values here. "env" => app_container["env"] || [], "envFrom" => app_container["envFrom"] || [], "resources" => app_container["resources"] || %{} } ] } } end FLAME.Pool, name: MyApp.SamplePool, backend: {FLAMEK8sBackend, manifest: manifest_fun}} ``` -------------------------------- ### Configure Runner Pod Manifest with Elixir Map Source: https://hexdocs.pm/flame_k8s_backend/FLAMEK8sBackend.html Set environment variables and resources for the runner pod using an Elixir map. This is useful for straightforward manifest configurations. ```elixir manifest = %{ "spec" => %{ "containers" => [ %{ "env" => [ %{"name" => "FOO", "value" => "bar"} ], "resources" => %{ "requests" => %{"memory" => "256Mi", "cpu" => "100m"}, "limits" => %{"memory" => "256Mi", "cpu" => "400m"} } } ] } } {FLAME.Pool, name: MyApp.SamplePool, backend: {FLAMEK8sBackend, manifest: manifest}} ``` -------------------------------- ### Configure Runner Pod Manifest with YAML Sigil Source: https://hexdocs.pm/flame_k8s_backend/FLAMEK8sBackend.html Define complex runner pod manifests using YAML within Elixir code via the `~y` sigil. Requires the `:yaml_elixir` package. ```elixir manifest = ~y""" metadata: spec: containers: - resources: requests: memory: 256Mi cpu: 100m limits: memory: 256Mi cpu: 400m - env: - name: FOO value: bar """ {FLAME.Pool, name: MyApp.SamplePool, backend: {FLAMEK8sBackend, manifest: manifest}} ``` -------------------------------- ### RBAC Configuration for Service Account Source: https://hexdocs.pm/flame_k8s_backend/readme.html Define a ServiceAccount, Role, and RoleBinding to grant necessary permissions for managing pods. Ensure the `namespace` and `name` fields are correctly set for your application. ```yaml --- 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 ``` -------------------------------- ### Configure Environment Variables for Runners Source: https://hexdocs.pm/flame_k8s_backend/readme.html Set `POD_NAME` and `POD_NAMESPACE` environment variables in your deployment configuration. These are used by the backend to gather information about the pod and configure runner pods. ```yaml 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 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.