π 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:
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:
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