Minikube is a great tool! Almost everybody begins Kubernetes with it and continues to use it all the time. I figured out a way to use single-node GKE clusters just like Minikube:

Normally, app development workflow on minikube looks like this:

eval $(minikube docker-env)
docker build -t myapp .
kubectl run --image-pull-policy=IfNotPresent --image=myapp [...]

The first command sets environment variables so that docker CLI can directly talk to the Docker socket running inside the Minikube VM. This way, you don’t need to push Docker images to a registry to run them on Kubernetes.

What makes this work is that Minikube is a single-instance cluster. The image you built will be present when you do deploy using Kubernetes (i.e. the Pod won’t land on a node that doesn’t have the image).

Using GKE like Minikube

A single-instance Google Kubernetes Engine cluster can be made to work pretty much like Minikube, too!

gcloud container clusters create --num-nodes 1 test

Then expose the /var/run/docker.sock from the GKE node locally in your machine:

gcloud compute ssh \
    $(kubectl get nodes -o=custom-columns=:metadata.name) -- \
    -N -o StreamLocalBindUnlink=yes \
    -L $HOME/gke.sock:/var/run/docker.sock

This command will establish an Unix domain socket tunnel to the GKE instance’s docker socket. (It will not print anything and seem like stuck but it will succeed.) Keep this command running to maintain the connection.

Now you can run docker commands against the GKE node:

export DOCKER_HOST=unix:///$HOME/gke.sock
docker version

And get on your business just like before you did on Minikube:

docker build -t myapp .
kubectl run --image-pull-policy=IfNotPresent --image=myapp [...]

I hope it’s useful!

I’m looking at improving the developer workflows for Kubernetes and taking a stab at various bits and pieces. I’ll be publishing my work as much as I can, stay tuned.


P.S. I’m working on another tool that restarts containers when the image is rebuilt. If you give it a try, let me know how you like it.