kubes 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +52 -0
- data/docs/_docs/dsl/resources/secret.md +19 -2
- data/docs/_docs/generators.md +4 -4
- data/docs/_docs/helpers/aws/advanced/secrets.md +131 -0
- data/docs/_docs/helpers/aws/advanced/ssm.md +78 -0
- data/docs/_docs/helpers/aws/advanced.md +10 -0
- data/docs/_docs/helpers/aws/secrets.md +18 -88
- data/docs/_docs/helpers/aws/ssm.md +20 -38
- data/docs/_docs/helpers/google/advanced/secrets.md +78 -0
- data/docs/_docs/helpers/google/advanced.md +10 -0
- data/docs/_docs/helpers/google/secrets.md +18 -27
- data/docs/_docs/helpers.md +16 -2
- data/docs/_docs/intro.md +2 -11
- data/docs/_docs/layering/mix.md +99 -0
- data/docs/_docs/layering.md +2 -0
- data/docs/_docs/patterns/multiple-envs.md +55 -0
- data/docs/_docs/variables/advanced.md +62 -0
- data/docs/_docs/variables/basic.md +137 -0
- data/docs/_docs/variables.md +23 -0
- data/docs/_docs/vs/custom.md +109 -0
- data/docs/_docs/vs/helm.md +243 -0
- data/docs/_docs/vs/kustomize.md +167 -0
- data/docs/_docs/vs.md +10 -0
- data/docs/_includes/intro/features.md +10 -0
- data/docs/_includes/layering/layers.md +2 -4
- data/docs/_includes/sidebar.html +39 -0
- data/docs/_includes/vs/article.md +1 -0
- data/docs/_includes/vs/kubes/layering.md +10 -0
- data/docs/_includes/vs/kubes/structure.md +24 -0
- data/docs/_reference/kubes-new-help.md +15 -0
- data/docs/_reference/kubes-new-helper.md +25 -0
- data/docs/_reference/kubes-new-resource.md +56 -0
- data/docs/_reference/kubes-new-variable.md +20 -0
- data/docs/_reference/kubes-new.md +6 -38
- data/kubes.gemspec +2 -2
- data/lib/kubes/auth/base.rb +21 -0
- data/lib/kubes/auth/ecr.rb +1 -15
- data/lib/kubes/auth/gcr.rb +24 -0
- data/lib/kubes/auth.rb +4 -1
- data/lib/kubes/cli/help/new/helper.md +4 -0
- data/lib/kubes/cli/help/{new.md → new/resource.md} +3 -3
- data/lib/kubes/cli/new/helper.rb +24 -0
- data/lib/kubes/cli/new/resource.rb +97 -0
- data/lib/kubes/cli/new/variable.rb +16 -0
- data/lib/kubes/cli/new.rb +12 -94
- data/lib/kubes/command.rb +1 -1
- data/lib/kubes/compiler/decorator/base.rb +1 -1
- data/lib/kubes/compiler/dsl/core/base.rb +6 -9
- data/lib/kubes/compiler/layering.rb +21 -7
- data/lib/kubes/compiler/shared/custom_variables.rb +38 -0
- data/lib/kubes/compiler/shared/plugin_helpers.rb +14 -0
- data/lib/kubes/compiler/strategy/base.rb +59 -2
- data/lib/kubes/compiler/strategy/dsl.rb +0 -29
- data/lib/kubes/compiler/strategy/erb.rb +10 -22
- data/lib/kubes/compiler/strategy.rb +7 -6
- data/lib/kubes/compiler/util/normalize.rb +6 -3
- data/lib/kubes/compiler/util/yaml_dump.rb +4 -4
- data/lib/kubes/plugin.rb +14 -0
- data/lib/kubes/util/sh.rb +1 -1
- data/lib/kubes/version.rb +1 -1
- data/lib/kubes.rb +4 -3
- data/lib/templates/new/helper/file.rb +2 -0
- data/lib/templates/new/{dsl → resource/dsl}/backend_config.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/config_map.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/daemon_set.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/deployment.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/ingress.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/job.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/managed_certificate.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/namespace.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/network_policy.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/pod.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/role.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/role_binding.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/secret.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/service.rb +0 -0
- data/lib/templates/new/{dsl → resource/dsl}/service_account.rb +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/backend_config.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/config_map.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/daemon_set.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/deployment.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/ingress.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/job.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/managed_certificate.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/namespace.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/network_policy.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/pod.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/role.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/role_binding.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/secret.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/service.yaml +0 -0
- data/lib/templates/new/{yaml → resource/yaml}/service_account.yaml +0 -0
- data/lib/templates/new/variable/file.rb +1 -0
- data/spec/fixtures/multiple-files/{deployment-1.rb → .kubes/resources/web/deployment-1.rb} +0 -0
- data/spec/fixtures/multiple-files/{deployment-2.rb → .kubes/resources/web/deployment-2.rb} +0 -0
- data/spec/fixtures/project/.kubes/resources/{deployment.rb → web/deployment.rb} +0 -0
- data/spec/fixtures/project/.kubes/resources/{foobar.rb → web/empty.rb} +0 -0
- data/spec/fixtures/project/.kubes/resources/{service.rb → web/service.rb} +1 -1
- data/spec/fixtures/syntax/{network_policy.rb → .kubes/resources/web/network_policy.rb} +0 -0
- data/spec/fixtures/syntax/{pod.rb → .kubes/resources/web/pod.rb} +0 -0
- data/spec/kubes/compiler/strategy/dsl_spec.rb +2 -2
- data/spec/kubes/compiler_spec.rb +1 -1
- data/spec/kubes/dsl/network_policy_spec.rb +1 -1
- data/spec/kubes/dsl/pod_spec.rb +1 -1
- metadata +81 -48
@@ -4,17 +4,9 @@ nav_text: Secrets
|
|
4
4
|
categories: helpers-google
|
5
5
|
---
|
6
6
|
|
7
|
-
|
7
|
+
The `google_secret` helper fetches secret data from Google Secrets.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
before("compile",
|
13
|
-
execute: KubesGoogle::Secrets.new(upcase: true, prefix: 'projects/686010496118/secrets/demo-dev-')
|
14
|
-
)
|
15
|
-
```
|
16
|
-
|
17
|
-
Then set the secrets in the YAML:
|
9
|
+
## Example
|
18
10
|
|
19
11
|
.kubes/resources/shared/secret.yaml
|
20
12
|
|
@@ -26,18 +18,17 @@ metadata:
|
|
26
18
|
labels:
|
27
19
|
app: demo
|
28
20
|
data:
|
29
|
-
|
30
|
-
|
31
|
-
<% end -%>
|
21
|
+
PASS: <%= google_secret("demo-#{Kubes.env}-PASS") %>
|
22
|
+
USER: <%= google_secret("demo-#{Kubes.env}-USER") %>
|
32
23
|
```
|
33
24
|
|
34
|
-
|
25
|
+
The values are automatically base64 encoded.
|
35
26
|
|
36
27
|
For example if you have these secret values:
|
37
28
|
|
38
|
-
$ gcloud secrets versions access latest --secret demo-dev-
|
29
|
+
$ gcloud secrets versions access latest --secret demo-dev-USER
|
39
30
|
test1
|
40
|
-
$ gcloud secrets versions access latest --secret demo-dev-
|
31
|
+
$ gcloud secrets versions access latest --secret demo-dev-PASS
|
41
32
|
test2
|
42
33
|
$
|
43
34
|
|
@@ -52,8 +43,8 @@ metadata:
|
|
52
43
|
apiVersion: v1
|
53
44
|
kind: Secret
|
54
45
|
data:
|
55
|
-
|
56
|
-
|
46
|
+
PASS: dGVzdDEK
|
47
|
+
USER: dGVzdDIK
|
57
48
|
```
|
58
49
|
|
59
50
|
## Variables
|
@@ -62,15 +53,15 @@ These environment variables can be set:
|
|
62
53
|
|
63
54
|
Name | Description
|
64
55
|
---|---
|
65
|
-
|
66
|
-
GOOGLE_PROJECT | Google project id.
|
56
|
+
GOOGLE_PROJECT | Google project id. This is required.
|
67
57
|
|
68
|
-
|
58
|
+
## Base64 Option
|
69
59
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
60
|
+
The value is automatically base64 encoded. You can set the `base64` option to turn on and off the automated base64 encoding.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
google_secret("demo-#{Kubes.env}-USER", base64: true) # default is base64=true
|
64
|
+
google_secret("demo-#{Kubes.env}-PASS", base64: false)
|
65
|
+
```
|
75
66
|
|
76
|
-
{% include helpers/base64.md %}
|
67
|
+
{% include helpers/base64.md %}
|
data/docs/_docs/helpers.md
CHANGED
@@ -6,10 +6,10 @@ Kubes provides some helper methods to help write Kubernetes YAML files. Here's
|
|
6
6
|
|
7
7
|
Helper | Description
|
8
8
|
--- | ---
|
9
|
-
decode64 |
|
9
|
+
decode64 | Base64 decode a string.
|
10
10
|
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 %})
|
11
11
|
dockerfile_port | Exposed port extracted from the Dockerfile of the project.
|
12
|
-
encode64 |
|
12
|
+
encode64 | Base64 encode a string. Also available as `base64` method.
|
13
13
|
extra | The `KUBES_EXTRA` value.
|
14
14
|
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 %}).
|
15
15
|
|
@@ -25,3 +25,17 @@ There are also provider-specific helpers:
|
|
25
25
|
|
26
26
|
* [AWS Helpers]({% link _docs/helpers/aws.md %})
|
27
27
|
* [Google Helpers]({% link _docs/helpers/google.md %})
|
28
|
+
|
29
|
+
## Generator
|
30
|
+
|
31
|
+
To help you get started quickly, you can generate starter helper code.
|
32
|
+
|
33
|
+
$ kubes new helper custom
|
34
|
+
create .kubes/helpers/custom_helper.rb
|
35
|
+
|
36
|
+
.kubes/helpers/custom_helper.rb
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
module CustomHelper
|
40
|
+
end
|
41
|
+
```
|
data/docs/_docs/intro.md
CHANGED
@@ -6,15 +6,6 @@ title: What is Kubes?
|
|
6
6
|
|
7
7
|
<div class="video-box"><div class="video-container"><iframe src="https://www.youtube.com/embed/M4zHL0mfKNU" frameborder="0" allowfullscreen=""></iframe></div></div>
|
8
8
|
|
9
|
-
## Features
|
9
|
+
## Features
|
10
10
|
|
11
|
-
|
12
|
-
* Syntactic Sugar: Use an [ERB/YAML]({% link _docs/yaml.md %}) or a [DSL]({% link _docs/dsl.md %}) to write your Kubernetes YAML files. You can use a mix of DSL and YAML definitions in the `.kubes/resources` folder.
|
13
|
-
* Layering: Use the same Kubernetes YAML to build multiple environments like dev and prod with [layering]({% link _docs/layering.md %}).
|
14
|
-
* Generators: Kubes ships with a few generators to help you get building with Kubernetes quickly. See: [Generator Docs]({% link _docs/generators.md %}).
|
15
|
-
* CLI Customizations: You can customize the [cli args]({% link _docs/config/args/kubectl.md %}).
|
16
|
-
* Hooks: You can also run [hooks]({% link _docs/config/hooks.md %}) before and after [kubes]({% link _docs/config/hooks/kubes.md %}) and [kubectl]({% link _docs/config/hooks/kubectl.md %}) commands.
|
17
|
-
* Automated Suffix Hashes: Automatically appends a suffix hash to ConfigMap and Secret resources. More details in [ConfigMap]({% link _docs/dsl/resources/config_map.md %}) and [Secret]({% link _docs/dsl/resources/secret.md %}) docs.
|
18
|
-
* Kustomize Support: If you’re a kustomization user, you can use it with Kubes. More details in [Kustomize Support Docs]({% link _docs/misc/kustomize.md %}).
|
19
|
-
* 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]({% link _docs/misc/auto-context.md %}).
|
20
|
-
* Ordering: Kubes run kubectl apply to create resources in the [correct order]({% link _docs/intro/ordering.md %}). For deleting, it kubes will run `kubectl delete` in the correct reverse order. The order is also [customizable]({% link _docs/intro/ordering/custom.md %}).
|
11
|
+
{% include intro/features.md %}
|
@@ -0,0 +1,99 @@
|
|
1
|
+
---
|
2
|
+
title: Mixed Layering
|
3
|
+
---
|
4
|
+
|
5
|
+
You can mix and match the YAML and DSL forms together and layering still works.
|
6
|
+
|
7
|
+
## Project Structure
|
8
|
+
|
9
|
+
Here's an example structure, so we can understand how layering works.
|
10
|
+
|
11
|
+
.kubes/resources/
|
12
|
+
├── base
|
13
|
+
│ ├── all.yaml
|
14
|
+
│ └── deployment.yaml
|
15
|
+
└── web
|
16
|
+
├── deployment
|
17
|
+
│ ├── dev.yaml
|
18
|
+
│ └── prod.yaml
|
19
|
+
├── deployment.rb
|
20
|
+
└── service.yaml
|
21
|
+
|
22
|
+
Notice, how deployment.rb is defined as a DSL. The layers will still be merged like so:
|
23
|
+
|
24
|
+
.kubes/resources/base/all.yaml
|
25
|
+
.kubes/resources/base/deployment.yaml
|
26
|
+
.kubes/resources/web/deployment.rb
|
27
|
+
.kubes/resources/web/deployment/dev.rb
|
28
|
+
|
29
|
+
## Resources Files
|
30
|
+
|
31
|
+
.kubes/resources/base/all.yaml
|
32
|
+
|
33
|
+
```yaml
|
34
|
+
metadata:
|
35
|
+
namespace: demo-<%= Kubes.env %>
|
36
|
+
labels:
|
37
|
+
app: demo
|
38
|
+
```
|
39
|
+
|
40
|
+
.kubes/resources/base/deployment.yaml
|
41
|
+
|
42
|
+
```yaml
|
43
|
+
metadata:
|
44
|
+
labels:
|
45
|
+
app: demo
|
46
|
+
spec:
|
47
|
+
selector:
|
48
|
+
matchLabels:
|
49
|
+
app: demo
|
50
|
+
template:
|
51
|
+
metadata:
|
52
|
+
labels:
|
53
|
+
app: demo
|
54
|
+
```
|
55
|
+
|
56
|
+
.kubes/resources/web/deployment.rb
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
name "web"
|
60
|
+
labels(role: "web")
|
61
|
+
image "nginx"
|
62
|
+
```
|
63
|
+
|
64
|
+
.kubes/resources/web/deployment/dev.yaml
|
65
|
+
|
66
|
+
```yaml
|
67
|
+
spec:
|
68
|
+
replicas: 2
|
69
|
+
```
|
70
|
+
|
71
|
+
## Output
|
72
|
+
|
73
|
+
The result is the merge layered files.
|
74
|
+
|
75
|
+
```yaml
|
76
|
+
metadata:
|
77
|
+
namespace: demo-dev
|
78
|
+
labels:
|
79
|
+
app: demo
|
80
|
+
role: web
|
81
|
+
name: web
|
82
|
+
spec:
|
83
|
+
selector:
|
84
|
+
matchLabels:
|
85
|
+
app: demo
|
86
|
+
role: web
|
87
|
+
template:
|
88
|
+
metadata:
|
89
|
+
labels:
|
90
|
+
app: demo
|
91
|
+
role: web
|
92
|
+
spec:
|
93
|
+
containers:
|
94
|
+
- image: nginx
|
95
|
+
name: web
|
96
|
+
replicas: 2
|
97
|
+
apiVersion: apps/v1
|
98
|
+
kind: Deployment
|
99
|
+
```
|
data/docs/_docs/layering.md
CHANGED
@@ -6,3 +6,5 @@ Kubes supports layering files together so you can use the same Kubernetes files
|
|
6
6
|
|
7
7
|
* [YAML Layering]({% link _docs/layering/yaml.md %})
|
8
8
|
* [DSL Layering]({% link _docs/layering/dsl.md %})
|
9
|
+
* [Mix Layering]({% link _docs/layering/mix.md %})
|
10
|
+
* [Merge Behavior]({% link _docs/layering/merge.md %})
|
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
title: Multiple Enviroments with Layering
|
3
|
+
nav_text: Multiple Enviroments
|
4
|
+
categories: patterns
|
5
|
+
---
|
6
|
+
|
7
|
+
You can use Kubes to easily create multiple enviroments with the same YAML configs. This is thanks to [Kubes Layering]({% link _docs/layering.md %}). We'll walk through an example to help understand how it works.
|
8
|
+
|
9
|
+
## Creating Multiple Enviroments
|
10
|
+
|
11
|
+
To create multiple enviroments like dev and prod just change KUBES_ENV. Example:
|
12
|
+
|
13
|
+
KUBES_ENV=dev kubes deploy
|
14
|
+
KUBES_ENV=prod kubes deploy
|
15
|
+
|
16
|
+
Different env files will be layered and merged to produce YAML files specific to each environment.
|
17
|
+
|
18
|
+
## Project Structure
|
19
|
+
|
20
|
+
Here's an example structure, so we can understand how layering works to create multiple enviroments.
|
21
|
+
|
22
|
+
.kubes/resources/
|
23
|
+
├── base
|
24
|
+
│ ├── all.yaml
|
25
|
+
│ └── deployment.yaml
|
26
|
+
└── web
|
27
|
+
├── deployment
|
28
|
+
│ ├── dev.yaml
|
29
|
+
│ └── prod.yaml
|
30
|
+
├── deployment.yaml
|
31
|
+
└── service.yaml
|
32
|
+
|
33
|
+
## Concrete Example
|
34
|
+
|
35
|
+
Let's look at a concrete web/deployment.yaml.
|
36
|
+
|
37
|
+
Here are the files that get layered when `KUBES_ENV=dev`:
|
38
|
+
|
39
|
+
.kubes/resources/base/all.yaml
|
40
|
+
.kubes/resources/base/deployment.yaml
|
41
|
+
.kubes/resources/web/deployment.yaml
|
42
|
+
.kubes/resources/web/deployment/dev.yaml
|
43
|
+
|
44
|
+
And when `KUBES_ENV=prod`:
|
45
|
+
|
46
|
+
.kubes/resources/base/all.yaml
|
47
|
+
.kubes/resources/base/deployment.yaml
|
48
|
+
.kubes/resources/web/deployment.yaml
|
49
|
+
.kubes/resources/web/deployment/prod.yaml
|
50
|
+
|
51
|
+
Layering allows us to have common settings that are processed before your main `.kubes/resources/web/deployment.yaml` YAML manifest. And then add **environment** specific YAML files that get merged.
|
52
|
+
|
53
|
+
## Variables and Helpers
|
54
|
+
|
55
|
+
Additional, you can use variables and helpers to provide environment specific values.
|
@@ -0,0 +1,62 @@
|
|
1
|
+
---
|
2
|
+
title: Advanced Variables
|
3
|
+
nav_text: Advanced
|
4
|
+
categories: variables
|
5
|
+
---
|
6
|
+
|
7
|
+
Basic variables layering should provides enough flexibility and is generally recommended. This page covers more advanced variables layering.
|
8
|
+
|
9
|
+
## Advanced Layering Example
|
10
|
+
|
11
|
+
Here's a more complex structure to demonstrate advanced layering.
|
12
|
+
|
13
|
+
.kubes/variables
|
14
|
+
├── base
|
15
|
+
│ └── deployment.rb
|
16
|
+
├── base.rb
|
17
|
+
├── dev.rb
|
18
|
+
├── prod.rb
|
19
|
+
└── web
|
20
|
+
├── deployment
|
21
|
+
│ ├── dev.rb
|
22
|
+
│ └── prod.rb
|
23
|
+
└── deployment.rb
|
24
|
+
|
25
|
+
## Concrete Example
|
26
|
+
|
27
|
+
Let's look at a concrete web/deployment.yaml.
|
28
|
+
|
29
|
+
Here are the files that get layered when `KUBES_ENV=dev`:
|
30
|
+
|
31
|
+
.kubes/variables/base.rb
|
32
|
+
.kubes/variables/dev.rb
|
33
|
+
.kubes/variables/base/deployment.rb
|
34
|
+
.kubes/variables/web/deployment.rb
|
35
|
+
.kubes/variables/web/deployment/dev.rb
|
36
|
+
|
37
|
+
And when `KUBES_ENV=prod`:
|
38
|
+
|
39
|
+
.kubes/variables/base.rb
|
40
|
+
.kubes/variables/prod.rb
|
41
|
+
.kubes/variables/base/deployment.rb
|
42
|
+
.kubes/variables/web/deployment.rb
|
43
|
+
.kubes/variables/web/deployment/prod.rb
|
44
|
+
|
45
|
+
With advanced layering you can target a specific role and kind. So variables are only scoped to the resources you want.
|
46
|
+
|
47
|
+
## Full Layering Table
|
48
|
+
|
49
|
+
Here's a table showing the the full layering.
|
50
|
+
|
51
|
+
Folder/Pattern | Example
|
52
|
+
------------------|--------------------------------------------
|
53
|
+
base.rb | base.rb
|
54
|
+
ENV.rb | dev.rb
|
55
|
+
base/all.rb | base/all.rb
|
56
|
+
base/all/ENV.rb | base/all/dev.rb
|
57
|
+
base/KIND.rb | base/deployment.rb
|
58
|
+
base/KIND/base.rb | base/deployment/base.rb
|
59
|
+
base/KIND/ENV.rb | base/deployment/dev.rb
|
60
|
+
ROLE/KIND.rb | web/deployment.rb
|
61
|
+
ROLE/KIND/base.rb | web/deployment/base.rb
|
62
|
+
ROLE/KIND/ENV.rb | web/deployment/dev.rb
|
@@ -0,0 +1,137 @@
|
|
1
|
+
---
|
2
|
+
title: Basic Variables
|
3
|
+
nav_text: Basic
|
4
|
+
categories: variables
|
5
|
+
---
|
6
|
+
|
7
|
+
## Basic Layering Example
|
8
|
+
|
9
|
+
Here's an example variables directory structure:
|
10
|
+
|
11
|
+
.kubes/variables
|
12
|
+
├── base.rb
|
13
|
+
├── dev.rb
|
14
|
+
└── prod.rb
|
15
|
+
|
16
|
+
base.rb
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
@endpoint = "base-endpoint" # overriden by ENV specific variable files.
|
20
|
+
```
|
21
|
+
|
22
|
+
dev.rb
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
@endpoint = "dev-endpoint"
|
26
|
+
```
|
27
|
+
|
28
|
+
prod.rb
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
@endpoint = "prod-endpoint"
|
32
|
+
```
|
33
|
+
|
34
|
+
The `@endpoint` value will be overriden by the ENV specific variable files.
|
35
|
+
|
36
|
+
## Deployment YAML
|
37
|
+
|
38
|
+
Here's an example deployment.yaml
|
39
|
+
|
40
|
+
.kubes/resources/web/deployment.yaml
|
41
|
+
|
42
|
+
```yaml
|
43
|
+
apiVersion: apps/v1
|
44
|
+
kind: Deployment
|
45
|
+
metadata:
|
46
|
+
name: web
|
47
|
+
labels:
|
48
|
+
role: web
|
49
|
+
spec:
|
50
|
+
replicas: 1 # overridden on a env basis
|
51
|
+
selector:
|
52
|
+
matchLabels:
|
53
|
+
role: web
|
54
|
+
template:
|
55
|
+
metadata:
|
56
|
+
labels:
|
57
|
+
role: web
|
58
|
+
spec:
|
59
|
+
containers:
|
60
|
+
- name: web
|
61
|
+
image: <%= docker_image %>
|
62
|
+
env:
|
63
|
+
- name: endpoint
|
64
|
+
value: <%= @endpoint %>
|
65
|
+
```
|
66
|
+
|
67
|
+
## Deploy
|
68
|
+
|
69
|
+
When you deploy you can use `KUBES_ENV` to and the ENV specific variables will be used:
|
70
|
+
|
71
|
+
KUBES_ENV=dev kubes deploy
|
72
|
+
|
73
|
+
Results in:
|
74
|
+
|
75
|
+
```yaml
|
76
|
+
metadata:
|
77
|
+
namespace: demo-dev
|
78
|
+
labels:
|
79
|
+
app: demo
|
80
|
+
role: web
|
81
|
+
name: web
|
82
|
+
spec:
|
83
|
+
selector:
|
84
|
+
matchLabels:
|
85
|
+
app: demo
|
86
|
+
role: web
|
87
|
+
template:
|
88
|
+
metadata:
|
89
|
+
labels:
|
90
|
+
app: demo
|
91
|
+
role: web
|
92
|
+
spec:
|
93
|
+
containers:
|
94
|
+
- name: web
|
95
|
+
image: gcr.io/GOOGLE_PROJECT/demo:kubes-2020-11-07T22-29-02
|
96
|
+
env:
|
97
|
+
- name: endpoint
|
98
|
+
value: dev-endpoint
|
99
|
+
replicas: 1
|
100
|
+
apiVersion: apps/v1
|
101
|
+
kind: Deployment
|
102
|
+
```
|
103
|
+
|
104
|
+
When using `KUBES_ENV=prod` the endpoint will use the `variables/prod.rb` values.
|
105
|
+
|
106
|
+
KUBES_ENV=prod kubes deploy
|
107
|
+
|
108
|
+
Results in:
|
109
|
+
|
110
|
+
```yaml
|
111
|
+
metadata:
|
112
|
+
namespace: demo-prod
|
113
|
+
labels:
|
114
|
+
app: demo
|
115
|
+
role: web
|
116
|
+
name: web
|
117
|
+
spec:
|
118
|
+
selector:
|
119
|
+
matchLabels:
|
120
|
+
app: demo
|
121
|
+
role: web
|
122
|
+
template:
|
123
|
+
metadata:
|
124
|
+
labels:
|
125
|
+
app: demo
|
126
|
+
role: web
|
127
|
+
spec:
|
128
|
+
containers:
|
129
|
+
- name: web
|
130
|
+
image: gcr.io/GOOGLE_PROJECT/demo:kubes-2020-11-07T22-29-02
|
131
|
+
env:
|
132
|
+
- name: endpoint
|
133
|
+
value: prod-endpoint
|
134
|
+
replicas: 1
|
135
|
+
apiVersion: apps/v1
|
136
|
+
kind: Deployment
|
137
|
+
```
|
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
title: Variables
|
3
|
+
---
|
4
|
+
|
5
|
+
You can set variables to be made available to the templates. Generally, it is recommended to use Basic layering.
|
6
|
+
|
7
|
+
{% assign docs = site.docs | where: "categories","variables" %}
|
8
|
+
{% for doc in docs -%}
|
9
|
+
* [{{ doc.title }}]({{ doc.url }})
|
10
|
+
{% endfor %}
|
11
|
+
|
12
|
+
## Generator
|
13
|
+
|
14
|
+
To help you get started quickly, you can generate starter variable code.
|
15
|
+
|
16
|
+
$ kubes new variable
|
17
|
+
create .kubes/variables/dev.rb
|
18
|
+
|
19
|
+
.kubes/variables/dev.rb
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
@example = "dev-value"
|
23
|
+
```
|
@@ -0,0 +1,109 @@
|
|
1
|
+
---
|
2
|
+
title: Kubes vs Custom Solutions
|
3
|
+
nav_text: Custom Solutions
|
4
|
+
categories: vs
|
5
|
+
---
|
6
|
+
|
7
|
+
Kubernetes provide a great platform to run and manage Docker containers. The `kubectl` command how you usually interact with a Kubernetes cluster. It does its job well and is quite a powerful tool.
|
8
|
+
|
9
|
+
{% include vs/article.md %}
|
10
|
+
|
11
|
+
## Kubernetes Questions
|
12
|
+
|
13
|
+
With Kubernetes, you usually use `kubectl` commands to deploy Docker images and run them on a Kubernetes cluster. As you get your Kubernetes applications production-ready, you'll have to answer many questions:
|
14
|
+
|
15
|
+
* How do you create multiple environments like dev and prod with the same code and not duplicate the YAML?
|
16
|
+
* How you handle creating service accounts and managing cloud permissions like AWS IAM, Google Service Accounts, etc?
|
17
|
+
* How will we build the Docker image and update Docker image?
|
18
|
+
* How do you deploy updated Kubernetes YAML settings in a controlled manner?
|
19
|
+
|
20
|
+
## Kubectl with Simple Wrappers
|
21
|
+
|
22
|
+
Most folks start off with `kubectl` commands to create their Kubernetes resources. It's simple. It's also important to learn how to use `kubectl` commands to establish fundamentals. Eventually, you grow tired of typing the same commands repeatedly, though. So you write a wrapper bash script. Example:
|
23
|
+
|
24
|
+
kubectl-wrapper.sh
|
25
|
+
|
26
|
+
kubectl apply -f service.yaml
|
27
|
+
kubectl apply -f deployment.yaml
|
28
|
+
|
29
|
+
Bash shines for simple scripts and light glue, but it can quickly get messy as the script takes on more things to do.
|
30
|
+
|
31
|
+
## Multiple Envs Duplication
|
32
|
+
|
33
|
+
One way to create different env like dev and prod is to copy their YAML files. Here's a naive example structure:
|
34
|
+
|
35
|
+
├── dev
|
36
|
+
│ ├── deployment.yaml
|
37
|
+
│ └── service.yaml
|
38
|
+
└── prod
|
39
|
+
├── deployment.yaml
|
40
|
+
└── service.yaml
|
41
|
+
|
42
|
+
We then write a wrapper script that selects the folder:
|
43
|
+
|
44
|
+
kubectl-wrapper.sh
|
45
|
+
|
46
|
+
KUBE_ENV=${1:-dev}
|
47
|
+
kubectl apply -f $KUBE_ENV/service.yaml
|
48
|
+
kubectl apply -f $KUBE_ENV/deployment.yaml
|
49
|
+
|
50
|
+
We've duplicated `service.yaml` and `deployment.yaml`, though. Instead, it'll be nice if we use the same YAML and create a different env like dev and prod with it. Things like `envsubst` to replace variables from the same "template" YAML files can help. As requirements increases, the simple bash glue scripts end up getting messy.
|
51
|
+
|
52
|
+
## PreBuilt Docker Image
|
53
|
+
|
54
|
+
Additionally, the Docker image is expected to be prebuilt. Because you must first build the Docker image, folks will usually write bash script that perform these additional steps and then glue things together.
|
55
|
+
|
56
|
+
## Kubernetes Resources Galore
|
57
|
+
|
58
|
+
Kubernetes has a large service area, and there are so many resource Kinds that we can create that it's difficult for a simple wrapper script to handle enough control for your needs.
|
59
|
+
|
60
|
+
## Kubes Makes It Easier
|
61
|
+
|
62
|
+
Kubes is a Kubernetes Deployment Tool that automates the following:
|
63
|
+
|
64
|
+
1. It builds the docker image
|
65
|
+
2. Creates the Kubernetes YAML
|
66
|
+
3. Runs kubectl apply
|
67
|
+
|
68
|
+
Kubes works transparently and straightforwardly. The deploy command simply do all 3 steps: build, compile, and apply.
|
69
|
+
|
70
|
+
kubes deploy
|
71
|
+
|
72
|
+
### Layering: Multiple Environments like dev and prod
|
73
|
+
|
74
|
+
To deploy and create multiple environments like dev and prod with the same YAML, we use a different KUBES_ENV setting:
|
75
|
+
|
76
|
+
KUBES_ENV=dev kubes deploy
|
77
|
+
KUBES_ENV=prod kubes deploy
|
78
|
+
|
79
|
+
The same code is used to create different environments. Kubes achieves this with a feature called Layering. The concept is similar to Kustomize overlays. Here's the general layering processing order that Kubes takes.
|
80
|
+
|
81
|
+
* [Layering Docs]({% link _docs/layering.md %})
|
82
|
+
|
83
|
+
## Hooks
|
84
|
+
|
85
|
+
Kubes support a variety of hooks run scripts at any part of the `kubectl` commands. This allows you customize and add app-specific logic needed. Example:
|
86
|
+
|
87
|
+
.kubes/config/hooks/kubectl.rb
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
before("apply",
|
91
|
+
on: "web/deployment",
|
92
|
+
execute: "echo 'before apply hook test'",
|
93
|
+
)
|
94
|
+
|
95
|
+
after("delete",
|
96
|
+
on: "web/deployment",
|
97
|
+
execute: "echo 'after delete hook test'",
|
98
|
+
)
|
99
|
+
```
|
100
|
+
|
101
|
+
There are also [cloud helpers]({% link _docs/helpers.md %}) that will handle things like Secrets and IAM Account creation.
|
102
|
+
|
103
|
+
* [Kubes Kubectl Hooks Docs]({% link _docs/config/hooks/kubectl.md %})
|
104
|
+
|
105
|
+
## Summary
|
106
|
+
|
107
|
+
Many companies roll their own custom solutions. Chances are that the `kubectl` wrapper scripts eventually grow into messy glue. Every time you go to another company, you must relearn and figure out the home-grown solution's particularities. Even within companies, going from team to team, there may be different scripts that are their own unique beasts. It's a science project.
|
108
|
+
|
109
|
+
Kubes provides a tool that streamlines the `kubectl` deployment already. Kubes also works in a transparent and straightforward manner. You know what's going on. It's also extendable and customizable. You can add business logic that you wish. Kubes provides convenient tooling and helps you get things done quickly.
|