← Back to Blog

πŸš€ Setting Up a Container Registry in Minikube: A Step-by-Step Guide 🐳

πŸš€ Setting Up a Container Registry in Minikube: A Step-by-Step Guide 🐳 If you're working with Kubernetes and Minikube, setting up a local container registry is an efficient way to manage images directly within your cluster.

πŸš€ Setting Up a Container Registry in Minikube: A Step-by-Step Guide 🐳

If you're working with Kubernetes and Minikube, setting up a local container registry is an efficient way to manage images directly within your cluster. In this guide, I'll show you how to enable Minikube’s built-in registry, build and push images, and use them in your deployments. Let’s dive in!


πŸ”₯ Step 1: Start Minikube with the Registry Addon πŸ› οΈ

To enable the registry addon right from the start, use the following command:

Start Minikube with registry addon enabled

minikube start --addons=registry

πŸ‘‰ Already running Minikube? No problem! You can enable the registry on a running Minikube cluster:

minikube addons enable registry

This will create a container registry inside your Minikube cluster, ready to store images for your deployments!

πŸš€ Pause for a Screenshot: Here, take a screenshot of the terminal after enabling the addon.


πŸ› οΈ Step 2: Confirm the Registry is Running πŸ”„

Let’s check that the registry is running. Run the following command:

kubectl get pods -n kube-system | grep registry

If successful, you’ll see a registry pod running in the kube-system namespace.

πŸš€ Pause for a Screenshot: Grab a screenshot showing the registry pod status to confirm it’s up and running.


🌐 Step 3: Get the Registry URL πŸ“

To access the registry, get Minikube’s internal IP by running:

minikube ip

Combine this IP with port 5000 to create the registry URL like so:

:5000

For example, if the IP is 192.168.49.2, your registry URL will be 192.168.49.2:5000.

πŸš€ Pause for a Screenshot: Capture the IP output here.


🐳 Step 4: Build and Push an Image to the Minikube Registry πŸ”¨

Let’s build and push a Docker image to the registry.

  • Set Up Docker to Work with Minikube’s Environment: eval $(minikube docker-env)

  • Build the Docker Image: docker build -t <minikube_ip>:5000/my-image:latest .

  • Push the Image to the Registry: docker push <minikube_ip>:5000/my-image:latest

πŸš€ Pause for Screenshots: Show the Docker build and push commands in action, confirming they’re successful.


πŸ›‘οΈ Step 5: Use the Image in Your Kubernetes Deployment βš™οΈ

Now, reference the Minikube registry image in your Kubernetes deployment YAML. Here’s an example:

apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-container
image: :5000/my-image:latest
ports:
- containerPort: 80

Replace <minikube_ip> with your actual Minikube IP.


βœ… Step 6: Test the Deployment πŸŽ‰

Apply the deployment YAML to confirm the image is successfully pulled from the Minikube registry:

kubectl apply -f deployment.yaml

To verify the deployment status:

kubectl get pods

πŸš€ Pause for a Screenshot: Capture the output showing the successful deployment and running pods.


🌍 Optional: Port Forward to Access Registry from Host πŸ”—

To access the registry from your local machine, set up port forwarding:

kubectl port-forward --namespace kube-system svc/registry 5000:80

You can now interact with the registry via localhost:5000.


And there you have it! You’ve successfully set up a container registry inside Minikube and deployed an image from it. Enjoy containerizing with ease! πŸ₯³


πŸ”— Connect with me:


Imported from rifaterdemsahin.com Β· 2024