Skip to content

Commit

Permalink
Merge pull request #35 from boltops-tools/mix
Browse files Browse the repository at this point in the history
mix layering support, variables, custom helpers, plugin helpers
  • Loading branch information
tongueroo authored Nov 9, 2020
2 parents 5856a37 + c57c96e commit 7b56b01
Show file tree
Hide file tree
Showing 95 changed files with 1,400 additions and 412 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
All notable changes to this project will be documented in this file.
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.

## [UNRELEASED]
- mix layering support: evaluate DSL so layering can be mixed between YAML and DSL
- custom variables support
- custom helpers support
- plugins helpers support
- generators: new resource, new helper, new variable
- setup autoloader earlier. removes need for shims
- auth login for gcr also
- fix cli -h when not within Kubes project

## [0.5.1]
- fix deployment generator

Expand Down
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,62 @@ The deploy command, does all 3 steps: builds the docker image, compiles the `.ku

kubes deploy

## Multiple Enviroments

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](https://kubes.guru/docs/patterns/multiple-envs/)

## 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](https://kubes.guru/docs/config/docker/) and updates the compiled YAML files
* Syntactic Sugar: Use an [ERB/YAML](https://kubes.guru/docs/yaml/) or a [DSL](https://kubes.guru/docs/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](https://kubes.guru/docs/layering/).
* Generators: Kubes ships with a few generators to help you get building with Kubernetes quickly. See: [Generator Docs](https://kubes.guru/docs/generators/).
* CLI Customizations: You can customize the [cli args](https://kubes.guru/docs/config/args/kubectl/).
* Hooks: You can also run [hooks](https://kubes.guru/docs/config/hooks/) before and after [kubes](https://kubes.guru/docs/config/hooks/kubes/) and [kubectl](https://kubes.guru/docs/config/hooks/kubectl/) commands.
* Automated Suffix Hashes: Automatically appends a suffix hash to ConfigMap and Secret resources. More details in [ConfigMap](https://kubes.guru/docs/dsl/resources/config_map/) and [Secret](https://kubes.guru/docs/dsl/resources/secret/) docs.
* Kustomize Support: If you're a kustomization user, you can use it with Kubes. More details in [Kustomize Support Docs](https://kubes.guru/docs/misc/kustomize/).
* 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](https://kubes.guru/docs/misc/auto-context/).
* Ordering: Kubes run kubectl apply to create resources in the [correct order](https://kubes.guru/docs/intro/ordering/). For deleting, it kubes will run `kubectl delete` in the correct reverse order. The order is also [customizable](https://kubes.guru/docs/intro/ordering/custom/).

## Installation

Install with:

gem install kubes

## Comparison

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

* Blog Post: [Kustomize vs Helm vs Kubes: Kubernetes Deploy Tools](https://blog.boltops.com/2020/11/05/kustomize-vs-helm-vs-kubes-kubernetes-deploy-tools)
* [Kubes vs Custom Solution](https://kubes.guru/docs/vs/custom/)
* [Kubes vs Helm](https://kubes.guru/docs/vs/helm/)
* [Kubes vs Kustomize](https://kubes.guru/docs/vs/kustomize/)

For more info: [kubes.guru](https://kubes.guru)
21 changes: 19 additions & 2 deletions docs/_docs/dsl/resources/secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data(

Produces:

.kubes/output/shared/service.yaml
.kubes/output/shared/secret.yaml

```yaml
apiVersion: v1
Expand All @@ -38,6 +38,23 @@ data:
{% include dsl/rolling_deployment.md kind="Secret" %}
.kubes/resources/web/deployment.yaml:
```yaml
# ..
spec:
template:
spec:
containers:
- name: demo
image: nginx
envFrom:
- secretRef:
name: demo-secret
```
Produces:
.kubes/output/web/deployment.yaml:
```yaml
Expand All @@ -46,7 +63,7 @@ spec:
template:
spec:
containers:
- name: demo-shared
- name: demo
image: nginx
envFrom:
- secretRef:
Expand Down
8 changes: 4 additions & 4 deletions docs/_docs/generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ Kubes ships with a few generators to help you get building with Kubernetes quick

Here are a few examples:

$ kubes new ingress
$ kubes new resource ingress
create .kubes/resources/web/ingress.yaml
$ kubes new service_account
$ kubes new resource service_account
create .kubes/resources/shared/service_account.yaml
$

Use `-h` to see the cli options:

kubes new -h
kubes new resource -h

## Supported Resources

Expand All @@ -38,4 +38,4 @@ Here's a list of some of the supported resources.
service_account
service

Refer to the [source code](https://github.com/boltops-tools/kubes/blob/master/lib/templates/new/yaml) to all the resources that the generator supports.
Refer to the [source code](https://github.com/boltops-tools/kubes/blob/master/lib/templates/new/resource/yaml) to all the resources that the generator supports.
18 changes: 16 additions & 2 deletions docs/_docs/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Kubes provides some helper methods to help write Kubernetes YAML files. Here's

Helper | Description
--- | ---
decode64 | Basey64 decode a string.
decode64 | Base64 decode a string.
docker_image | Method refers to the latest Docker image built by Kubes. This spares you from having to update the image manually in the deployment resource. Note, this can be overridden with the `--image` cli option or the `Kubes.config.image` setting. See: [Docker Image]({% link _docs/intro/docker-image.md %})
dockerfile_port | Exposed port extracted from the Dockerfile of the project.
encode64 | Basey64 encode a string. Also available as `base64` method.
encode64 | Base64 encode a string. Also available as `base64` method.
extra | The `KUBES_EXTRA` value.
with_extra | Appends the `KUBES_EXTRA` value to a string if it's set. It's covered in the [Extra Env Docs]({% link _docs/extra-env.md %}).

Expand All @@ -25,3 +25,17 @@ There are also provider-specific helpers:

* [AWS Helpers]({% link _docs/helpers/aws.md %})
* [Google Helpers]({% link _docs/helpers/google.md %})

## Generator

To help you get started quickly, you can generate starter helper code.

$ kubes new helper custom
create .kubes/helpers/custom_helper.rb

.kubes/helpers/custom_helper.rb

```ruby
module CustomHelper
end
```
10 changes: 10 additions & 0 deletions docs/_docs/helpers/aws/advanced.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Advanced AWS Helpers
nav_text: Advanced
categories: helpers-aws
---

{% assign docs = site.docs | where: "categories","advanced-helpers-aws" %}
{% for doc in docs -%}
* [{{ doc.nav_text }}]({{ doc.url }})
{% endfor %}
131 changes: 131 additions & 0 deletions docs/_docs/helpers/aws/advanced/secrets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
---
title: AWS Secrets Advanced
nav_text: Secrets
categories: advanced-helpers-aws
---

This covers an advanced way so that Kubernetes Secrets are created from AWS Secrets Manager in a conventional way.

## Simple Values

For example if you have these secret values:

$ aws secretsmanager get-secret-value --secret-id demo/dev/db_user | jq '.SecretString'
user
$ aws secretsmanager get-secret-value --secret-id demo/dev/db_pass | jq '.SecretString'
pass

Set up a [Kubes hook](https://kubes.guru/docs/config/hooks/kubes/).

.kubes/config/hooks/kubes.rb

```ruby
secrets = KubesAws::Secrets.new(upcase: true, prefix: "demo/dev/")
before("compile",
label: "Get secrets from AWS Secrets Manager",
execute: secrets,
)
```

Then set the secrets in the YAML:

.kubes/resources/shared/secret.yaml

```yaml
apiVersion: v1
kind: Secret
metadata:
name: demo
labels:
app: demo
data:
<% KubesAws::Secrets.data.each do |k,v| -%>
<%= k %>: <%= base64(v) %>
<% end -%>
```

This results in AWS secrets with the prefix the `demo/dev/` being added to the Kubernetes secret data. The values are automatically base64 encoded. Produces:

.kubes/output/shared/secret.yaml

```yaml
metadata:
namespace: demo
name: demo-2a78a13682
labels:
app: demo
apiVersion: v1
kind: Secret
data:
db_pass: dGVzdDEK
db_user: dGVzdDIK
```
## JSON Values
For example if you have these secret values:
$ aws secretsmanager get-secret-value --secret-id demo/dev/k2 | jq '.SecretString'
{\"a\":1,\"b\":2}"
Set up a [Kubes hook](https://kubes.guru/docs/config/hooks/kubes/).
.kubes/config/hooks/kubes.rb
```ruby
secrets = KubesAws::Secrets.new(prefix: "rails/dev/")
before("compile",
label: "Get secrets from AWS Secrets Manager",
execute: secrets,
)
```

Then set the secrets in the YAML:

.kubes/resources/shared/secret.yaml

```yaml
apiVersion: v1
kind: Secret
metadata:
name: demo
labels:
app: demo
data:
<% k2 = JSON.load(KubesAws::Secrets.data["k2"]) %>
a: <%= base64(k2["a"]) %>
b: <%= base64(k2["b"]) %>
```
Produces:
```yaml
metadata:
namespace: demo-dev
name: demo-a4cd604a95
labels:
app: demo
apiVersion: v1
kind: Secret
data:
a: MQ==
b: Mg==
```
## Variables
These environment variables can be set:
Name | Description
---|---
AWS_SECRET_PREFIX | Prefixed used to list and filter AWS secrets. IE: `demo/dev/`.

Secrets#initialize options:

Variable | Description | Default
---|---|---
base64 | Automatically base64 encode the values. | false
upcase | Automatically upcase the Kubernetes secret data keys. | false
prefix | Prefixed used to list and filter AWS secrets. IE: `demo/dev/`. Can also be set with the `AWS_SECRET_PREFIX` env variable. The env variable takes the highest precedence. | nil

{% include helpers/base64.md %}
Loading

0 comments on commit 7b56b01

Please sign in to comment.