Skip to content

Commit d9b4d32

Browse files
committed
feat(crd): add security context and resource configuration support
Add comprehensive security and resource configuration options to the MCPServer CRD to enable production-ready deployments following Kubernetes security best practices. Signed-off-by: skhedim <sebastien.khedim@gmail.com>
1 parent dc97609 commit d9b4d32

2 files changed

Lines changed: 138 additions & 1 deletion

File tree

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Example MCPServer with production security best practices
2+
# This demonstrates all available security and resource configuration options
3+
apiVersion: kagent.dev/v1alpha1
4+
kind: MCPServer
5+
metadata:
6+
name: mcp-server-secure
7+
namespace: mcp-servers
8+
labels:
9+
environment: production
10+
team: platform
11+
spec:
12+
# Transport type: stdio (uses init container) or http
13+
transportType: stdio
14+
15+
deployment:
16+
# Container image for the MCP server
17+
image: "ghcr.io/example/mcp-server:v1.0.0"
18+
imagePullPolicy: IfNotPresent
19+
20+
# Number of replicas (optional, defaults to 1)
21+
replicas: 2
22+
23+
# Custom labels applied to pods
24+
labels:
25+
app.kubernetes.io/component: mcp-server
26+
app.kubernetes.io/part-of: ai-platform
27+
team: platform
28+
29+
# Custom annotations applied to pods
30+
annotations:
31+
prometheus.io/scrape: "true"
32+
prometheus.io/port: "8080"
33+
34+
# Image pull secrets for private registries
35+
imagePullSecrets:
36+
- name: registry-credentials
37+
38+
# Resource requests and limits for the main container
39+
resources:
40+
requests:
41+
memory: "128Mi"
42+
cpu: "100m"
43+
limits:
44+
memory: "512Mi"
45+
cpu: "500m"
46+
47+
# Container-level security context (applies to main container)
48+
securityContext:
49+
runAsNonRoot: true
50+
runAsUser: 1000
51+
runAsGroup: 1000
52+
readOnlyRootFilesystem: true
53+
allowPrivilegeEscalation: false
54+
capabilities:
55+
drop:
56+
- ALL
57+
seccompProfile:
58+
type: RuntimeDefault
59+
60+
# Pod-level security context
61+
podSecurityContext:
62+
runAsNonRoot: true
63+
runAsUser: 1000
64+
runAsGroup: 1000
65+
fsGroup: 1000
66+
seccompProfile:
67+
type: RuntimeDefault
68+
69+
# Init container configuration (for stdio transport)
70+
initContainer:
71+
# Custom image for init container (optional)
72+
# image: "ghcr.io/kagent-dev/agentgateway:latest"
73+
imagePullPolicy: IfNotPresent
74+
75+
# Resources for init container
76+
resources:
77+
requests:
78+
memory: "32Mi"
79+
cpu: "10m"
80+
limits:
81+
memory: "64Mi"
82+
cpu: "50m"
83+
84+
# Security context for init container
85+
# If not specified, inherits from main container's securityContext
86+
securityContext:
87+
runAsNonRoot: true
88+
runAsUser: 1000
89+
runAsGroup: 1000
90+
readOnlyRootFilesystem: false # Needs write access to copy binary
91+
allowPrivilegeEscalation: false
92+
capabilities:
93+
drop:
94+
- ALL
95+
96+
# Node scheduling constraints
97+
nodeSelector:
98+
kubernetes.io/os: linux
99+
# node-type: compute
100+
101+
# Pod affinity/anti-affinity rules
102+
affinity:
103+
podAntiAffinity:
104+
preferredDuringSchedulingIgnoredDuringExecution:
105+
- weight: 100
106+
podAffinityTerm:
107+
labelSelector:
108+
matchLabels:
109+
app.kubernetes.io/name: mcp-server-secure
110+
topologyKey: kubernetes.io/hostname
111+
112+
# Tolerations for tainted nodes
113+
tolerations:
114+
- key: "dedicated"
115+
operator: "Equal"
116+
value: "ai-workloads"
117+
effect: "NoSchedule"
118+
119+
# Environment variables
120+
env:
121+
- name: LOG_LEVEL
122+
value: "info"
123+
- name: MCP_SERVER_PORT
124+
value: "8080"
125+
126+
# Reference to secrets for environment variables
127+
secretRefs:
128+
- name: mcp-server-secrets
129+
key: API_KEY
130+
envName: MCP_API_KEY
131+
132+
# MCP server configuration
133+
mcpServer:
134+
name: "secure-mcp-server"
135+
args:
136+
- "--port"
137+
- "8080"

0 commit comments

Comments
 (0)