Setting up Kubernetes for local development using k3d and Docker | Day in my life

October 28, 2021

Setting up Kubernetes for local development using k3d and Docker

Kubernetes has become the defacto choice for running workloads for most microservices. Hence keeping parity with production, it’s wise to use Kubernetes for local development. This article uses k3d distributions of Kubernetes since it’s lightweight and runs on docker. If you are confident running Kubernetes, there are other options like minikube and Docker Desktop.

I initially wrote this article for version 3.x of k3d. The later version supports the local registry out of the box in k3d. If you are interested in setting up the registry outside of k3d, follow along, else skips to the k3d cluster setup.

Pre-requisites

Have following software installed

Setting up local docker registry

Setting up the k3d cluster

Test the cluster and setup

Test your setup to prove you can successfully push to the registry, and your k8s cluster can pull from it

# Pull a nginx latest image 
docker pull nginx:latest

# Tag the nginx image 
docker tag nginx:latest registry.localhost:5000/nginx:k8s

# Push the tagged image to your local docker registry
docker push registry.localhost:5000/nginx:k8s

# Run a container on your local k8s cluster pulled from local docker registry
kubectl run nginx --image=registry.localhost:5000/nginx:k8s

If you see the successful running of the pod on the k8s cluster with an image pulled from the local docker registry, you have a working setup!

© Nataraj Basappa 2021