EikenDram / kube-build

Build tool for kubernetes deployment in air-gapped environment
MIT License
0 stars 1 forks source link

About

This is a CLI tool for building a K3S kubernetes cluster deployment for a Fedora CoreOS server in an air-gapped environment

Introduction

Coming from developing .net web applications for windows server, switching recently to dotnet core allowed me to build applications for linux platform as well. Decided to try updating server architecture to cloud and implement some DevOps; after a bit of research ended up with K3S on Fedora CoreOS - as something that looked simple enough to start with.

This project was initially a set of notes about setting everything up on a virtual machine, but as the production environment i'm working with is air-gapped, setting everything up required quite a lot of additional work, which I then decided to automate by making this tool.

Cluster configuration

COMPONENT DIRECTORY CONTENT
SYSTEM
os os/coreos Fedora CoreOS
vmtools os/vmtools Optional vmware tools
port-forward os/port-forward Optional port-forwarding container
KUBERNETES
k3s kubernetes/k3s K3S kubernetes cluster
registry kubernetes/registry Private Docker registry
openebs kubernetes/openebs OpenEBS storage provider
chartmuseum kubernetes/chartmuseum Helm chart repository Chartmuseum
keycloak kubernetes/keycloak Access manager Keycloak
oauth2 kubernetes/oauth2 Reverse proxy OAuth2-proxy
dashboard kubernetes/dashboard Kubernetes dashboard
portainer kubernetes/portainer Kubernetes manager Portainer CE
registry-ui kubernetes/registry-ui Docker registry dashboard
traefik-ui kubernetes/traefik-ui Traefik dashboard
prometheus kubernetes/prometheus Monitoring service Prometheus and Grafana
loki kubernetes/loki Logging service Loki
minio kubernetes/minio Backup storage MinIO
velero kubernetes/velero Backup service Velero
nfs kubernetes/nfs [NFS server] (https://hub.docker.com/r/itsthenetwork/nfs-server-alpine)
CI/CD
gitea cicd/gitea Git and package repository Gitea
tekton cicd/tekton CI/CD pipeline Tekton
argocd cicd/argocd CD automation Argo CD
dev cicd/dev Loaders for npm/nuget/go packages into gitea
SERVICES
ibmdb2 services/ibmdb2 IBM DB2 community edition database server
db2console services/db2console DB2 data management console
rabbitmq services/rabbitmq Message query server Rabbit MQ
rocker services/rocker RStudio server
APPLICATIONS
kube-home apps/kube-home KubeHome home page for cluster
kube-r apps/kube-r KubeR service for processing reports as R scripts
kube-utils apps/kube-utils KubeUtils tools for managing cluster resources
kube-app-template apps/kube-app-tempalte KubeAppTemplate template application

Development status

KubeR, KubeUtils, KubeAppTemplate, Keycloak authorization, application development are work in progress

Project structure

Tutorial

Tutorial is available in docs directory

Compilation

Running from source code

Install go

Clone this git repository and run

go run github.com/EikenDram/kube-build/build

Building from source code

Run

GOOS=$os GOARCH=$arch go build github.com/EikenDram/kube-build/build

for building tool for specific platform

Customization

Configuration files

Build tool uses text/template module to process files as templates using following data:

Update images configuration

Build tool has command images that creates images.sh script in deployment directory from template _images.sh in config directory, runs it and updates images.yaml configuration with the list of used images from helm charts, .yaml files in manifest and install directories, and images from config/version.yaml (for some charts the image plugin wont retrieve all the images that will be used in deployment, you will have to update those versions manually)

Script uses:

Build process

Build program goes through all components as defined in components array in build.json, looks for files in .path + /template/ directory, and processes them as follow:

Files in .path + /copy/ directory are copied into deployment directly

Script templates

Templates _prepare.sh and _script.sh in config directory contain service scripts and following sub-templates:

Place a # at the end of -echo block to comment out the default message if necessary

Build configuration

Build configuration is loaded from build.json, with following structure:

{
  "pre": [],
  "build": [],
  "components": [],
  "post": []
}

components array contains a list of all build components with structure:

{
  "name": "",
  "path": "",
  "message": "",
  "comment" : ""
}

Where:

pre, build and post arrays contain a list of build commands with structure:

{
  "comment": "",
  "message": "",
  "type": "",
  "name": "",
  "location": "",
  "from": {
    "location": "",
    "name": ""
  },
  "to": {
    "location": "",
    "name": ""
  }
}

Where:

Snippets

Project contains Visual Studio Code snippets for _prepare.sh and _script.sh script templates in component's deploy directories, shortcuts are: shPrepare and shScript

VS Code launch.json

        {
            "name": "Launch Build",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceFolder}/src/",
            "cwd": "${workspaceFolder}",
            "args": [
                "--values=values.yaml"
            ]
        }