Kubernetes Environment for Developers - Kind, Minikube and Skaffold

06.04.2021 | 7 min read

DevOps image of tools on a blue background

Companies have shifted to Kubernetes in production, but most developers are still using tools like 'Docker Compose' to run and test their applications. As the DevOps approach is becoming a new normal, developers need to consider Kubernetes development environment. It provides new processes for continuous deployment and integration, helps developers merge code, and automates deployment and scaling across containers.

What is Kubernetes?

Kubernetes is an extensible, portable, open-source platform that manages containerized workloads and services. It facilitates automation and declarative configuration. Kubernetes has a rapidly growing, large ecosystem with widely available tools, support, and services.

Kubernetes provides a framework to run distributed systems. It takes care of failover and scaling for applications and provides deployment patterns.

It provides users with:

  • Automated rollouts and rollbacks
  • Load balancing and service discovery
  • Configuration management
  • Storage orchestration
  • Automatic bin-packing

The first step to start with Kubernetes is to set up a Kubernetes environment on a local machine. It can be an ultimate local environment for developers, particularly to deal with a large number of microservices. Turning your local machine into a powerful Kubernetes development environment is extremely simple. The best way to deploy a local Kubernetes environment is using tools such as kind, minikube, and skaffold. In this article, we’ll discuss these tools to run a

Kubernetes cluster on a local machine.

Kind

Kind is also a Kubernetes SIG project which stands for 'Kubernetes in Docker'. It is a tool used to run Kubernetes clusters locally using Docker container "nodes".

It was designed to test Kubernetes itself but may be used for CI environment or local development. Apart from these, it uses 'kubeadm' to bootstrap Kubernetes inside the Docker.

It consists of

● Packages implementing image build, cluster creation, etc.

● A cmd interface and kubetest integration built on these packages.

● Docker images are written to run Kubernetes, systems, etc.

Minimum requirements for the host machine

For building Kubernetes on Windows or macOS, a minimum of 6GB RAM is required to run Docker Engine on a Virtual Machine. However, 8GB of RAM is recommended.

Installation

Kind can be installed through 'Go' or using package managers. Use the latest Go for kind installation, preferably Go 1.14 or greater.

For Windows, run command

choco install kind

For mac, run command

brew install kind

Remember that because there’s no dedicated cluster IP, everything is directly on localhost. However, the cluster needs to be configured explicitly to map ports.

apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
  - role: control-plane
    extraPortMappings:
      - containerPort: 30002  
        hostPort: 30002       
  - role: worker
Map container’s port 30002 to host’s port 30002

One needs to pass the configuration at creation time:

kind create cluster --config kind.yml

Note that the cluster configuration cannot be changed. The only workaround is to delete the cluster (see below) and create another one with the new configuration.

Interact with the cluster

Use kubectl to interact with the created cluster using a configuration file generated by kind. This file is stored in ${HOME}/.kube/config by default.

Deleting a cluster

Delete the cluster using the following command if you created it with ‘kind create cluster’.

Coming from minikube, there are a couple of differences worth mentioning. The most important one is that kind runs in Docker. Its name is actually an acronym for “ k*ubernetes *in *d*ocker”. Hence, Docker must be running prior to any kind-related operation.

As a consequence, there’s no dedicated cluster IP, everything is directly on localhost. However, the cluster needs to be configured explicitly to map ports.

apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
  - role: control-plane
    extraPortMappings:
      - containerPort: 30002  
        hostPort: 30002       
  - role: worker
Map container’s port 30002 to host’s port 30002

One needs to pass the configuration at creation time:

kind create cluster --config kind.yml

The cluster configuration cannot be changed. The only workaround is to delete the cluster and create another one with the new configuration.

Another important difference becomes visible when the image of the scheduled pod is local i.e. not available in a registry. With minikube, one would configure the environment so that when one builds an image, it’s directly loaded into the cluster’s Docker daemon. With kind, one needs to load images from Docker to the kind cluster.

kind load docker-image hazelcast/hzshop:1.0

Why kind?

  • It supports
  • multi-node clusters, including HA
  • Kubernetes release builds from source
  • In addition to pre-published builds, it has support for docker/bash/make or bazel.
  • Multiple operating systems, such as Windows, Linux, macOS.

Pros

  • It supports multi-node clusters.
  • It can run in several CI environments.
  • It is a docker native installation on Linux, and you can run it without a VM.
  • It is easy to install (as a container docker)
  • It enables easy versioning
  • It is relatively light
  • It is ideal for use in CI (as a container)

Cons

  • The local registry setup is new and changing rapidly.

Minikube

Minikube is a tool to run a single-node Kubernetes cluster on a local machine, including Windows, Linux, and macOS. It supports common Kubernetes features, including DNS, CNI, Dashboards, Config Maps, NodePorts, etc.

Minikube features

Minikube sets up a Kubernetes cluster on a local machine with the following features.

  • It supports the latest Kubernetes release
  • It can be deployed as a container, VM, or on bare-metal
  • It offers multiple container runtimes, such as CRI-O, docker, containerd
  • Addons are available for easily installed Kubernetes applications.
  • It offers advanced features such as filesystem mounts, LoadBalancer, and FeatureGates

All we need to install minikube is a Virtual Machine environment or Docker container, and the Kubernetes development environment is a single command away. minikube start

Requirements for a host machine

The host machine must have

  • 20GB disk space
  • 2GB free memory
  • 2 or more CPUs
  • Internet connection
  • Container or VM manager

Installation

For Windows, use this command to install minikube if the Windows Package Manager is installed.

For Linux, there are three easy download options.

  • Binary download
  • Debian package
  • RPM package

Follow theofficial documentation for a comprehensive guide.

For mac, it is easy to install minikube with a simple command.

brew install minikube

Start local cluster

To start with Kubernetes, enter a command 'minikube start' from a terminal with administrator access, but do not log in as root. It will create a single-node cluster inside a VM.

Verify the status after the cluster gets started using the command

minikube status

Interact with cluster

If kubectl is already installed on the system, access the cluster using the command

kubectl get po -A

Minikube dashboard

Kubernetes' web-based user interface helps to manage clusters and deploy applications. It can be used to monitor the state of cluster resources and modify them.

Following command allows adapting to a new environment.

minikube dashboard

Minikube dashboard can be used to:

  • deploy a containerized application to Kubernetes clusters
  • manage cluster resources
  • troubleshoot containerized applications
  • create and modify individual Kubernetes resources
  • examine applications running on a local cluster.

Pros and Cons of Minikube

Minikube for the local development environment is perfect for those who use multiple OS machines and have basic familiarity with Docker and Kubernetes.

Pros

  • Minikube is a mature solution
  • It works on Windows, Linux, and macOS.
  • It is easy to install and flexible on upgrades.
  • It comes with built-in add-ons and some of them are enabled by default, such as dashboard.
  • It’s great for if you’re starting out, and for local testing

Cons

  • It has a slow initial startup time.


Skaffold

It is a command-line tool that saves time by automating the development workflow from source to deployment. The Skaffold supports the application deployment and image-building strategies and makes it compatible with several pre-existing and new projects. It handles all the workflow for building, deploying, and pushing applications and provides components for creating CD/CI pipelines. Skaffold can operate on the client-side without any component requirement on the cluster.

Skaffold features

  • It detects changes in source code and handles the workflow of your application using policy-based image tagging.
  • It is an easy way to share projects with the world using ‘skaffold run’ and ‘git clone’.
  • It can work independently of a CI vendor, and you do not need Kubernetes or docker plugin.
  • It has no cluster-side component, so there is no maintenance or overhead burden to the cluster.
  • It is super lightweight and provides a minimal pipeline to keep things easy and simple.
  • It is perfect for microservice-based applications as it supports applications with multiple components.

Skaffold workflow and architecture

It simplifies the development workflow by organizing basic development stages into a simple command. Here is a shortlist of Skaffold's tasks.

  • Detect changes in the source code.
  • Synchronize files to the pod if they do not require building.
  • Build artifacts from the code.
  • Test the artifacts using a container-structure-test.
  • Tag, push and deploy artifacts.
  • Monitor deployed artifacts.

On exit, it cleans up deployed artifacts using Ctrl+C.

Installation

For macOS, run command

brew install skaffold

For Windows, run command

choco install -y skaffold

Build

If you’ve used Docker, the default behaviour here is to create a docker image with the use of the Dockerfile. Your main aim here is to get your code packaged into a container, ready for deploy.

Note this useful example from Dockerlabs. From the example’s Dockerfile we see that it is creating a Node container with the port 8080 exposed. No special instructions are added for Skaffold, it is just a simple Dockerfile.

FROM node:12.16.0-alpine3.10
WORKDIR /app
EXPOSE 8080
CMD [“npm”, “run”, “dev”]
COPY package* ./
# examples don’t use package-lock.json to minimize updates
RUN npm install — no-package-lock
COPY . .

No need to rebuild images: One of the major benefits of Skaffold is that it can update files used by the container without having to rebuild your images every time your file changes. Additionally, if you make a change that doesn’t directly affect the container, Skaffold will pick up on this and rebuild it as necessary. These newly created images will then be handed off at the deploy stage.

Deployment

The great thing about skaffold is that it enables developers to focus on writing code and managing kubernetes. At the deploy stage, Skaffold acts like an Ops engineer, creating deployments and services in the development cluster.

Still working with the above example from Dockerlabs., the deployment and service configurations for the sample application are defined in the manifest files located in k8s folder. We are able to see the react-reload image created in the build stage and service exposing port 8080. Skaffold also supports Helm and Kustomize manifest files.

apiVersion: v1
kind: Service
metadata:
name: node
spec:
ports:
- port: 8080
type: LoadBalancer
selector:
app: node
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: node
spec:
selector:
matchLabels:
app: node
template:
metadata:
labels:
app: node
spec:
containers:
- name: react
image: react-reload
ports:
- containerPort: 8080

Skaffold now knows how to apply this configuration. With the sample application up and running, it will switch into watcher mode. If you’re a developer you can go from writing code to testing code deployed to kubernetes without having to worry about any of the ops elements.

Pros

  • It enables quick integration with the target environment
  • It is a typical development tool
  • It is focused on capturing changes and quickly updating them on the target environment
  • It provides flexible workflows for testers and deployers.
  • It offers built-in integrations with builders/deployers.
  • Docker images can be pushed or tagged with customizable tagging.

Cons

  • Complex setup.

Final Words

In short, the three tools outlined in this blog post each cover different use cases. If you’re just starting out with Kubernetes and you’re looking to learn quickly, minikube is the right choice for you. If you’re looking for CI/CD uses, then kind is the way to go. Skaffold on the other hand is perfect for developers.

You may also like these posts

Start a project with 10Clouds

Hire us