Deploying a Node.js Application with Kustomize on Minikube

Introduction In this article, we will explore how to deploy a Node.js application using Kustomize on a Minikube cluster. We will cover the project structure, Dockerfile setup, Kubernetes manifests, and how to use Kustomize to manage different configurations for development, staging, and production environments. We will also discuss the advantages of using Kustomize over other alternatives. Prerequisites Before we begin, ensure you have the following installed on your machine: Docker Minikube kubectl Project Structure Here is the structure of our project: profile-app/ ├── config/ │ ├── config.json ├── k8s/ │ ├── base/ │ │ ├── deployment.yaml │ │ ├── service.yaml │ │ ├── pvc.yaml │ │ ├── namespace.yaml │ │ ├── kustomization.yaml │ ├── overlays/ │ │ ├── dev/ │ │ │ ├── config.json │ │ │ ├── kustomization.yaml │ │ ├── prod/ │ │ │ ├── config.json │ │ │ ├── kustomization.yaml │ │ ├── staging/ │ │ │ ├── config.json │ │ │ ├── kustomization.yaml ├── app.js ├── package.json ├── Dockerfile ├── docs/ │ ├── readme.md Application Code app.js const express = require("express"); const fs = require("fs"); const app = express(); const PORT = process.env.PORT || 3001; // Read the mounted config file const CONFIG_PATH = "./config/config.json"; let config = { name: "Noel Bansikah", role: "DevOps Engineer", nameColor: "black", roleColor: "gray", environment: "development" }; // Check if the config file exists if (fs.existsSync(CONFIG_PATH)) { config = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8")); } // Define a color map for meaningful colors const colorMap = { black: "#000000", gray: "#6c757d", blue: "#007BFF", yellow: "#FFC107", red: "#DC3545", green: "#28A745" }; // Get the colors from the config or default to black and gray const nameColor = colorMap[config.nameColor] || colorMap.black; const roleColor = colorMap[config.roleColor] || colorMap.gray; app.get("/", (req, res) => { res.send(` Hello, I am ${config.name}

Mar 12, 2025 - 01:09
 0
Deploying a Node.js Application with Kustomize on Minikube

Introduction

In this article, we will explore how to deploy a Node.js application using Kustomize on a Minikube cluster. We will cover the project structure, Dockerfile setup, Kubernetes manifests, and how to use Kustomize to manage different configurations for development, staging, and production environments. We will also discuss the advantages of using Kustomize over other alternatives.

Prerequisites

Before we begin, ensure you have the following installed on your machine:

Project Structure

Here is the structure of our project:

profile-app/
├── config/
│   ├── config.json
├── k8s/
│   ├── base/
│   │   ├── deployment.yaml
│   │   ├── service.yaml
│   │   ├── pvc.yaml
│   │   ├── namespace.yaml
│   │   ├── kustomization.yaml
│   ├── overlays/
│   │   ├── dev/
│   │   │   ├── config.json
│   │   │   ├── kustomization.yaml
│   │   ├── prod/
│   │   │   ├── config.json
│   │   │   ├── kustomization.yaml
│   │   ├── staging/
│   │   │   ├── config.json
│   │   │   ├── kustomization.yaml
├── app.js
├── package.json
├── Dockerfile
├── docs/
│   ├── readme.md

Application Code

app.js

const express = require("express");
const fs = require("fs");

const app = express();
const PORT = process.env.PORT || 3001;

// Read the mounted config file
const CONFIG_PATH = "./config/config.json";
let config = { name: "Noel Bansikah", role: "DevOps Engineer", nameColor: "black", roleColor: "gray", environment: "development" };

// Check if the config file exists
if (fs.existsSync(CONFIG_PATH)) {
  config = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8"));
}

// Define a color map for meaningful colors
const colorMap = {
  black: "#000000",
  gray: "#6c757d",
  blue: "#007BFF",
  yellow: "#FFC107",
  red: "#DC3545",
  green: "#28A745"
};

// Get the colors from the config or default to black and gray
const nameColor = colorMap[config.nameColor] || colorMap.black;
const roleColor = colorMap[config.roleColor] || colorMap.gray;

app.get("/", (req, res) => {
  res.send(`
    
      
        

${nameColor};">Hello, I am ${config.name}