openclaw: añade kubectl-ro via initContainer setup-kubectl

- initContainer bitnami/kubectl copia kubectl y crea wrapper kubectl-ro en emptyDir /opt/kube
- kubectl-ro deniega verbos destructivos (delete/apply/patch/edit/exec/scale/rollout/drain/...)
- Main container monta /opt/kube; SA token automontado para in-cluster auth
- Sin kubeconfig manual: kubectl detecta KUBERNETES_SERVICE_HOST/PORT automáticamente

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-24 14:33:17 +00:00
parent e176bb9810
commit 792b53dee7
+32
View File
@@ -19,6 +19,34 @@ spec:
securityContext: securityContext:
runAsUser: 1000 runAsUser: 1000
fsGroup: 1000 fsGroup: 1000
initContainers:
- name: setup-kubectl
image: bitnami/kubectl:latest
imagePullPolicy: IfNotPresent
command:
- sh
- -c
- |
cp $(which kubectl) /opt/kube/kubectl
chmod +x /opt/kube/kubectl
cat > /opt/kube/kubectl-ro << 'SCRIPT'
#!/bin/sh
DENIED="delete apply patch edit exec scale rollout drain cordon uncordon taint replace create annotate label"
if [ "$#" -eq 0 ]; then exec /opt/kube/kubectl "$@"; fi
SUBCMD="$1"
for d in $DENIED; do
if [ "$SUBCMD" = "$d" ]; then
echo "ERROR: \"$SUBCMD\" no permitido en modo solo lectura." >&2; exit 1
fi
done
exec /opt/kube/kubectl "$@"
SCRIPT
chmod +x /opt/kube/kubectl-ro
volumeMounts:
- name: kube-tools
mountPath: /opt/kube
securityContext:
runAsUser: 0
containers: containers:
- name: openclaw - name: openclaw
image: ghcr.io/openclaw/openclaw:2026.4.22 image: ghcr.io/openclaw/openclaw:2026.4.22
@@ -38,7 +66,11 @@ spec:
volumeMounts: volumeMounts:
- name: data - name: data
mountPath: /home/node/.openclaw mountPath: /home/node/.openclaw
- name: kube-tools
mountPath: /opt/kube
volumes: volumes:
- name: data - name: data
persistentVolumeClaim: persistentVolumeClaim:
claimName: openclaw-pvc claimName: openclaw-pvc
- name: kube-tools
emptyDir: {}