SJCNet

SJCNet is the home of architect/developer/techie, Simon Coope.

Setting up a Dev Environment for Kubernetes and Docker

Overview

Recently I've been doing more work with Kubernetes and as such I've had to set-up my environment a few times to run Kubernetes, but also maintain some other work I've been doing separately in Docker. Not wanting to run both MiniKube/VirtualBox and the full Docker Desktop installation (including the Docker Host) I've been investigating ways to combine the set-up.

First, let's be clear what we're talking about here. Both Docker and Kubernetes are about containers right? Well, they are both container-based but do different things with containers. At a really high level it's as follows:

  • Docker - enables us to create and deploy software in containers.
  • Kubernetes - is an open-source container orchestration platform which enables us to create, deploy and manage a large number of containers.

Yes, Docker provides Docker Swarm which can handle container orchestration. But I'm talking about my personal set-up (and the set-up we use at work) which is to create containers using docker and orchestrate them using Kubernetes.

Moving onto Kubernetes and my local set-up, as mentioned I'm running Minikube. The interesting point for this set-up is that Minikube includes a built-in Docker daemon, which means we should be able to get away without the full installation of Docker Desktop, doesn't it? Let's run through the set-up and see!

Dev Environment

Set-up VirtualBox and Minikube

I won't explain how to set-up VirtualBox and Minikube up as that's covered really well in the Kubernetes docs here. I should also point out that I'm on a Mac and using Homebrew to install everything.

Set-up Docker

First we need to check that you don't have docker already installed, run the docker command in the terminal. It should return with something like command not found if it's not installed.

To set-up docker I run the following homebrew command at the terminal

brew install docker

This command installs the docker CLI, now if I run the docker command again it should return the terminal help for the command to show that it's installed.

Now to see that we're connected to a docker daemon (which at this point we shouldn't be) run a general docker command, such as docker image list. It should return with an error such as Cannot connect to Docker daemon at unix:.... This means we need to configure Docker to connect to the daemon running in Kubernetes in Minikube. To do that run the following command:

minikube docker-env

This should output the environment variables for the docker daemon within minikube. Next we run the following command which set's our local environment variables with the docker settings from Minikube:

eval $(minikube docker-env)

This just evaluates the minikube docker-env output, which sets the evironment variables locally.

Now if you run the general docker command again (e.g. docker image list), you should see the images in your instance of Minikube.

Testing Docker

To test docker, run the hello-world Docker image, by running the following command:

docker run hello-world

This command should output show the output Hello from Docker! and you're done.

I've played with this set-up a little bit and haven't had any problems as yet! Will post back here if I do.

Author image
About Simon Coope
Sydney, Australia Website
Experienced developer/consultant. Loves all things development, technology, gadgets, football and running.