kubes 0.5.0 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gcloudignore +22 -0
- data/.gitignore +1 -1
- data/CHANGELOG.md +22 -0
- data/Dockerfile +6 -6
- data/Dockerfile.alpine +20 -0
- data/README.md +54 -8
- data/docker/install/docker.sh +8 -0
- data/docker/install/gcloud.sh +18 -0
- data/docker/install/kubectl.sh +4 -0
- data/docs/_docs/config/hooks/kubes.md +1 -0
- data/docs/_docs/config/reference.md +1 -0
- data/docs/_docs/dsl/multiple-resources.md +3 -1
- data/docs/_docs/dsl/resources/secret.md +19 -2
- data/docs/_docs/generators.md +4 -4
- data/docs/_docs/helpers.md +16 -2
- data/docs/_docs/helpers/aws/advanced.md +10 -0
- 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/secrets.md +18 -88
- data/docs/_docs/helpers/aws/ssm.md +20 -38
- data/docs/_docs/helpers/google/advanced.md +10 -0
- data/docs/_docs/helpers/google/advanced/secrets.md +78 -0
- data/docs/_docs/helpers/google/gke.md +89 -0
- data/docs/_docs/helpers/google/secrets.md +18 -27
- data/docs/_docs/intro.md +2 -11
- data/docs/_docs/intro/how-kubes-works.md +7 -11
- data/docs/_docs/layering.md +2 -0
- data/docs/_docs/layering/mix.md +99 -0
- data/docs/_docs/patterns/multiple-envs.md +55 -0
- data/docs/_docs/variables.md +23 -0
- data/docs/_docs/variables/advanced.md +62 -0
- data/docs/_docs/variables/basic.md +137 -0
- data/docs/_docs/vs.md +10 -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/_includes/intro/features.md +11 -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.rb +4 -3
- data/lib/kubes/auth.rb +13 -1
- 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/cli/apply.rb +0 -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.rb +12 -94
- 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/prune.rb +4 -2
- 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.rb +7 -6
- 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/util/normalize.rb +6 -3
- data/lib/kubes/compiler/util/yaml_dump.rb +4 -4
- data/lib/kubes/config.rb +14 -0
- data/lib/kubes/hooks/builder.rb +20 -5
- data/lib/kubes/hooks/concern.rb +1 -1
- data/lib/kubes/kubectl/batch.rb +7 -0
- data/lib/kubes/plugin.rb +14 -0
- data/lib/kubes/util/sh.rb +1 -1
- data/lib/kubes/version.rb +1 -1
- 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 -1
- 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 +95 -56
|
@@ -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/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 %}
|
|
@@ -10,20 +10,16 @@ In fact, you can use Kubes to build the files first, and then run `kubectl` dire
|
|
|
10
10
|
kubes docker push
|
|
11
11
|
kubes compile # compiles the .kubes/resources files to .kubes/output
|
|
12
12
|
|
|
13
|
-
Now, use `kubectl` directly
|
|
13
|
+
Now, use `kubectl` directly and apply them in the proper order:
|
|
14
14
|
|
|
15
|
-
kubectl apply
|
|
16
|
-
|
|
17
|
-
You can also selectively apply specific files:
|
|
18
|
-
|
|
19
|
-
kubectl apply -f .kubes/output/web/deployment.yaml
|
|
15
|
+
kubectl apply -f .kubes/output/shared/namespace.yaml
|
|
20
16
|
kubectl apply -f .kubes/output/web/service.yaml
|
|
17
|
+
kubectl apply -f .kubes/output/web/deployment.yaml
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
kubes apply
|
|
25
|
-
|
|
26
|
-
The deploy command, does all 3 steps: builds the docker image, compiles the `.kubes/resources` files, and runs kubectl apply.
|
|
19
|
+
The deploy command simpifily does all 3 steps: build, compile, and apply.
|
|
27
20
|
|
|
28
21
|
kubes deploy
|
|
29
22
|
|
|
23
|
+
You can also run the `kubectl apply` only. The `kube apply` command compiles but will skip the docker build stage if it's already been built.
|
|
24
|
+
|
|
25
|
+
kubes apply
|
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,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 merged 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
|
+
```
|
|
@@ -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,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,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
|
+
```
|