top of page
Writer's pictureTravis Martin

Using Skaffold for Development in Kubernetes

Developing applications for Kubernetes can be challenging due to the complexity of the environment. Skaffold simplifies this process, providing a smooth development workflow that automates the build, push, and deploy steps. In this blog post, we will explore how to use Skaffold for developing Node.js services in a Kubernetes cluster. We will cover installation, setup, and configuration to speed up local development, including setting up an Ingress controller for routing.


Why Use Skaffold?

Skaffold is an open-source tool that facilitates continuous development for Kubernetes applications. It enables developers to focus on writing code by automating repetitive tasks such as building images, pushing them to registries, and deploying applications to Kubernetes clusters. Key benefits include:

  • Simplified Workflow: Automates the build, push, and deploy steps, reducing manual effort.

  • Rapid Iteration: Enables quick feedback loops by minimizing the time between code changes and application updates.

  • Consistency: Ensures that the development environment is consistent with the production environment.


Installation

Before we begin, ensure you have the following installed:

  1. kubectl: Kubernetes command-line tool.

  2. minikube: A local Kubernetes cluster. (Optional if you use docker desktop)

  3. Docker Desktop: Containerization platform / local Kubernetes cluster.

  4. Node.js: JavaScript runtime.


Installing Skaffold

You can install Skaffold using Homebrew, Chocolatey, or by downloading the binary directly. Here, we'll use Homebrew for macOS:








Setting Up the Ingress Controller

An ingress controller is necessary to route traffic to the correct service. We'll use the NGINX Ingress Controller for this example.


Install the NGINX Ingress Controller








Creating an Ingress Resource

To route traffic to your services, create an Ingress resource. This configuration directs traffic to different services based on the request path.

























Updating the Hosts File

To ensure proper routing, update your /etc/hosts file (or C:\Windows\System32\drivers\etc\hosts on Windows) with the following entry:

127.0.0.1 <your-service-domain>

Replace <your-service-domain> with the domain you will use to access your service.


Creating a Node.js Service

I created a github project that will contain all the services used in this blog, and others coming. The service complete is an authorization service that allows users to signin, signout, signup and return the current user. Repo: https://github.com/travism26/microservice-examples/


Dockerfile

Create a Dockerfile to containerize your Node.js application:










Kubernetes Manifests

Create Kubernetes manifests to define your application, including Deployment and Service resources. All the kubernetes manifests files are located at ./infra/k8s/* directory, this file represents the auth deployment.



































Generally I tend to keep both the service and the deployment in the same file just so its clear how we connect to the corresponding service instead of switching between files.


Skaffold Configuration

Configure Skaffold by creating a skaffold.yaml file. This file defines the build and deployment process.

















Running the Application with Skaffold

Run the following command to start the development environment with Skaffold:

skaffold dev

Skaffold will build the Docker image, push it to the local registry, and deploy the application to your Kubernetes cluster. It will also watch for changes in your code and automatically rebuild and redeploy the application.


Conclusion

Using Skaffold simplifies the development workflow for Kubernetes applications, allowing you to focus on writing code. By automating the build, push, and deploy steps, Skaffold ensures rapid iteration and consistent environments. Follow the steps outlined in this blog post to set up Skaffold for your Node.js services and experience a smoother development process.

16 views0 comments

Comments


bottom of page