Docker
Kubernetes
Dockerfile
Containerization
DevOps

Deploying local Docker image DockerFIle as local Kubernetes pod

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Deploying a local Docker image to a local Kubernetes pod is a common development workflow for rapid iteration. The key challenge is making sure the cluster can access your locally built image without pulling from a remote registry. The exact steps depend on your local Kubernetes runtime.

Build the Local Image

Start with a simple Dockerfile and build the image.

dockerfile
1FROM python:3.12-slim
2WORKDIR /app
3COPY app.py .
4CMD ["python", "app.py"]
bash
docker build -t local-demo:0.1 .

Confirm it exists locally:

bash
docker images | grep local-demo

Option 1: Minikube Image Load

If using Minikube, load the image into the cluster runtime.

bash
minikube image load local-demo:0.1

Then deploy with imagePullPolicy: IfNotPresent.

yaml
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4  name: local-demo
5spec:
6  replicas: 1
7  selector:
8    matchLabels:
9      app: local-demo
10  template:
11    metadata:
12      labels:
13        app: local-demo
14    spec:
15      containers:
16        - name: app
17          image: local-demo:0.1
18          imagePullPolicy: IfNotPresent
19          ports:
20            - containerPort: 8000

Apply and inspect:

bash
kubectl apply -f deployment.yaml
kubectl get pods

Option 2: Kind Cluster Image Load

For Kind, use kind load docker-image.

bash
kind load docker-image local-demo:0.1 --name kind
kubectl apply -f deployment.yaml

This copies the local image into Kind node containers.

Option 3: Docker Desktop Kubernetes

When Docker Desktop Kubernetes is enabled, local images are usually visible directly because Docker and Kubernetes share runtime context. Still keep IfNotPresent to avoid unnecessary pulls.

Debugging Image Pull Failures

If pod status is ImagePullBackOff or ErrImagePull, inspect events.

bash
kubectl describe pod local-demo-abc123
kubectl get events --sort-by=.metadata.creationTimestamp

Common causes:

  • image tag mismatch between build and deployment
  • imagePullPolicy: Always forcing remote pull
  • wrong cluster context

Check context before deploying:

bash
kubectl config current-context

Fast Iteration Workflow

For rapid local development:

  • rebuild image with same tag
  • reload into cluster runtime if required
  • restart deployment pods
bash
docker build -t local-demo:0.1 .
minikube image load local-demo:0.1
kubectl rollout restart deployment/local-demo

Using a consistent process prevents confusion across local cluster tools.

Local Registry Alternative

If you rebuild often, a local registry can simplify image distribution across multiple local clusters. Build and push once, then pull from a consistent local endpoint.

bash
docker run -d -p 5000:5000 --name registry registry:2
docker tag local-demo:0.1 localhost:5000/local-demo:0.1
docker push localhost:5000/local-demo:0.1

Update deployment image:

yaml
image: localhost:5000/local-demo:0.1
imagePullPolicy: IfNotPresent

This pattern helps when teammates use different local runtimes and you need a shared, low-latency image source for development.

Service Exposure for Local Testing

After deployment, expose the pod with a service so you can validate end-to-end behavior.

bash
kubectl expose deployment local-demo --port 80 --target-port 8000
kubectl port-forward service/local-demo 8080:80
curl http://127.0.0.1:8080

This confirms image load, pod startup, and networking path in one quick smoke test.

Keep deployment manifests in version control so image tags and service settings stay synchronized across local environments.

Common Pitfalls

  • Building image locally but deploying to a different Kubernetes context.
  • Using imagePullPolicy: Always with a non-pushed local tag.
  • Forgetting to load image into Kind or Minikube runtime.
  • Reusing stale image tags without rebuild and rollout restart.
  • Debugging only pod logs while ignoring pull-related events.

Summary

  • Local Docker image deployment to Kubernetes depends on cluster runtime integration.
  • Use image load commands for Minikube and Kind.
  • Keep deployment image tag and local build tag identical.
  • Set imagePullPolicy to avoid accidental remote pulls.
  • Use describe and events to diagnose pull failures quickly.

Course illustration
Course illustration

All Rights Reserved.