When developing Kubernetes applications locally, Minikube provides a convenient way to spin up a single-node cluster. A crucial part of this process is building and using your own Docker or Podman images within that Minikube environment. However, the approach varies depending on your chosen containerization tool.
Docker: The Traditional Approach
For many, Docker remains the go-to containerization platform. Minikube’s integration with Docker is relatively straightforward.
Using minikube docker-env
This method leverages Minikube’s built-in Docker daemon.
- Start Minikube with the Docker driver:
bash minikube start --driver=docker - Configure your Docker CLI:
bash eval $(minikube docker-env)
This command directs your local Docker commands to the Minikube Docker daemon. - Build your image:
bash docker build -t your-image-name:tag . - Create your Kubernetes deployment YAML:
yaml apiVersion: apps/v1 kind: Deployment metadata: name: my-deployment spec: replicas: 1 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: containers: - name: my-container image: your-image-name:tag imagePullPolicy: Never # Crucial for local images - Apply the deployment:
bash kubectl apply -f your-deployment.yaml
Using minikube image load
If you’ve already built your Docker image locally, you can load it into Minikube.
- Build your image:
bash docker build -t your-image-name:tag . - Load the image into Minikube:
bash minikube image load your-image-name:tag - Deploy as described in the previous section.
Using minikube image build
Minikube also has a command that builds images directly within the minikube enviroment.
- Build your image:
bash minikube image build -t your-image-name:tag -f ./Dockerfile . - Deploy as described in the first section.
Podman: The Daemonless Alternative
Podman offers a daemonless approach to containerization. While Minikube supports Podman, the integration requires careful consideration.
Minikube with CRI-O
When using Podman, Minikube typically relies on the CRI-O container runtime.
- Start Minikube with Podman and CRI-O:
bash minikube start --driver=podman --container-runtime=cri-o - Build your image with Podman:
bash podman build -t your-image-name:tag . - Ensure CRI-O can access the image:
- This is the most challenging aspect. You might need to configure mount points or use tools like Podman Desktop to facilitate image transfer.
- Deploy with a similar YAML as above, using
imagePullPolicy: Never.
Podman Desktop
Podman Desktop simplifies the process by providing integrations for pushing images into Minikube.
- Podman desktop has features that allow you to push images directly into a minikube cluster, which can be very helpful.
Key Considerations for Both
imagePullPolicy: Never: Always use this in your deployment YAML for local images.- Storage Access: Ensure the container runtime (Docker or CRI-O) can access your images.
- Compatibility: Keep Minikube, Docker/Podman, and CRI-O versions up to date.
- Podman and CRI-O: When using these technologies, pay extra attention to the official documentation, regarding image storage locations.
Conclusion
Building and using local images in Minikube is a fundamental part of local Kubernetes development. While Docker offers a smoother integration, Podman provides a viable alternative with its daemonless architecture. Understanding the nuances of each approach will help you streamline your development workflow.