Custom Shell Containers
The shell container is where users execute commands. Customize it based on your scenario’s requirements.
Using Standard Images
For simple scenarios, use standard container images:
shell: image: repository: debian tag: bookworm pullPolicy: IfNotPresent
command: ["sleep"] args: ["infinity"]Common Base Images
| Image | Use Case |
|---|---|
debian:bookworm | General purpose, most tools available |
ubuntu:22.04 | Similar to Debian, some prefer it |
alpine:3.19 | Minimal, fast, uses apk |
python:3.11 | Python development |
node:20 | Node.js development |
golang:1.22 | Go development |
Building Custom Images
For scenarios requiring specific tools, build a custom image.
Basic Template
FROM debian:bookworm
# Install required toolsRUN apt-get update && apt-get install -y --no-install-recommends \ curl \ vim \ git \ jq \ # Add your tools here && rm -rf /var/lib/apt/lists/*
# Create workspaceRUN mkdir -p /workspace && chmod 777 /workspaceWORKDIR /workspace
# Custom promptRUN echo 'export PS1="\[\e[32m\]\u@learning\[\e[0m\]:\[\e[34m\]\w\[\e[0m\]\$ "' >> /etc/bash.bashrc
CMD ["sleep", "infinity"]Build and Push
# Builddocker build -f Containerfile.my-scenario -t myregistry/my-learning-shell:v1 .
# Push to registrydocker push myregistry/my-learning-shell:v1Use in Values
shell: image: repository: myregistry/my-learning-shell tag: v1 pullPolicy: IfNotPresentExample: Kubernetes Shell
Shell with kubectl, helm, and k9s:
FROM debian:bookworm
ARG TARGETARCH
# Install base toolsRUN apt-get update && apt-get install -y --no-install-recommends \ curl \ wget \ ca-certificates \ bash-completion \ vim \ nano \ less \ jq \ git \ tree \ && rm -rf /var/lib/apt/lists/*
# Install kubectlRUN ARCH=${TARGETARCH:-amd64} && \ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${ARCH}/kubectl" && \ chmod +x kubectl && \ mv kubectl /usr/local/bin/
# Install helmRUN ARCH=${TARGETARCH:-amd64} && \ curl -fsSL https://get.helm.sh/helm-v3.14.0-linux-${ARCH}.tar.gz | tar xz && \ mv linux-${ARCH}/helm /usr/local/bin/ && \ rm -rf linux-${ARCH}
# Install k9sRUN ARCH=${TARGETARCH:-amd64} && \ curl -fsSL "https://github.com/derailed/k9s/releases/download/v0.32.4/k9s_Linux_${ARCH}.tar.gz" | tar xz -C /usr/local/bin k9s
# Setup bash completionRUN echo 'source /etc/bash_completion 2>/dev/null || true' >> /etc/bash.bashrc && \ echo 'source <(kubectl completion bash)' >> /etc/bash.bashrc && \ echo 'source <(helm completion bash)' >> /etc/bash.bashrc && \ echo 'alias k=kubectl' >> /etc/bash.bashrc && \ echo 'complete -o default -F __start_kubectl k' >> /etc/bash.bashrc
WORKDIR /workspaceCMD ["sleep", "infinity"]Example: Python Data Science
Shell for data science tutorials:
FROM python:3.11-slim
RUN apt-get update && apt-get install -y --no-install-recommends \ git \ curl \ vim \ && rm -rf /var/lib/apt/lists/*
# Install data science packagesRUN pip install --no-cache-dir \ pandas \ numpy \ matplotlib \ seaborn \ scikit-learn \ jupyter \ ipython
WORKDIR /workspaceCMD ["sleep", "infinity"]Example: Network Tools
Shell for networking tutorials:
FROM debian:bookworm
RUN apt-get update && apt-get install -y --no-install-recommends \ net-tools \ iputils-ping \ dnsutils \ tcpdump \ nmap \ netcat-openbsd \ iproute2 \ iptables \ curl \ wget \ vim \ && rm -rf /var/lib/apt/lists/*
WORKDIR /workspaceCMD ["sleep", "infinity"]Example: Cryptography
Shell for cryptography tutorials:
FROM debian:bookworm
RUN apt-get update && apt-get install -y --no-install-recommends \ openssl \ gnupg \ xxd \ vim \ less \ && rm -rf /var/lib/apt/lists/*
WORKDIR /workspaceCMD ["sleep", "infinity"]Local Development with Kind
For local development, load images directly into Kind:
# Build locallydocker build -f Containerfile.my-scenario -t my-learning-shell:latest .
# Load into Kind clusterkind load docker-image my-learning-shell:latest --name my-clusterConfigure to use local image:
shell: image: repository: my-learning-shell tag: latest pullPolicy: IfNotPresent # Important: don't try to pullSecurity Considerations
Capabilities
By default, drop all capabilities and add only what’s needed:
shell: securityContext: capabilities: drop: - ALL add: - SETGID # For sudo/su - SETUID # For sudo/su - NET_RAW # For ping, tcpdump allowPrivilegeEscalation: falseRead-Only Root Filesystem
For extra security (may break some tools):
shell: securityContext: readOnlyRootFilesystem: trueNon-Root User
Run as non-root (may require image changes):
shell: securityContext: runAsNonRoot: true runAsUser: 1000Troubleshooting
Image not pulling
For local images in Kind:
shell: image: pullPolicy: IfNotPresent # Not "Always"Missing tools
If a tool is missing at runtime, either:
- Add it to the Containerfile and rebuild
- Install at runtime (not recommended for production)
Permission issues
Check the security context and ensure the workspace is writable:
RUN mkdir -p /workspace && chmod 777 /workspace