A lightweight, secure Alpine-based container image with kubectl client.
1.5K
A lightweight, secure Alpine-based container image with kubectl client, designed for running Kubernetes jobs and automation tasks within clusters. Perfect for PersistentVolume reconciliation, cluster management jobs, and GitOps workflows.
Now available in three optimized variants:
Choose the right variant for your needs:
| Variant | Tag | Size | Bash | Shell | UPX | Best For |
|---|---|---|---|---|---|---|
| Standard | 1.0.0 | 76 MB | β Yes | sh + bash | β No | Production, complex scripts, debugging |
| Slim | 1.0.0-slim | 20 MB | β No | sh only | β Yes | Size-critical, simple scripts, CI/CD |
| Minimal | 1.0.0-minimal | 14 MB | β No | β None | β Yes | Maximum security, no debugging needed |
# Run kubectl command
docker run --rm boyroywax/kubectl:1.0.0 version --client
# Interactive shell
docker run --rm -it boyroywax/kubectl:1.0.0 /bin/bash
# Ultra-lightweight kubectl with UPX compression
docker run --rm boyroywax/kubectl:1.0.0-slim version --client
# Interactive shell (sh only)
docker run --rm -it boyroywax/kubectl:1.0.0-slim /bin/sh
# Distroless - no shell, maximum security
docker run --rm boyroywax/kubectl:1.0.0-minimal version --client
# Note: No shell available in minimal variant (by design)
# Mount kubeconfig for cluster access (works with both variants)
docker run --rm \
-v ~/.kube/config:/root/.kube/config:ro \
boyroywax/kubectl:1.0.0 get pods
apiVersion: batch/v1
kind: Job
metadata:
name: create-nfs-pv
spec:
template:
spec:
serviceAccountName: pv-creator
containers:
- name: kubectl
image: boyroywax/kubectl:1.0.0
command: ["/bin/bash", "-c"]
args:
- |
kubectl apply -f - <<EOF
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 100Gi
accessModes:
- ReadWriteMany
nfs:
server: nfs-server.default.svc.cluster.local
path: /nfsshare/data
EOF
restartPolicy: OnFailure
apiVersion: batch/v1
kind: Job
metadata:
name: cleanup-resources
spec:
template:
spec:
serviceAccountName: cluster-admin
containers:
- name: kubectl
image: boyroywax/kubectl:1.0.0
command: ["/bin/bash", "-c"]
args:
- |
# Cleanup old pods
kubectl delete pods --field-selector status.phase=Failed -n default
# Check cluster status
kubectl get nodes
restartPolicy: OnFailure
| Argument | Default | Description |
|---|---|---|
KUBECTL_VERSION | v1.33.5 | Kubernetes client version to install |
| Variable | Purpose | Example |
|---|---|---|
KUBECONFIG | Path to kubeconfig file | /root/.kube/config |
kubectl - Kubernetes command-line tool (v1.33.5, 57MB uncompressed)curl - Data transfer utilityca-certificates - SSL/TLS certificate bundlebash - GNU Bourne-Again shellkubectl - Kubernetes command-line tool (v1.33.5, 11MB UPX compressed)ca-certificates - SSL/TLS certificate bundlesh - POSIX shell (busybox)kubectl - Kubernetes command-line tool (v1.33.5, 11MB UPX compressed)ca-certificates - SSL/TLS certificate bundle# Clone the repository
git clone https://github.com/boyroywax/kubectl.git
cd kubectl
# Build all variants (default)
./build-with-attestation.sh
# Build standard variant only
./build-with-attestation.sh standard
# Build slim variant only
./build-with-attestation.sh slim
# Build minimal variant only
./build-with-attestation.sh minimal
# Build with specific kubectl version
./build-with-attestation.sh all 1.0.0 v1.31.0
# Standard variant (76 MB)
docker build -t kubectl:1.0.0 -f Dockerfile .
# Slim variant (20 MB) - with UPX compression
docker build -t kubectl:1.0.0-slim -f Dockerfile.slim .
# Minimal variant (14 MB) - distroless
docker build -t kubectl:1.0.0-minimal -f Dockerfile.minimal .
# With specific kubectl version
docker build --build-arg KUBECTL_VERSION=v1.31.0 -t kubectl:1.31.0 .
export REGISTRY="registry.example.com/your-namespace"
export IMAGE_NAME="${REGISTRY}/kubectl"
docker build --build-arg KUBECTL_VERSION=v1.33.5 -t "${IMAGE_NAME}:v1.33.5" .
docker push "${IMAGE_NAME}:v1.33.5"
# Build with SBOM and provenance
./build-with-attestation.sh
Update your Helm chart values to use the kubectl image:
nfs:
pv:
enabled: true
jobImage:
repository: boyroywax/kubectl
tag: 1.0.0
pullPolicy: IfNotPresent
apiVersion: batch/v1
kind: CronJob
metadata:
name: cluster-health-check
spec:
schedule: "0 */6 * * *" # Every 6 hours
jobTemplate:
spec:
template:
spec:
serviceAccountName: cluster-reader
containers:
- name: kubectl
image: boyroywax/kubectl:1.0.0
command: ["/bin/bash", "-c"]
args:
- |
echo "=== Cluster Health Check ==="
kubectl get nodes
kubectl get pods --all-namespaces | grep -v Running
restartPolicy: OnFailure
# Build image with multiple kubeconfig contexts
docker run --rm \
-v ~/.kube/config:/root/.kube/config:ro \
boyroywax/kubectl:1.0.0 \
config get-contexts
Problem: Job fails with RBAC errors
Error from server (Forbidden): persistentvolumes is forbidden
Solution: Create appropriate ServiceAccount and RBAC:
apiVersion: v1
kind: ServiceAccount
metadata:
name: pv-creator
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: pv-creator
rules:
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["create", "get", "list", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: pv-creator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: pv-creator
subjects:
- kind: ServiceAccount
name: pv-creator
namespace: default
Problem: Command not found errors
/bin/sh: kubectl: not found
Solution: Ensure you're using the correct entrypoint:
command: ["/usr/local/bin/kubectl"]
# Or use full path in scripts
args: ["/usr/local/bin/kubectl get pods"]
Problem: API version mismatch
error: SchemaError(io.k8s.api.core.v1.PersistentVolume)
Solution: Build with compatible kubectl version:
# Check cluster version
kubectl version --short
# Build with matching version
docker build --build-arg KUBECTL_VERSION=v1.30.0 -t kubectl:1.30.0 .
Problem: Cannot connect to cluster
The connection to the server localhost:8080 was refused
Solution: Ensure in-cluster config or mounted kubeconfig:
# Use in-cluster service account (recommended)
serviceAccountName: kubectl-runner
# Or mount kubeconfig
volumes:
- name: kubeconfig
secret:
secretName: kubeconfig-secret
volumeMounts:
- name: kubeconfig
mountPath: /root/.kube
readOnly: true
To use a different kubectl version:
Build with new version:
docker build --build-arg KUBECTL_VERSION=v1.34.0 -t kubectl:1.34.0 .
Update Helm values:
jobImage:
tag: 1.34.0
Verify version:
kubectl run test --rm -it --image=kubectl:1.34.0 -- version --client
/usr/local/bin/kubectl--help/usr/local/bin/kubectl--help/usr/local/bin/kubectl--helpContributions are welcome! Please feel free to submit a Pull Request.
# Clone the repository
git clone https://github.com/boyroywax/kubectl.git
cd kubectl
# Build locally
docker build -t kubectl:dev .
# Test
docker run --rm kubectl:dev version --client
This project is licensed under the MIT License - see the LICENSEβ file for details.
Docker Hub: https://hub.docker.com/r/boyroywax/kubectlβ
Content type
Image
Digest
sha256:70b2a4730β¦
Size
27.5 MB
Last updated
about 1 year ago
docker pull boyroywax/kubectl