Kubes

Gem Version

BoltOps Badge

Kubernetes App Deploy Tool: build docker image, compile Kubernetes YAML files, and apply them.

Please watch/star this repo to help grow and support the project.

Official Docs Site: kubes.guru

Kubes will:

  1. Build the docker image and push it to repo
  2. Compile Kubernetes YAML files from YAML/ERB or a DSL with built Docker image
  3. Deploy via kubectl apply on the compiled Kubernetes YAML files

Usage

kubes init # creates .kubes structure
# edit the .kubes/resources files to your needs
kubes deploy

How It Works

Kubes is pretty straightforward. Kubes first builds the Docker image and compiles Kubernetes YAML files. Then it merely calls kubectl.

In fact, you can use Kubes to build the files first, and then run kubectl directly. Example:

kubes docker build
kubes docker push
kubes compile  # compiles the .kubes/resources files to .kubes/output

Now, use kubectl directly in the proper order:

kubectl apply -f .kubes/output/shared/namespace.yaml
kubectl apply -f .kubes/output/web/service.yaml
kubectl apply -f .kubes/output/web/deployment.yaml

You can also apply with kubes. This will automatically compile the files also.

kubes apply

The deploy command, does all 3 steps: builds the docker image, compiles the .kubes/resources files, and runs kubectl apply.

kubes deploy

Multiple Environments

You can easily create multiple environments with the same YAML configs. Example:

KUBES_ENV=dev  kubes deploy
KUBES_ENV=prod kubes deploy

See: Multiple Enviroments Pattern

Generators: Stop Writing Boilerplate

Your time is precious. Why are we copying and pasting boilerplate structure in this day and age?

Kubes provides generators to help you get going right away.

Resources examples:

$ kubes new resource secret
      create  .kubes/resources/shared/secret.yaml
$ kubes new resource service_account
      create  .kubes/resources/shared/service_account.yaml

Kubes components examples:

$ kubes new helper
      create  .kubes/helpers/custom_helper.rb
$ kubes new variable
      create  .kubes/variables/dev.rb
$

Features

  • Automation: Builds the Docker image and updates the compiled YAML files
  • Syntactic Sugar: Use an ERB/YAML or a DSL to write your Kubernetes YAML files. You can use a mix of DSL and YAML definitions in the .kubes/resources folder.
  • Layering: Use the same Kubernetes YAML to build multiple environments like dev and prod with layering.
  • Secrets: Use helpers like aws_secret, aws_ssm, and google_secret to build Kubernetes secrets.yaml from secret providers designed for it.
  • Generators: Kubes ships with a few generators to help you get building with Kubernetes quickly. See: Generator Docs.
  • CLI Customizations: You can customize the cli args.
  • Hooks: You can also run hooks before and after kubes and kubectl commands.
  • Automated Suffix Hashes: Automatically appends a suffix hash to ConfigMap and Secret resources. More details in ConfigMap and Secret docs.
  • Kustomize Support: If you're a kustomization user, you can use it with Kubes. More details in Kustomize Support Docs.
  • Auto Context Switching: Map dev to a specific kubectl context and prod to another kubectl context and Kubes can switch them automatically so you won't have to remember. More details in Auto Context Docs.
  • Ordering: Kubes run kubectl apply to create resources in the correct order. For deleting, it kubes will run kubectl delete in the correct reverse order. The order is also customizable.

Installation

Install with:

gem install kubes

Comparison

Here are some useful comparisons to help you compare Kubes vs other tools in the ecosystem:

For more info: kubes.guru