Skip to main content

One post tagged with "kind"

View All Tags

Test local with k3d

· 7 min read
Guster
Principal Engineer

image

Introduction​

Every Kubernetes manifest I write eventually ends up on EKS. For a long time I tested those manifests by applying them straight to a shared dev cluster. It worked, but the feedback loop was painful. A wrong selector meant waiting for a rollout, a bad probe meant reading events on a remote node, and every experiment left a small mess behind.

So I started looking for a local cluster that was fast enough to create per task and close enough to EKS to trust. I tried kind, then minikube, and finally k3d. k3d is the one I kept.

This is not a feature-by-feature review of every local Kubernetes tool. It is the setup I use, the parts that matter to me, and why k3d became my default.

The short version​

k3dkindminikube
Runtimek3s in DockerKubernetes in DockerVM or container
Start timeSecondsSecondsA minute or more
Multi-node--agents NConfig file--nodes N
Local registryBuilt inManualAddon or manual
IngressTraefik includedInstall manuallyAddon
Best forApp dev and CIUpstream Kubernetes testingLearning and addons

What I wanted from a local cluster​

  • Fast enough to create and delete per task.
  • More than one node, so scheduling, affinity, and rolling updates mean something.
  • A registry that does not require pushing to a cloud account.
  • Ingress on localhost, so I can test real URLs.
  • A small enough footprint to run in CI.
  • Close enough to EKS that a manifest which works locally has a good chance of working there.

Why k3d​

k3d runs k3s inside Docker. k3s is a CNCF conformant Kubernetes distribution, so the API and the core objects behave the way I expect. The difference is packaging: one lightweight binary, a small control plane, and a load balancer container in front.

Creating a cluster with two agents is one command:

k3d cluster create dev \
--agents 2 \
--port "8080:80@loadbalancer" \
--port "8443:443@loadbalancer"

The cluster is ready in seconds. The port flags map localhost to the load balancer, so an Ingress on port 80 is reachable at http://localhost:8080.

Getting my image into the cluster​

This is the part that usually annoys me with local clusters. k3d has image import:

docker build -t my-api:dev .
k3d image import my-api:dev -c dev

The Deployment can then use my-api:dev with imagePullPolicy: IfNotPresent. No registry, no push, no credentials.

If I want a real registry, k3d can create one:

k3d registry create registry.localhost --port 5000
k3d cluster create dev --registry-use k3d-registry.localhost:5000

I use the registry when I am testing Helm charts or CI pipelines that expect to pull by tag. For day to day, image import is faster.

A config file I can commit​

Typing flags gets old, so I keep a k3d-config.yaml in the repo:

apiVersion: k3d.io/v1alpha5
kind: Simple
metadata:
name: dev
servers: 1
agents: 2
ports:
- port: 8080:80
nodeFilters:
- loadbalancer
- port: 8443:443
nodeFilters:
- loadbalancer
k3d cluster create --config k3d-config.yaml

Now the cluster shape is versioned with the app, and a new teammate gets the same setup with one command.

Testing the manifests​

My loop is boring, which is the point:

kubectl apply -f k8s/
kubectl rollout status deployment/my-api
curl http://localhost:8080/health

If a probe is wrong, I see it in seconds. If a selector does not match, kubectl describe is local and instant. If I break the cluster, I delete it and start again:

k3d cluster delete dev

That last command is the reason I stopped using a shared dev cluster for manifest work. I can be careless locally in a way I never could on a cluster someone else also uses.

What k3d is not​

k3d is not EKS. There are no IAM roles for service accounts, no ALB ingress controller, no EBS CSI driver, no VPC CNI, and no managed node groups. The defaults are different too: Traefik instead of ALB, ServiceLB instead of a cloud load balancer, and local-path storage instead of EBS.

If I am testing IAM, load balancer annotations, or storage classes, I still need a small EKS dev cluster. I use k3d for the parts that are application behaviour: deployments, services, config maps, secrets, probes, jobs, ingress rules, and rolling updates.

k3d also needs a Docker daemon. Podman support exists, but I stick to Docker because that is what my CI runners already have.

k3d vs kind vs minikube​

kind is excellent. It runs upstream Kubernetes in Docker and it is the tool I reach for when I want to test something close to the source, like a new Kubernetes version or an admission controller. The trade-off is setup: no ingress controller, no registry, and multi-node clusters need a config file. I can build all of that, but I would rather not rebuild it for every project.

minikube is the most feature-complete of the three. It has addons for ingress, dashboards, metrics, and more, and it is a great way to learn Kubernetes. It is also the heaviest. A VM or container driver, more memory, and a slower start make it a worse fit when I want a cluster for a twenty-minute task. Multi-node works, but it is not the default experience.

k3d sits in the middle and wins on workflow. Multi-node is a flag. Ingress is already there. A registry is one command. Image import is one command. The cluster starts in seconds and deletes cleanly. For application development and CI, that combination is hard to beat.

How I use it day to day​

  • One cluster per project, named after the project.
  • k3d cluster stop at the end of the day, k3d cluster start in the morning, and k3d cluster delete when the branch is merged.
  • A k8s/ directory with Kustomize overlays: local for k3d, prod for EKS. The local overlay only changes the image and points the Ingress host at localhost.
  • Integration tests in CI: create the cluster, import the image, apply the manifests, run the tests, delete the cluster.
  • Pin the k3s image in the config so a new release does not change behaviour mid-sprint.
image: rancher/k3s:<version>-k3s1

What I don't like​

  • Docker dependency. When Docker Desktop is unhappy, k3d is unhappy.
  • Defaults differ from EKS, so some manifests need a local overlay. Traefik versus ALB is the usual one.
  • Image import is manual. Forget it, and you get ImagePullBackOff for a tag that exists locally. I have done this more than once.
  • Networking through the load balancer container can be confusing when a service is not reachable. k3d node list and docker logs are part of the debugging story.
  • Version skew. k3s is not EKS, and a feature that works on one may not exist on the other.
  • Resource use. Two agents plus a server is still three containers plus the load balancer. On a small laptop, one agent is enough.

Which one should you use​

  • k3d if you want a fast, disposable cluster for app development and CI, with multi-node and ingress without extra setup.
  • kind if you are testing Kubernetes itself, need upstream parity, or already have a kind-based workflow.
  • minikube if you are learning Kubernetes and want addons and a dashboard in one command.
  • A real EKS dev cluster for IAM, load balancers, storage classes, and anything else that depends on AWS.

Closing thoughts​

k3d is my preferred local cluster because it removes the friction I actually care about: creating a cluster, getting my image in, reaching it on localhost, and deleting it when I am done. It is not a replacement for EKS, and I do not pretend it is. It is the place where I catch the boring mistakes before they cost me a rollout on the real cluster.