The Kubernetes Files

This page holds the five files for the Kubernetes installation: namespace.yaml creates the app’s own namespace, rbac.yaml gives the app and its Agents their rights in it, network-policy.yaml decides who may call a Topic or an Agent, admission-policy.yaml limits the pods and jobs an Agent may start and keeps each Agent pod to its own helper pods and jobs, and deployment.yaml starts the app and its database.


1. Save the files

  1. Create an installation directory and go into it, for example aiknowledgefabric.

  2. Create a file called namespace.yaml in it, copy the whole file from section 2 into it and save it.

  3. Create a file called rbac.yaml, copy the whole file from section 3 into it and save it.

  4. Create a file called network-policy.yaml, copy the whole file from section 4 into it and save it.

  5. Create a file called admission-policy.yaml, copy the whole file from section 5 into it and save it.

  6. Create a file called deployment.yaml, copy the whole file from section 6 into it and save it.

Before you apply them, change the values that section 7 lists. Then go back to the installation steps.


2. namespace.yaml

# The app's own namespace. Required: the app's Role manages every Deployment, Service and Secret in its namespace,
# so nothing else may run there. Apply first:
#   kubectl apply -f k8s/namespace.yaml
#
# Pod Security: topic and GraphRAG topic pods meet "restricted"; the app, Postgres and agent pods do not yet. So
# "restricted" only warns and audits here. Once every pod meets it, add  pod-security.kubernetes.io/enforce: restricted.
apiVersion: v1
kind: Namespace
metadata:
  name: aiknowledgefabric
  labels:
    pod-security.kubernetes.io/warn: restricted
    pod-security.kubernetes.io/audit: restricted

3. rbac.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: aiknowledgefabric
  namespace: aiknowledgefabric
---
# Namespace-scoped, but it manages every Deployment, StatefulSet, Service and Secret in it: give the app a namespace of
# its own (namespace.yaml) and run nothing else there.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: aiknowledgefabric
  namespace: aiknowledgefabric
rules:
# Topics, GraphRAG Topics and managed servers run as Deployments
- apiGroups: ["apps"]
  resources: ["deployments"]
  verbs: ["get", "list", "create", "update", "delete", "patch"]
# Agents: one StatefulSet each (agent-<id>, server-side applied)
- apiGroups: ["apps"]
  resources: ["statefulsets"]
  verbs: ["get", "list", "create", "update", "delete", "patch"]
# Topics, GraphRAG topics and agents: each one's credentials live in its own Secrets (topic-<id>-secrets,
# graphrag-<id>-secrets, agent-<id>-secrets, agent-<id>-pipelines), written at start (not list: the app only touches
# its own Secrets, by name)
- apiGroups: [""]
  resources: ["secrets"]
  verbs: ["get", "create", "update", "patch", "delete"]
# Topics: a pod's ReplicaSet must belong to the topic's Deployment before the app sends it a user's token
- apiGroups: ["apps"]
  resources: ["replicasets"]
  verbs: ["get", "list"]
- apiGroups: [""]
  resources: ["services", "persistentvolumeclaims", "configmaps"]
  verbs: ["get", "list", "create", "update", "delete", "patch"]
# Autoscalers: the chat servers' of a topic, only when its Kubernetes settings ask for automatic scaling, and every
# agent's (scaling needs metrics-server in the cluster)
- apiGroups: ["autoscaling"]
  resources: ["horizontalpodautoscalers"]
  verbs: ["get", "list", "create", "update", "delete", "patch"]
# Topics: a PodDisruptionBudget, only when a topic's Kubernetes settings set availability.pdbMaxUnavailable
- apiGroups: ["policy"]
  resources: ["poddisruptionbudgets"]
  verbs: ["get", "list", "create", "update", "delete", "patch"]
# Topics, optional: a PodMonitor for the Prometheus Operator, only when a topic's Kubernetes settings set
# observability.podMonitor. Without the Prometheus Operator (or this rule) such a topic starts with a warning.
- apiGroups: ["monitoring.coreos.com"]
  resources: ["podmonitors"]
  verbs: ["get", "list", "create", "update", "delete", "patch"]
# The app lists the pods of a topic or agent (logs and DEV reports of every pod; a stopped one's history login is
# disabled once its pods are gone). It never creates, execs into or deletes a pod itself.
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: aiknowledgefabric
  namespace: aiknowledgefabric
subjects:
- kind: ServiceAccount
  name: aiknowledgefabric
  namespace: aiknowledgefabric
roleRef:
  kind: Role
  name: aiknowledgefabric
  apiGroup: rbac.authorization.k8s.io
---
# Agent pods (the StatefulSets agent-<id>) run under this ServiceAccount, never under the app's. An MCP_DOCKER tool runs
# as a pod the agent creates, execs its MCP server into and deletes; a PYTHON_SCRIPT module runs as a Job whose script
# is handed over in a ConfigMap owned by the Job, and whose output is read from the Job pod's log; a tool pod's env
# comes from a Secret the agent creates for it. Nothing else: no reading or changing Secrets, no Deployments,
# StatefulSets or Services. Topic pods do not use the Kubernetes API at all (no token is mounted), and neither do the
# tool pods (they mount no ServiceAccount token).
apiVersion: v1
kind: ServiceAccount
metadata:
  name: aiknowledgefabric-agent
  namespace: aiknowledgefabric
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: aiknowledgefabric-agent
  namespace: aiknowledgefabric
rules:
# Tool pods: create, check before every exec, list its own on a clean stop (by its instance label) and to find a Job's
# pod, delete. Their owner reference names the agent pod without blockOwnerDeletion, so nothing on pods/finalizers.
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "list", "create", "delete"]
# One exec per MCP session, over WebSocket (newer Kubernetes versions check create, older ones get)
- apiGroups: [""]
  resources: ["pods/exec"]
  verbs: ["get", "create"]
# A PYTHON_SCRIPT Job's output
- apiGroups: [""]
  resources: ["pods/log"]
  verbs: ["get"]
- apiGroups: ["batch"]
  resources: ["jobs"]
  verbs: ["get", "create", "delete"]
# A PYTHON_SCRIPT Job's script, created after the Job and owned by it
- apiGroups: [""]
  resources: ["configmaps"]
  verbs: ["create", "delete"]
# An MCP_DOCKER tool pod's env (API keys, mostly): a Secret named like the pod and owned by it, created after it. Create
# only: the agent never reads, lists, changes or deletes a Secret; the garbage collector deletes it with its pod.
- apiGroups: [""]
  resources: ["secrets"]
  verbs: ["create"]
# The PYTHON_SCRIPT pip cache claim, read once at start to warn when it is not ReadWriteMany
- apiGroups: [""]
  resources: ["persistentvolumeclaims"]
  verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: aiknowledgefabric-agent
  namespace: aiknowledgefabric
subjects:
- kind: ServiceAccount
  name: aiknowledgefabric-agent
  namespace: aiknowledgefabric
roleRef:
  kind: Role
  name: aiknowledgefabric-agent
  apiGroup: rbac.authorization.k8s.io

4. network-policy.yaml

# Who may call the pods the app starts (D25). Apply once per installation, in the app's namespace:
#   kubectl apply -f k8s/network-policy.yaml
# Needs a network plugin that enforces NetworkPolicy (for example Calico or Cilium; minikube: --cni=calico).
# Without one, Kubernetes accepts these objects and ignores them.
#
# - Servers of topics and GraphRAG topics (port 8080): the primary server (cyrock.ai/role: all; answers chats and
#   takes uploads) and the chat servers (cyrock.ai/role: chat). Allowed: the app itself, and pods the app started
#   (label managed-by: aiknowledgefabric on the pod): other topics and GraphRAG topics calling a topic as an MCP tool,
#   agents, and the topic's own servers forwarding an abort to each other.
# - Agent pods (port 8080): the app itself, and other agent pods (see the agent policy below for who they are).
# - Pods an agent starts for its tools (MCP_DOCKER tool pods, PYTHON_SCRIPT Job pods): nobody. The agent reaches them
#   only through the Kubernetes API server (exec, logs), never over the pod network.
# - Postgres (port 5432): the app, the servers of topics and GraphRAG topics, and the pods of agents (they read and
#   write their chat history, each with its own login).
# Everything else is refused. This holds only while nobody who can create pods in this namespace sets these labels
# freely (see D23 in the topic's plan). Egress stays open.
#
# A gateway that publishes a topic or an agent (see the installation docs) needs one more rule of its own in the
# topic or agent policy, for example:
#   - from:
#     - namespaceSelector:
#         matchLabels:
#           kubernetes.io/metadata.name: ingress-nginx
#     ports:
#     - protocol: TCP
#       port: 8080
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: aiknowledgefabric-topic-chat
  namespace: aiknowledgefabric
spec:
  podSelector:
    matchExpressions:
    - key: cyrock.ai/role
      operator: In
      values: ["chat", "all"]
  policyTypes: ["Ingress"]
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: aiknowledgefabric
    - podSelector:
        matchLabels:
          managed-by: aiknowledgefabric
    ports:
    - protocol: TCP
      port: 8080
---
# Agent pods (the StatefulSet agent-<id>; label cyrock.ai/agent-id, which their tool pods do not carry). Callers:
# - the app: chat, pipeline checks and status, logs and DEV reports of every pod;
# - other agent pods: a REMOTE_PIPELINE module calling another agent's /mcp (its URL is the other agent's Service),
#   and an agent's own pods forwarding a resume or abort of a paused run to the pod that holds it (peers Service).
# Topics and GraphRAG topics never call an agent. MCP clients outside the cluster reach an agent only through a gateway
# the admin publishes it with (rule above), or through the app.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: aiknowledgefabric-agent
  namespace: aiknowledgefabric
spec:
  podSelector:
    matchLabels:
      managed-by: aiknowledgefabric
    matchExpressions:
    - key: cyrock.ai/agent-id
      operator: Exists
  policyTypes: ["Ingress"]
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: aiknowledgefabric
    - podSelector:
        matchLabels:
          managed-by: aiknowledgefabric
        matchExpressions:
        - key: cyrock.ai/agent-id
          operator: Exists
    ports:
    - protocol: TCP
      port: 8080
---
# MCP_DOCKER tool pods an agent creates (label ai.cyrock.managed): no ingress at all. The agent talks to the MCP server
# in them through exec on the API server.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: aiknowledgefabric-agent-tool-pods
  namespace: aiknowledgefabric
spec:
  podSelector:
    matchExpressions:
    - key: ai.cyrock.managed
      operator: Exists
  policyTypes: ["Ingress"]
---
# PYTHON_SCRIPT Job pods an agent creates (label ai.cyrock.python-script, which the agent puts on the Job's pod
# template): no ingress at all (the agent reads their output from the pod log).
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: aiknowledgefabric-agent-job-pods
  namespace: aiknowledgefabric
spec:
  podSelector:
    matchExpressions:
    - key: ai.cyrock.python-script
      operator: Exists
  policyTypes: ["Ingress"]
---
# Who may reach the configuration database (D42): the app, the servers of topics and GraphRAG topics reading and
# writing their chat history with their own login (Postgres limits each login to its topic's rows), and agent pods
# (label cyrock.ai/agent-id; pod -0 also stores scheduled runs), with the agent's own login. The pods an agent starts
# for its tools (no managed-by label) need no access.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: aiknowledgefabric-postgres
  namespace: aiknowledgefabric
spec:
  podSelector:
    matchLabels:
      app: postgres
  policyTypes: ["Ingress"]
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: aiknowledgefabric
    - podSelector:
        matchLabels:
          managed-by: aiknowledgefabric
        matchExpressions:
        - key: cyrock.ai/role
          operator: In
          values: ["chat", "all"]
    - podSelector:
        matchLabels:
          managed-by: aiknowledgefabric
        matchExpressions:
        - key: cyrock.ai/agent-id
          operator: Exists
    ports:
    - protocol: TCP
      port: 5432

5. admission-policy.yaml

# What the agents' ServiceAccount (aiknowledgefabric-agent, rbac.yaml) may create, delete and exec into, checked by the
# API server itself. Its Role lets an agent create and delete pods, Jobs and ConfigMaps, create Secrets and exec into
# pods in this namespace; these policies narrow that to the shapes the agent really creates and to each agent pod's own
# tool workloads, so a compromised agent pod cannot start a privileged pod, mount a node's disk, mount a ServiceAccount
# token or another Secret, exec into the app, Postgres, a topic or another agent's tools, plant a Secret the app or
# Kubernetes would trust, or delete what is not its own. Apply once per installation, after rbac.yaml:
#   kubectl apply -f k8s/admission-policy.yaml
# Needs Kubernetes 1.30 or newer (ValidatingAdmissionPolicy, admissionregistration.k8s.io/v1, and the pod name and uid
# in a bound ServiceAccount token, which every pod gets). The objects are cluster-wide; they match only requests of
# that one ServiceAccount, by its user name, which names the namespace: with another namespace than aiknowledgefabric,
# change it in the six matchConditions.
#
# Each agent pod is told apart by the pod its token was issued for (request.userInfo.extra
# authentication.kubernetes.io/pod-name and pod-uid, set by the API server; a request without them is denied):
# - Pods (MCP_DOCKER tools): name mcp-<agent pod name>-*, label ai.cyrock.managed, owned by the calling agent pod (its
#   uid) and by nothing else. Delete: only pods so named and owned by the calling agent pod. The only Secret a tool pod
#   refers to (envFrom, secretKeyRef) is its own env Secret, named like the pod; no secret or projected-secret volume.
# - Secrets (a tool pod's env): create only, name mcp-<agent pod name>-*, type Opaque, owned by a Pod of the Secret's
#   own name and by nothing else (at least one owner: the garbage collector deletes it with its tool pod).
# - Jobs (PYTHON_SCRIPT): name python-script-*, label ai.cyrock.python-script on the pod template, owned by the
#   calling agent pod and by nothing else, referring to no Secret. Delete: only Jobs owned by the calling agent pod.
#   The Job's pods and its ConfigMap are removed by Kubernetes (Job controller, garbage collector) under their own
#   identities.
# - ConfigMaps (a script Job's input): create and delete only python-script-*.
# - Pods and Jobs: no ServiceAccount token and no other ServiceAccount than default, no host network, PID or IPC
#   namespace, no hostPath volume; every container and init container unprivileged, without privilege escalation and
#   without added capabilities.
# - exec: only into the calling agent pod's own tool pods (mcp-<agent pod name>-*; the trailing - keeps agent-x-1 out
#   of agent-x-10's pods).
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: aiknowledgefabric-agent-pods
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups: [""]
      apiVersions: ["v1"]
      operations: ["CREATE"]
      resources: ["pods"]
  matchConditions:
  - name: agent-service-account
    expression: "request.userInfo.username == 'system:serviceaccount:aiknowledgefabric:aiknowledgefabric-agent'"
  variables:
  - name: podName
    expression: "has(request.userInfo.extra) && 'authentication.kubernetes.io/pod-name' in request.userInfo.extra && size(request.userInfo.extra['authentication.kubernetes.io/pod-name']) == 1 ? request.userInfo.extra['authentication.kubernetes.io/pod-name'][0] : ''"
  - name: podUid
    expression: "has(request.userInfo.extra) && 'authentication.kubernetes.io/pod-uid' in request.userInfo.extra && size(request.userInfo.extra['authentication.kubernetes.io/pod-uid']) == 1 ? request.userInfo.extra['authentication.kubernetes.io/pod-uid'][0] : ''"
  - name: spec
    expression: "object.spec"
  - name: containers
    expression: "object.spec.containers + (has(object.spec.initContainers) ? object.spec.initContainers : [])"
  validations:
  - expression: "variables.podName != '' && variables.podUid != ''"
    message: "Only an agent pod creates tool pods (its ServiceAccount token names no pod)."
  - expression: "object.metadata.name.startsWith('mcp-' + variables.podName + '-')"
    message: "An agent pod creates only its own tool pods, named mcp-<agent pod name>-*."
  - expression: "has(object.metadata.labels) && 'ai.cyrock.managed' in object.metadata.labels"
    message: "An agent's tool pod carries the label ai.cyrock.managed."
  - expression: "has(object.metadata.ownerReferences) && object.metadata.ownerReferences.exists(r, r.apiVersion == 'v1' && r.kind == 'Pod' && r.name == variables.podName && r.uid == variables.podUid) && object.metadata.ownerReferences.all(r, r.uid == variables.podUid)"
    message: "An agent's tool pod is owned by the agent pod that creates it, and by nothing else."
  - expression: "has(variables.spec.automountServiceAccountToken) && variables.spec.automountServiceAccountToken == false"
    message: "automountServiceAccountToken must be false."
  - expression: "(!has(variables.spec.serviceAccountName) || variables.spec.serviceAccountName in ['', 'default']) && (!has(variables.spec.serviceAccount) || variables.spec.serviceAccount in ['', 'default'])"
    message: "Only the default ServiceAccount."
  - expression: "!(has(variables.spec.hostNetwork) && variables.spec.hostNetwork) && !(has(variables.spec.hostPID) && variables.spec.hostPID) && !(has(variables.spec.hostIPC) && variables.spec.hostIPC)"
    message: "No host network, PID or IPC namespace."
  - expression: "!has(variables.spec.volumes) || variables.spec.volumes.all(v, !has(v.hostPath))"
    message: "No hostPath volume."
  - expression: "variables.containers.all(c, !has(c.securityContext) || !has(c.securityContext.privileged) || c.securityContext.privileged == false)"
    message: "No privileged container."
  - expression: "variables.containers.all(c, has(c.securityContext) && has(c.securityContext.allowPrivilegeEscalation) && c.securityContext.allowPrivilegeEscalation == false)"
    message: "Every container sets allowPrivilegeEscalation: false."
  - expression: "variables.containers.all(c, !has(c.securityContext) || !has(c.securityContext.capabilities) || !has(c.securityContext.capabilities.add) || size(c.securityContext.capabilities.add) == 0)"
    message: "No container adds capabilities."
  - expression: "variables.containers.all(c, (!has(c.envFrom) || c.envFrom.all(e, !has(e.secretRef) || e.secretRef.name == object.metadata.name)) && (!has(c.env) || c.env.all(e, !has(e.valueFrom) || !has(e.valueFrom.secretKeyRef) || e.valueFrom.secretKeyRef.name == object.metadata.name)))"
    message: "A tool pod's env refers to no Secret but its own, named like the pod."
  - expression: "!has(variables.spec.volumes) || variables.spec.volumes.all(v, !has(v.secret) && (!has(v.projected) || !has(v.projected.sources) || v.projected.sources.all(s, !has(s.secret))))"
    message: "No secret volume."
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
  name: aiknowledgefabric-agent-pods
spec:
  policyName: aiknowledgefabric-agent-pods
  validationActions: [Deny]
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: aiknowledgefabric-agent-jobs
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups: ["batch"]
      apiVersions: ["v1"]
      operations: ["CREATE"]
      resources: ["jobs"]
  matchConditions:
  - name: agent-service-account
    expression: "request.userInfo.username == 'system:serviceaccount:aiknowledgefabric:aiknowledgefabric-agent'"
  variables:
  - name: podName
    expression: "has(request.userInfo.extra) && 'authentication.kubernetes.io/pod-name' in request.userInfo.extra && size(request.userInfo.extra['authentication.kubernetes.io/pod-name']) == 1 ? request.userInfo.extra['authentication.kubernetes.io/pod-name'][0] : ''"
  - name: podUid
    expression: "has(request.userInfo.extra) && 'authentication.kubernetes.io/pod-uid' in request.userInfo.extra && size(request.userInfo.extra['authentication.kubernetes.io/pod-uid']) == 1 ? request.userInfo.extra['authentication.kubernetes.io/pod-uid'][0] : ''"
  - name: spec
    expression: "object.spec.template.spec"
  - name: containers
    expression: "object.spec.template.spec.containers + (has(object.spec.template.spec.initContainers) ? object.spec.template.spec.initContainers : [])"
  validations:
  - expression: "variables.podName != '' && variables.podUid != ''"
    message: "Only an agent pod creates script Jobs (its ServiceAccount token names no pod)."
  - expression: "object.metadata.name.startsWith('python-script-')"
    message: "An agent creates only its script Jobs, named python-script-*."
  - expression: "has(object.spec.template.metadata) && has(object.spec.template.metadata.labels) && 'ai.cyrock.python-script' in object.spec.template.metadata.labels"
    message: "An agent's script Job carries the label ai.cyrock.python-script on its pod template."
  - expression: "has(object.metadata.ownerReferences) && object.metadata.ownerReferences.exists(r, r.apiVersion == 'v1' && r.kind == 'Pod' && r.name == variables.podName && r.uid == variables.podUid) && object.metadata.ownerReferences.all(r, r.uid == variables.podUid)"
    message: "An agent's script Job is owned by the agent pod that creates it, and by nothing else."
  - expression: "has(variables.spec.automountServiceAccountToken) && variables.spec.automountServiceAccountToken == false"
    message: "automountServiceAccountToken must be false."
  - expression: "(!has(variables.spec.serviceAccountName) || variables.spec.serviceAccountName in ['', 'default']) && (!has(variables.spec.serviceAccount) || variables.spec.serviceAccount in ['', 'default'])"
    message: "Only the default ServiceAccount."
  - expression: "!(has(variables.spec.hostNetwork) && variables.spec.hostNetwork) && !(has(variables.spec.hostPID) && variables.spec.hostPID) && !(has(variables.spec.hostIPC) && variables.spec.hostIPC)"
    message: "No host network, PID or IPC namespace."
  - expression: "!has(variables.spec.volumes) || variables.spec.volumes.all(v, !has(v.hostPath))"
    message: "No hostPath volume."
  - expression: "variables.containers.all(c, !has(c.securityContext) || !has(c.securityContext.privileged) || c.securityContext.privileged == false)"
    message: "No privileged container."
  - expression: "variables.containers.all(c, has(c.securityContext) && has(c.securityContext.allowPrivilegeEscalation) && c.securityContext.allowPrivilegeEscalation == false)"
    message: "Every container sets allowPrivilegeEscalation: false."
  - expression: "variables.containers.all(c, !has(c.securityContext) || !has(c.securityContext.capabilities) || !has(c.securityContext.capabilities.add) || size(c.securityContext.capabilities.add) == 0)"
    message: "No container adds capabilities."
  - expression: "variables.containers.all(c, (!has(c.envFrom) || c.envFrom.all(e, !has(e.secretRef))) && (!has(c.env) || c.env.all(e, !has(e.valueFrom) || !has(e.valueFrom.secretKeyRef))))"
    message: "A script Job's env refers to no Secret."
  - expression: "!has(variables.spec.volumes) || variables.spec.volumes.all(v, !has(v.secret) && (!has(v.projected) || !has(v.projected.sources) || v.projected.sources.all(s, !has(s.secret))))"
    message: "No secret volume."
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
  name: aiknowledgefabric-agent-jobs
spec:
  policyName: aiknowledgefabric-agent-jobs
  validationActions: [Deny]
---
# Deletes: an agent pod deletes only its own tool pods and script Jobs (it deletes a Job with propagationPolicy
# Background; the garbage collector then deletes the Job's pods and ConfigMap as itself, not as the agent).
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: aiknowledgefabric-agent-deletes
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups: [""]
      apiVersions: ["v1"]
      operations: ["DELETE"]
      resources: ["pods"]
    - apiGroups: ["batch"]
      apiVersions: ["v1"]
      operations: ["DELETE"]
      resources: ["jobs"]
  matchConditions:
  - name: agent-service-account
    expression: "request.userInfo.username == 'system:serviceaccount:aiknowledgefabric:aiknowledgefabric-agent'"
  variables:
  - name: podName
    expression: "has(request.userInfo.extra) && 'authentication.kubernetes.io/pod-name' in request.userInfo.extra && size(request.userInfo.extra['authentication.kubernetes.io/pod-name']) == 1 ? request.userInfo.extra['authentication.kubernetes.io/pod-name'][0] : ''"
  - name: podUid
    expression: "has(request.userInfo.extra) && 'authentication.kubernetes.io/pod-uid' in request.userInfo.extra && size(request.userInfo.extra['authentication.kubernetes.io/pod-uid']) == 1 ? request.userInfo.extra['authentication.kubernetes.io/pod-uid'][0] : ''"
  validations:
  - expression: "variables.podName != '' && variables.podUid != ''"
    message: "Only an agent pod deletes its tool pods and Jobs (its ServiceAccount token names no pod)."
  - expression: "request.resource.resource == 'pods' ? request.name.startsWith('mcp-' + variables.podName + '-') : request.name.startsWith('python-script-')"
    message: "An agent pod deletes only its own tool pods (mcp-<agent pod name>-*) and script Jobs (python-script-*)."
  - expression: "has(oldObject.metadata.ownerReferences) && oldObject.metadata.ownerReferences.exists(r, r.apiVersion == 'v1' && r.kind == 'Pod' && r.uid == variables.podUid)"
    message: "An agent pod deletes only what it owns."
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
  name: aiknowledgefabric-agent-deletes
spec:
  policyName: aiknowledgefabric-agent-deletes
  validationActions: [Deny]
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: aiknowledgefabric-agent-configmaps
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups: [""]
      apiVersions: ["v1"]
      operations: ["CREATE", "DELETE"]
      resources: ["configmaps"]
  matchConditions:
  - name: agent-service-account
    expression: "request.userInfo.username == 'system:serviceaccount:aiknowledgefabric:aiknowledgefabric-agent'"
  variables:
  - name: podName
    expression: "has(request.userInfo.extra) && 'authentication.kubernetes.io/pod-name' in request.userInfo.extra && size(request.userInfo.extra['authentication.kubernetes.io/pod-name']) == 1 ? request.userInfo.extra['authentication.kubernetes.io/pod-name'][0] : ''"
  - name: podUid
    expression: "has(request.userInfo.extra) && 'authentication.kubernetes.io/pod-uid' in request.userInfo.extra && size(request.userInfo.extra['authentication.kubernetes.io/pod-uid']) == 1 ? request.userInfo.extra['authentication.kubernetes.io/pod-uid'][0] : ''"
  validations:
  - expression: "variables.podName != '' && variables.podUid != ''"
    message: "Only an agent pod writes script ConfigMaps (its ServiceAccount token names no pod)."
  - expression: "request.name.startsWith('python-script-')"
    message: "An agent creates and deletes only its script ConfigMaps, named python-script-*."
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
  name: aiknowledgefabric-agent-configmaps
spec:
  policyName: aiknowledgefabric-agent-configmaps
  validationActions: [Deny]
---
# Secrets: an MCP_DOCKER tool pod's env, created after the pod and owned by it. RBAC gives the agent create only, so it
# cannot read, overwrite or delete a Secret; this keeps it from planting one the app or Kubernetes would trust (another
# name, a service-account-token or other type) or one that outlives its tool pod.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: aiknowledgefabric-agent-secrets
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups: [""]
      apiVersions: ["v1"]
      operations: ["CREATE"]
      resources: ["secrets"]
  matchConditions:
  - name: agent-service-account
    expression: "request.userInfo.username == 'system:serviceaccount:aiknowledgefabric:aiknowledgefabric-agent'"
  variables:
  - name: podName
    expression: "has(request.userInfo.extra) && 'authentication.kubernetes.io/pod-name' in request.userInfo.extra && size(request.userInfo.extra['authentication.kubernetes.io/pod-name']) == 1 ? request.userInfo.extra['authentication.kubernetes.io/pod-name'][0] : ''"
  validations:
  - expression: "variables.podName != ''"
    message: "Only an agent pod creates tool pod Secrets (its ServiceAccount token names no pod)."
  - expression: "object.metadata.name.startsWith('mcp-' + variables.podName + '-')"
    message: "An agent pod creates only its own tool pods' Secrets, named mcp-<agent pod name>-*."
  - expression: "has(object.type) && object.type == 'Opaque'"
    message: "A tool pod's Secret is of type Opaque."
  - expression: "has(object.metadata.ownerReferences) && size(object.metadata.ownerReferences) > 0 && object.metadata.ownerReferences.all(r, r.apiVersion == 'v1' && r.kind == 'Pod' && r.name == object.metadata.name)"
    message: "A tool pod's Secret is owned by the Pod of the same name, and by nothing else."
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
  name: aiknowledgefabric-agent-secrets
spec:
  policyName: aiknowledgefabric-agent-secrets
  validationActions: [Deny]
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: aiknowledgefabric-agent-exec
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups: [""]
      apiVersions: ["v1"]
      operations: ["CONNECT"]
      resources: ["pods/exec"]
  matchConditions:
  - name: agent-service-account
    expression: "request.userInfo.username == 'system:serviceaccount:aiknowledgefabric:aiknowledgefabric-agent'"
  variables:
  - name: podName
    expression: "has(request.userInfo.extra) && 'authentication.kubernetes.io/pod-name' in request.userInfo.extra && size(request.userInfo.extra['authentication.kubernetes.io/pod-name']) == 1 ? request.userInfo.extra['authentication.kubernetes.io/pod-name'][0] : ''"
  validations:
  - expression: "variables.podName != ''"
    message: "Only an agent pod execs into its tool pods (its ServiceAccount token names no pod)."
  - expression: "request.name.startsWith('mcp-' + variables.podName + '-')"
    message: "An agent pod execs only into its own tool pods, named mcp-<agent pod name>-*."
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
  name: aiknowledgefabric-agent-exec
spec:
  policyName: aiknowledgefabric-agent-exec
  validationActions: [Deny]

6. deployment.yaml

apiVersion: v1
kind: Secret
metadata:
  name: aiknowledgefabric-secrets
  namespace: aiknowledgefabric
type: Opaque
stringData:
  # MUST be changed before deploying: Postgres holds every server's API key and every database password
  # (and the key that signs every token).
  DB_PASSWORD: "admin"
  # Shared secret the topic and agent pods send when they report usage metrics. Change before deploying.
  METRICS_API_KEY: "change-me"
  # License key. Without a valid key nothing can be created or started.
  # Can also be entered later under Admin → License.
  # CYROCK_LICENSE_KEY: ""
  # OPENAI_API_KEY: ""       # add API keys here or in aiknowledgefabric-api-keys secret
---
# The key the app encrypts stored sign-ins with (connected accounts, tool providers). Create it once and keep a
# copy: without it every user has to connect their accounts again. Without the Secret the app still starts; only
# those features are off.
# kubectl create secret generic aiknowledgefabric-encryption-keys \
#   --from-literal=keys="k1=$(openssl rand -base64 32)"
---
# Separate secret for AI provider API keys referenced by topic deployments.
# kubectl -n aiknowledgefabric create secret generic aiknowledgefabric-api-keys \
#   --from-literal=OPENAI_API_KEY=sk-... \
#   --from-literal=ANTHROPIC_API_KEY=sk-ant-...
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-data
  namespace: aiknowledgefabric
spec:
  accessModes: [ReadWriteOnce]
  resources:
    requests:
      storage: 5Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
  namespace: aiknowledgefabric
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:16-alpine
        env:
        - name: POSTGRES_DB
          value: AIKnowledgeFabric
        - name: POSTGRES_USER
          value: admin
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: aiknowledgefabric-secrets
              key: DB_PASSWORD
        ports:
        - containerPort: 5432
        volumeMounts:
        - name: postgres-data
          mountPath: /var/lib/postgresql/data
        readinessProbe:
          exec:
            command: ["pg_isready", "-U", "admin", "-d", "AIKnowledgeFabric"]
          initialDelaySeconds: 5
          periodSeconds: 5
      volumes:
      - name: postgres-data
        persistentVolumeClaim:
          claimName: postgres-data
---
apiVersion: v1
kind: Service
metadata:
  name: postgres
  namespace: aiknowledgefabric
spec:
  selector:
    app: postgres
  ports:
  - port: 5432
    targetPort: 5432
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: aiknowledgefabric
  namespace: aiknowledgefabric
spec:
  replicas: 1
  selector:
    matchLabels:
      app: aiknowledgefabric
  template:
    metadata:
      labels:
        app: aiknowledgefabric
    spec:
      serviceAccountName: aiknowledgefabric
      containers:
      - name: aiknowledgefabric
        # Exact version: the app starts topic, GraphRAG and agent pods with images of this same version.
        image: cyrockai/knowledge-fabric-frontend:1.3.0
        imagePullPolicy: IfNotPresent
        # The JVM sizes its heap from the limit (70 %, see the app image), so the limit is what makes the app's
        # memory predictable. Raise it when many people use the chat in the web UI at the same time.
        resources:
          requests:
            memory: "1Gi"
          limits:
            memory: "4Gi"
        ports:
        - containerPort: 8080
        env:
        # Behind an Ingress or gateway that terminates TLS, uncomment both: the app then builds https links
        # from the proxy's headers, and the browser sends the login cookie only over https. Not the default,
        # because with plain http (no TLS anywhere) a Secure cookie is never sent and login fails.
        # - name: SERVER_FORWARDHEADERSSTRATEGY
        #   value: "native"
        # - name: SERVER_SERVLET_SESSION_COOKIE_SECURE
        #   value: "true"
        - name: ORCHESTRATION_MODE
          value: "kubernetes"
        - name: KUBERNETES_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: DB_URL
          value: "jdbc:postgresql://postgres:5432/AIKnowledgeFabric"
        - name: DB_USERNAME
          value: "admin"
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: aiknowledgefabric-secrets
              key: DB_PASSWORD
        - name: METRICS_API_KEY
          valueFrom:
            secretKeyRef:
              name: aiknowledgefabric-secrets
              key: METRICS_API_KEY
        # Where topic and agent pods reach this app (token-verification keys, service tokens, metrics):
        # this app's Service. The built-in default (host.docker.internal) exists only under Docker.
        # Adjust the namespace if you change it.
        - name: CONTAINER_FRONTEND_URL
          value: "http://aiknowledgefabric.aiknowledgefabric.svc.cluster.local:8080"
        # Where topic and agent pods read their chat history: the same database as DB_URL above. The built-in default
        # (host.docker.internal) exists only under Docker.
        - name: TOPIC_HISTORY_DB_URL
          value: "jdbc:postgresql://postgres:5432/AIKnowledgeFabric"
        - name: CYROCK_LICENSE_KEY
          valueFrom:
            secretKeyRef:
              name: aiknowledgefabric-secrets
              key: CYROCK_LICENSE_KEY
              optional: true
        - name: CYROCK_ENCRYPTION_KEYS_FILE
          value: "/run/secrets/cyrock-encryption/keys"
        volumeMounts:
        - name: encryption-keys
          mountPath: /run/secrets/cyrock-encryption
          readOnly: true
        readinessProbe:
          httpGet:
            path: /login
            port: 8080
          initialDelaySeconds: 30
          periodSeconds: 10
      volumes:
      - name: encryption-keys
        secret:
          secretName: aiknowledgefabric-encryption-keys
          optional: true
---
apiVersion: v1
kind: Service
metadata:
  name: aiknowledgefabric
  namespace: aiknowledgefabric
spec:
  selector:
    app: aiknowledgefabric
  ports:
  - port: 8080
    targetPort: 8080
  type: ClusterIP

7. What the files do and what to change

Part What it does Change it when

namespace.yaml

The namespace aiknowledgefabric, only for the app and what it starts. It is labeled with Pod Security warn/audit: restricted

You want another name: see Namespace below

rbac.yaml

Two ServiceAccounts, each with a Role and a RoleBinding. aiknowledgefabric is the app’s: it creates and removes the Deployments, StatefulSets, Services, Secrets and volumes of Topics, GraphRAG Topics, Agents and managed servers. aiknowledgefabric-agent is the Agents': it lets them start and remove their short-lived pods and jobs (Docker-based MCP tools, Python scripts) and hand a tool its settings in a Secret they may create but not read, and nothing else

Never. Without these rights, every start fails with a "forbidden" error

network-policy.yaml

Lets only the app, and the Topics, GraphRAG Topics and Agents it started, call a Topic; uploads reach a Topic only from the app. An Agent answers only the app and other Agents. The short-lived pods of Agents accept no connections at all. The database answers only the app, the Topics' chat pods and the Agents' pods, which read and write their chat history there. Needs a network plugin that enforces network policies (for example Calico or Cilium)

Never

admission-policy.yaml

Lets Kubernetes itself check every pod and job an Agent starts: only its own tool pods (mcp-…) and Python script jobs (python-script-…), without the rights of a node (no privileged containers, no host directories, no host network) and without a Kubernetes token or any other Secret than its own settings. An Agent may only create its own tool pods' settings Secrets and only open a shell connection (exec) into its own tool pods. Needs Kubernetes 1.30 or newer. Unlike the other files, its objects belong to the whole cluster, not to the namespace

You use another namespace: change aiknowledgefabric in the six request.userInfo.username lines

Secret aiknowledgefabric-secrets

The database password, the key for usage reports and, optionally, the license key

Always, before the first apply. Set DB_PASSWORD and METRICS_API_KEY to your own values. The database password counts only when the database is created for the first time

Comment block aiknowledgefabric-api-keys

Shows how to create a second Secret for the keys of your AI providers. Topics read a key from it when you enter it as ${NAME} on the AI server

You use cloud AI providers. See Keeping API keys out of the app

postgres-data volume

Holds all configuration of the app. Losing it loses everything. Back it up

Your data needs more than 5 GB

postgres Deployment and Service

The configuration database, PostgreSQL 16

Never. Another PostgreSQL version is not supported

aiknowledgefabric → image

The management app in an exact version, for example 1.3.0. The app starts Topics, GraphRAG Topics and Agents with images of the same version, so this tag decides the version of everything

You update: set the new version here. See Updating

aiknowledgefabric → resources

The memory the app may use: 4 Gi at most, 1 Gi reserved. The app sizes its working memory from the limit (70 %). See Memory of the app

Many people use the chat in the web UI at the same time, or the app restarts with out-of-memory errors. Your nodes are too small for the reserved 1 Gi

aiknowledgefabric → imagePullPolicy: IfNotPresent

Downloads the image only when the node does not have it yet. A released version never changes, so there is nothing newer to look for

Never

CONTAINER_FRONTEND_URL

The address where Topics and Agents reach the app inside the cluster

You use another namespace than aiknowledgefabric. With a wrong address, Topics and Agents refuse every request and the usage dashboard stays empty

readinessProbe

Kubernetes sends traffic to the app only once its login page answers

Never

aiknowledgefabric Service

Makes the app reachable inside the cluster on port 8080

Never. To reach it from outside, add an Ingress or a gateway of your own

Namespace: all five files use the namespace aiknowledgefabric. To use another one, replace every aiknowledgefabric namespace in them, including the one in CONTAINER_FRONTEND_URL and the one in the system:serviceaccount:aiknowledgefabric:aiknowledgefabric-agent user names of admission-policy.yaml.

More settings for the env: list of the app are in Other settings of the installation guide and in Supported settings.


8. Keeping the files up to date

The files change now and then, at least the version of the app image with every release. Compare your copies with this page after an update of the app. Copy the new lines into your files, or replace a whole file if you changed nothing in it besides the values from section 7, and then run:

kubectl apply -f namespace.yaml
kubectl apply -f rbac.yaml
kubectl apply -f network-policy.yaml
kubectl apply -f admission-policy.yaml
kubectl apply -f deployment.yaml

Running Topics and Agents are not stopped by this. The update steps say what else to do.