Fix K8s deployment with init container and proper security context
Build and Deploy to K3s / test (push) Successful in 2m5s
Build and Deploy to K3s / lint (push) Successful in 1m33s
Build and Deploy to K3s / build-and-push (push) Successful in 48s
Build and Deploy to K3s / deploy (push) Failing after 5m42s

- Add init container to set up config files with correct ownership
- Run main container as socktop user (UID 100, GID 101) from the start
- Use fsGroup to ensure proper volume permissions
- Add emptyDir volume for /var/lib/socktop to avoid permission issues
- Create docker-entrypoint.sh wrapper to detect root vs non-root execution
  - Root mode: uses init-config.sh for Docker/docker-compose
  - Non-root mode: directly runs entrypoint.sh for K8s
- Update deployment command format to work with new entrypoint

This resolves 'Operation not permitted' errors when running in K8s
with security contexts that restrict user switching and ownership changes.
This commit is contained in:
2025-11-30 04:22:43 -08:00
parent e870e2e4ec
commit 6915079e5c
2 changed files with 96 additions and 4 deletions
+13 -3
View File
@@ -122,8 +122,18 @@ EXPOSE 8082 3001
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8082/ || exit 1
# Set entrypoint (init-config.sh runs as root, copies configs, then switches to socktop user)
ENTRYPOINT ["/init-config.sh"]
# Create a wrapper script that detects if running as root or socktop user
RUN echo '#!/bin/bash\n\
if [ "$(id -u)" -eq 0 ]; then\n\
# Running as root - use init-config.sh to set up and switch to socktop\n\
exec /init-config.sh "$@"\n\
else\n\
# Running as socktop user - directly execute entrypoint\n\
exec /entrypoint.sh "$@"\n\
fi' > /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh
# Set entrypoint to the wrapper
ENTRYPOINT ["/docker-entrypoint.sh"]
# Default command - use restricted shell that only allows socktop commands
CMD ["/entrypoint.sh", "webterm-server", "--host", "0.0.0.0", "--port", "8082", "--command", "/usr/local/bin/restricted-shell.sh"]
CMD ["webterm-server", "--host", "0.0.0.0", "--port", "8082", "--command", "/usr/local/bin/restricted-shell.sh"]