Getting started with local development on Kubernetes with Skaffold
Containerization has been a revolution in software development. Technologies such as Docker allow developers package their software and all its dependencies in containers runnable in any computing environment, be it your local desktop, public cloud or your company's datacenter. This has drastically accelerated deploying software.
Warning
Update 2023: This post is old. I recommend using Tilt instead of Skaffold. Proceed with caution.
Containers are often deployed in container orchestration platforms such as Kubernetes. However, when locally developing services, I have used tools such as Docker Compose to run multiple related containers with a single command. This is great, but it feels a bit 2010s: My service has its own Kubernetes manifest describing how the service should be deployed, so why can't I use that for local development as well?
Enter Skaffold, a command-line tool for continuous development on Kubernetes. The tool was open-sourced by Google in 2018. Skaffold watches your code and, detecting changes, it handles building, pushing and deploying the application to your local Kubernetes installation. You can even use Skaffold to build your CI/CD pipeline, handling the deployment all the way from local workstation to the production cluster.
In this series of articles, we'll learn how to develop a Kubernetes-native web application. We'll use Django to build our web application, connect it to Postgres database, and write Kubernetes manifests to continuously develop the application on a local Minikube cluster. We'll learn Kubernetes concepts such as deployments, services, ConfigMaps, Secrets, Persistent Volumes, and Jobs.
In this first part of this series, we'll install all the requirements. After you've completed the first part, you can clone the accompanying repository and run
in the root of the repository to deploy the application to your local Minikube cluster. In the next part(s) of the series, we'll build the repository step-by-step.
Prerequisites
kubectl
First, we'll need kubectl
to interact with our Kubernetes cluster. The exact details will vary depending on your platform, so follow the instructions here to install kubectl
on your own machine.
On macOS, kubectl
can be installed as follows:
My commands:
$ cd ~/bin
$ curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl"
$ chmod +x kubectl
Here I download the kubectl
executable in the bin/
folder in my home directory. I have added this folder to my $PATH
with export PATH=$PATH:~/bin
in my ~/.bash_profile
, so I can execute the binary anywhere with the kubectl
command. You can put the binary anywhere in your $PATH
, say, in /usr/local/bin/kubectl
.
After installation, check that it works:
Minikube
Note that Docker Desktop includes a stand-alone Kubernetes server. If you wish to use that instead of Minikube, you can: see the instructions here how to use Docker Desktop with Skaffold.
The next step is to install Minikube. Again, the exact details vary on the platform. First, you may need to install a Hypervisor. I had hyperkit
installed on my machine already by Docker Desktop, which I confirmed by running
Alternatively, you can install VirtualBox.
After ensuring a Hypervisor is installed, you can install minikube
as stand-alone executable as follows:
$ cd ~/bin
$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64 \
$ chmod +x minikube
After this, you can bravely try and start your local Minikube cluster with:
Note that running this command for the first time requires downloading big disk images, so be patient. If everything goes well, the cluster starts and you can enter the following command to access the Kubernetes dashboard:
If anything goes wrong, you can try and explicitly specify the driver as instructed here.
Skaffold
Next, we'll need to install Skaffold. For macOS, I installed the stand-alone binary with:
$ cd ~/bin
$ curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-darwin-amd64
$ chmod +x skaffold
To verify your installation, run:
django-admin
If you want to follow along building the repository, you'll need django-admin
to bootstrap the Django application. Note that this step is optional: we only need to install Django to create the project boilerplate. If you don't want to install Python 3 and Django on your own machine, feel free to copy the code from the accompanying repository.
Installing Django requires, first of all, a working installation of Python 3, so make sure you have that available.
Our Django project will live in src/store
, so create that folde and cd
into it:
Create requirements.txt
and include django
:
Now activate your virtual environment and install Django:
Now, you should be able to find django-admin
in your PATH
. We'll use that to bootstrap the project in the next part.
Conclusion
This concludes the first part! If you followed through this far, you can try and run
in the accompanying repository to deploy the application to your local Kubernetes cluster. In the next part of the series, we'll build the application and get to the fun stuff: writing Kubernetes manifests. See you then!