kubes 0.3.1 → 0.4.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 +27 -0
- data/README.md +6 -5
- data/docs/_config.yml +1 -1
- data/docs/_docs/ci/cloudbuild.md +2 -0
- data/docs/_docs/config/args.md +10 -0
- data/docs/_docs/config/args/docker.md +19 -0
- data/docs/_docs/config/args/kubectl.md +19 -0
- data/docs/_docs/config/docker.md +4 -40
- data/docs/_docs/config/env.md +1 -1
- data/docs/_docs/config/hooks.md +10 -0
- data/docs/_docs/config/hooks/docker.md +70 -0
- data/docs/_docs/config/hooks/kubectl.md +83 -0
- data/docs/_docs/config/hooks/kubes.md +67 -0
- data/docs/_docs/config/hooks/ruby.md +74 -0
- data/docs/_docs/config/kubectl.md +3 -54
- data/docs/_docs/config/reference.md +20 -0
- data/docs/_docs/config/skip.md +58 -0
- data/docs/_docs/dsl/resources.md +1 -1
- data/docs/_docs/dsl/resources/backend_config.md +1 -1
- data/docs/_docs/intro.md +6 -3
- data/docs/_docs/learn/yaml/new-project.md +0 -1
- data/docs/_docs/{auto-context.md → misc/auto-context.md} +0 -0
- data/docs/_docs/{kustomize.md → misc/kustomize.md} +0 -0
- data/docs/_docs/misc/separate-steps.md +21 -0
- data/docs/_docs/patterns/migrations.md +121 -0
- data/docs/_includes/commands.html +2 -0
- data/docs/_includes/config/hooks/options.md +20 -0
- data/docs/_includes/sidebar.html +32 -10
- data/docs/_reference/kubes-exec.md +14 -6
- data/docs/_reference/kubes-init.md +1 -0
- data/docs/_reference/kubes-logs.md +1 -0
- data/docs/_sass/theme.scss +27 -2
- data/docs/img/logos/kubes-white.png +0 -0
- data/docs/index.html +2 -2
- data/lib/kubes/cli.rb +25 -6
- data/lib/kubes/cli/apply.rb +2 -1
- data/lib/kubes/cli/base.rb +11 -0
- data/lib/kubes/cli/delete.rb +1 -1
- data/lib/kubes/cli/exec.rb +37 -6
- data/lib/kubes/cli/get.rb +3 -2
- data/lib/kubes/cli/init.rb +34 -2
- data/lib/kubes/cli/logs.rb +52 -3
- data/lib/kubes/cli/prune.rb +95 -0
- data/lib/kubes/compiler.rb +18 -7
- data/lib/kubes/compiler/decorator/base.rb +7 -1
- data/lib/kubes/compiler/decorator/{resources/secret.rb → hashable.rb} +5 -4
- data/lib/kubes/compiler/decorator/hashable/field.rb +53 -0
- data/lib/kubes/compiler/decorator/hashable/storage.rb +19 -0
- data/lib/kubes/compiler/decorator/post.rb +77 -0
- data/lib/kubes/compiler/decorator/pre.rb +12 -0
- data/lib/kubes/compiler/strategy.rb +2 -2
- data/lib/kubes/compiler/strategy/base.rb +1 -1
- data/lib/kubes/compiler/strategy/result.rb +4 -6
- data/lib/kubes/config.rb +16 -11
- data/lib/kubes/docker/strategy/build/docker.rb +1 -1
- data/lib/kubes/docker/strategy/build/gcloud.rb +1 -1
- data/lib/kubes/docker/strategy/image_name.rb +1 -1
- data/lib/kubes/docker/strategy/push/docker.rb +1 -1
- data/lib/kubes/docker/strategy/push/gcloud.rb +1 -1
- data/lib/kubes/docker/strategy/utils.rb +1 -1
- data/lib/kubes/hooks/builder.rb +29 -15
- data/lib/kubes/hooks/concern.rb +10 -0
- data/lib/kubes/hooks/dsl.rb +2 -1
- data/lib/kubes/hooks/runner.rb +22 -0
- data/lib/kubes/kubectl.rb +21 -18
- data/lib/kubes/kubectl/batch.rb +8 -5
- data/lib/kubes/kubectl/{decider.rb → dispatcher.rb} +1 -1
- data/lib/kubes/kubectl/fetch/base.rb +13 -10
- data/lib/kubes/kubectl/fetch/deployment.rb +21 -11
- data/lib/kubes/kubectl/fetch/pods.rb +4 -15
- data/lib/kubes/kubectl/kustomize.rb +1 -1
- data/lib/kubes/kubectl/ordering.rb +12 -0
- data/lib/kubes/util/consider.rb +2 -1
- data/lib/kubes/util/sh.rb +1 -1
- data/lib/kubes/version.rb +1 -1
- data/lib/templates/dsl/.kubes/resources/base/all.rb.tt +6 -1
- data/lib/templates/dsl/.kubes/resources/shared/namespace.rb.tt +1 -1
- data/lib/templates/dsl/.kubes/resources/web/deployment.rb +1 -1
- data/lib/templates/yaml/.kubes/resources/base/all.yaml.tt +1 -1
- data/lib/templates/yaml/.kubes/resources/shared/namespace.yaml.tt +1 -1
- data/lib/templates/yaml/.kubes/resources/web/deployment.yaml.tt +1 -1
- data/spec/fixtures/decorators/deployment/both/envFrom.yaml +31 -0
- data/spec/fixtures/prune/capture.yaml +57 -0
- data/spec/fixtures/prune/fetch_items.yaml +268 -0
- data/spec/kubes/cli/prune_spec.rb +38 -0
- data/spec/kubes/compiler/decorator/{resources → post}/deployment_spec.rb +25 -6
- data/spec/kubes/compiler/decorator/{resources → post}/pod_spec.rb +2 -11
- metadata +39 -19
- data/lib/kubes/compiler/decorator.rb +0 -17
- data/lib/kubes/compiler/decorator/compile.rb +0 -12
- data/lib/kubes/compiler/decorator/resources/base.rb +0 -13
- data/lib/kubes/compiler/decorator/resources/container.rb +0 -76
- data/lib/kubes/compiler/decorator/resources/container/mapping.rb +0 -28
- data/lib/kubes/compiler/decorator/resources/deployment.rb +0 -10
- data/lib/kubes/compiler/decorator/resources/pod.rb +0 -10
- data/lib/kubes/compiler/decorator/write.rb +0 -14
- data/lib/kubes/docker/strategy/hooks.rb +0 -9
@@ -1,61 +1,10 @@
|
|
1
1
|
---
|
2
|
-
title: Kubectl
|
2
|
+
title: Kubectl Customizations
|
3
3
|
---
|
4
4
|
|
5
5
|
## General
|
6
6
|
|
7
7
|
Kubes calls out the `kubectl` command. You can customize the command.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
Here are some examples of customizing the kubectl args.
|
12
|
-
|
13
|
-
.kubes/config/kubectl/args.rb
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
command("apply",
|
17
|
-
args: ["--validate=true"],
|
18
|
-
)
|
19
|
-
|
20
|
-
command("delete",
|
21
|
-
args: ["--grace-period=-1"],
|
22
|
-
)
|
23
|
-
```
|
24
|
-
|
25
|
-
## Hooks
|
26
|
-
|
27
|
-
Here are some examples of running custom hooks before and after the kubectl commands.
|
28
|
-
|
29
|
-
.kubes/config/kubectl/hooks.rb
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
before("apply",
|
33
|
-
execute: "kubectl apply -f .kubes/shared/namespace.yaml",
|
34
|
-
)
|
35
|
-
|
36
|
-
after("delete",
|
37
|
-
execute: "echo 'delete hook',
|
38
|
-
)
|
39
|
-
```
|
40
|
-
|
41
|
-
You can use hooks to do things that may not make sense to do in the `.kubes/resources` definition. Here's an example of automatically creating the namespace.
|
42
|
-
|
43
|
-
.kubes/shared/namespace.yaml
|
44
|
-
|
45
|
-
```yaml
|
46
|
-
apiVersion: v1
|
47
|
-
kind: Namespace
|
48
|
-
metadata:
|
49
|
-
name: demo
|
50
|
-
```
|
51
|
-
|
52
|
-
### exit on fail
|
53
|
-
|
54
|
-
By default, if the hook commands fail, then terraspace will exit with the original hook error code. You can change this behavior with the `exit_on_fail` option.
|
55
|
-
|
56
|
-
```ruby
|
57
|
-
before("apply"
|
58
|
-
execute: "/command/will/fail/but/will/continue",
|
59
|
-
exit_on_fail: false,
|
60
|
-
)
|
61
|
-
```
|
9
|
+
* [Args]({% link _docs/config/args/kubectl.md %}): Customize the CLI args.
|
10
|
+
* [Hooks]({% link _docs/config/hooks/kubectl.md %}): Run hooks before and after the kubectl commands.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
title: Config Reference
|
3
|
+
---
|
4
|
+
|
5
|
+
Name | Description | Default
|
6
|
+
---|---|---
|
7
|
+
auto_prune | Prune and delete old hashed resources like Secret and ConfigMap. | true
|
8
|
+
builder | What docker build command to use. Can use `docker` or `gcloud` to build the Docker image. | docker
|
9
|
+
kubectl.context | What kubectl context to auto-switch to. | nil
|
10
|
+
kubectl.context_keep | Whether or not to keep the context switched | true
|
11
|
+
kubectl.exit_on_fail.apply | Whether or not continue if the `kubectl apply` fails. Note, can use `KUBES_EXIT_ON_FAIL=0` env var to set to false. | true
|
12
|
+
kubectl.exit_on_fail.delete | Whether or not continue if the `kubectl delete` fails. | false
|
13
|
+
kubectl.order.kinds | Change ordering for Kubernetes Kinds. | See [source code](https://github.com/boltops-tools/kubes/blob/master/lib/kubes/config.rb#L52)
|
14
|
+
kubectl.order.roles | Change ordering for Kubes Roles. | See [source code](https://github.com/boltops-tools/kubes/blob/master/lib/kubes/config.rb#L44)
|
15
|
+
logger | Logger object | Logger.new($stdout)
|
16
|
+
logger.level | Logger level. Can also be set with `KUBES_LOG_LEVEL` env var | info
|
17
|
+
repo | The Docker repo to use. Required to be set. | nil
|
18
|
+
skip | List of resources to skip. Can also be set with the `KUBES_SKIP` env var. `KUBES_SKIP` should be a list of strings separated by spaces. It adds onto the `config.skip` option. | []
|
19
|
+
state.docker_image_path | Where to store the state file with the last build Docker image. | .kubes/state/docker_image.txt
|
20
|
+
suffix_hash | Whether or not to append suffix hash to ConfigMap and Secret | true
|
@@ -0,0 +1,58 @@
|
|
1
|
+
---
|
2
|
+
title: Skip Option
|
3
|
+
---
|
4
|
+
|
5
|
+
You can tell Kubes to skip resources to deploy. This can useful if you want to still resources with Kubes and have it compile `.kubes/output` files, but wish to deploy them outside of Kubes manually.
|
6
|
+
|
7
|
+
## Example
|
8
|
+
|
9
|
+
Here's an example with a Job.
|
10
|
+
|
11
|
+
.kubes/resources/cleanup/job.yaml:
|
12
|
+
|
13
|
+
```yaml
|
14
|
+
apiVersion: batch/v1
|
15
|
+
kind: Job
|
16
|
+
metadata:
|
17
|
+
name: cleanup
|
18
|
+
spec:
|
19
|
+
template:
|
20
|
+
spec:
|
21
|
+
containers:
|
22
|
+
- name: cleanup
|
23
|
+
image: <%= built_image %>
|
24
|
+
command: ["bin/cleanup.sh"]
|
25
|
+
restartPolicy: Never
|
26
|
+
```
|
27
|
+
|
28
|
+
To skip the cleanup job, use the `config.skip` option:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
Kubes.configure do |config|
|
32
|
+
config.skip = ["cleanup/job"]
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
Now when you deploy, the `cleanup/job` resource will not be deployed:
|
37
|
+
|
38
|
+
kubes deploy # deploys everything except cleanup/job
|
39
|
+
|
40
|
+
## Deploy Outside of Kubes
|
41
|
+
|
42
|
+
Then to deploy outside of kubes.
|
43
|
+
|
44
|
+
$ kubes compile # not necessary if already ran: kubes deploy
|
45
|
+
Compiled .kubes/resources files to .kubes/output
|
46
|
+
$ kubectl apply -f .kubes/output/cleanup/job.yaml
|
47
|
+
job.batch/cleanup created
|
48
|
+
$ kubectl delete -f .kubes/output/cleanup/job.yaml
|
49
|
+
job.batch "cleanup" deleted
|
50
|
+
$
|
51
|
+
|
52
|
+
## Env Var KUBES_SKIP
|
53
|
+
|
54
|
+
You can also us ethe `KUBES_SKIP` env var. It takes list of strings separated by a space. It adds onto the `config.skip` option. Example:
|
55
|
+
|
56
|
+
KUBES_SKIP="cleanup/job" kubes delete
|
57
|
+
|
58
|
+
This can be useful for one-off use cases.
|
data/docs/_docs/dsl/resources.md
CHANGED
@@ -6,7 +6,7 @@ Here's a list of the resources supported by the Kubes DSL.
|
|
6
6
|
|
7
7
|
{% assign docs = site.docs | where: "categories","dsl" %}
|
8
8
|
{% for doc in docs -%}
|
9
|
-
* [{{ doc.
|
9
|
+
* [{{ doc.nav_text }}]({{ doc.url }})
|
10
10
|
{% endfor %}
|
11
11
|
|
12
12
|
For resources, that are not supported, you can use the [Generic resource]({% link _docs/dsl/resources/generic.md %}) or use [YAML]({% link _docs/yaml.md %}) instead. You can use a mix of DSL and YAML definitions in the `.kubes/resources` folder.
|
@@ -3,7 +3,7 @@ title: BackendConfig
|
|
3
3
|
categories: dsl
|
4
4
|
---
|
5
5
|
|
6
|
-
A BackendConfig is [custom resource definitions (CRDs)](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) that allow you to further customize the load balancer.
|
6
|
+
A [BackendConfig](https://cloud.google.com/kubernetes-engine/docs/how-to/ingress-features#create_backendconfig) is [custom resource definitions (CRDs)](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) that allow you to further customize the load balancer.
|
7
7
|
|
8
8
|
Here's an example of a BackendConfig.
|
9
9
|
|
data/docs/_docs/intro.md
CHANGED
@@ -4,12 +4,15 @@ title: What is Kubes?
|
|
4
4
|
|
5
5
|
{% include reference.md %}
|
6
6
|
|
7
|
+
<div class="video-box"><div class="video-container"><iframe src="https://www.youtube.com/embed/M4zHL0mfKNU" frameborder="0" allowfullscreen=""></iframe></div></div>
|
8
|
+
|
7
9
|
## Features:
|
8
10
|
|
9
11
|
* Automation: [Builds the Docker image]({% link _docs/config/docker.md %}) and updates the compiled YAML files
|
10
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.
|
11
13
|
* Layering: Use the same Kubernetes YAML to build multiple environments like dev and prod with [layering]({% link _docs/layering.md %}).
|
12
|
-
* CLI Customizations: You can customize the [cli args]({% link _docs/config/kubectl.md %}). You can also run hooks before and after kubectl commands.
|
14
|
+
* CLI Customizations: You can customize the [cli args]({% link _docs/config/args/kubectl.md %}). You can also run [hooks]({% link _docs/config/hooks/kubectl.md %}) before and after kubectl commands.
|
13
15
|
* 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.
|
14
|
-
* Kustomize Support: If you’re a kustomization user, you can use it with Kubes. More details in [Kustomize Support Docs]({% link _docs/kustomize.md %}).
|
15
|
-
* 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/auto-context.md %}).
|
16
|
+
* 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 %}).
|
17
|
+
* 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 %}).
|
18
|
+
* 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,7 +11,6 @@ If you already a project with an existing Dockerfile, you can use that. If you d
|
|
11
11
|
|
12
12
|
Let's generate a starter project:
|
13
13
|
|
14
|
-
$ REPO=$(aws ecr describe-repositories --repository-name demo | jq -r '.repositories[].repositoryUri')
|
15
14
|
$ kubes init --app demo --repo $REPO
|
16
15
|
create Dockerfile
|
17
16
|
create .kubes/config.rb
|
File without changes
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
title: Separate Steps
|
3
|
+
---
|
4
|
+
|
5
|
+
Sometimes you may want to run the 3 separate kubes steps directly. This may be useful if you are setting up CI/CD and need more control over the build process. Here are the 3 main steps:
|
6
|
+
|
7
|
+
To build and push the docker image:
|
8
|
+
|
9
|
+
kubes docker build
|
10
|
+
kubes docker push
|
11
|
+
|
12
|
+
Note, you must run a `kubes docker build` at least once. As the build step will store the image name in a `.kubes/state/docker_image.txt ` file for later use.
|
13
|
+
|
14
|
+
To compile the Kubernetes YAML files.
|
15
|
+
|
16
|
+
kubes compile
|
17
|
+
|
18
|
+
To apply the Kubernetes YAML files in the correct order and create resources on the cluster:
|
19
|
+
|
20
|
+
kubes apply
|
21
|
+
|
@@ -0,0 +1,121 @@
|
|
1
|
+
---
|
2
|
+
title: Database Migrations
|
3
|
+
---
|
4
|
+
|
5
|
+
A common task is to run database migrations. You can use Kubes hooks to achieve this as part of the `kubes deploy` process.
|
6
|
+
|
7
|
+
1. Create Migrate Job YAML
|
8
|
+
2. Set up Kubes Hooks
|
9
|
+
|
10
|
+
## 1. Create Migrate Job YAML
|
11
|
+
|
12
|
+
First, let's create the migrate job YAML. Here's a starter example:
|
13
|
+
|
14
|
+
.kubes/resources/migrate/job.yaml
|
15
|
+
|
16
|
+
```yaml
|
17
|
+
apiVersion: batch/v1
|
18
|
+
kind: Job
|
19
|
+
metadata:
|
20
|
+
name: migrate
|
21
|
+
spec:
|
22
|
+
template:
|
23
|
+
spec:
|
24
|
+
containers:
|
25
|
+
- name: migrate
|
26
|
+
image: <%= built_image %>
|
27
|
+
command: ["bin/job/migrate.sh"]
|
28
|
+
restartPolicy: Never
|
29
|
+
backoffLimit: 4
|
30
|
+
```
|
31
|
+
|
32
|
+
The Kubernetes job calls a `job/migrate.sh` script. Something like this:
|
33
|
+
|
34
|
+
bin/job/migrate.sh
|
35
|
+
|
36
|
+
#!/bin/bash
|
37
|
+
rails db:migrate
|
38
|
+
|
39
|
+
## 2. Set up Kubes Hooks
|
40
|
+
|
41
|
+
Set up the [kubes hooks]({% link _docs/config/hooks/kubectl.md %}) to help the migrate job run properly.
|
42
|
+
|
43
|
+
.kubes/config/hooks/kubectl.rb
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
before("apply",
|
47
|
+
on: "migrate/job",
|
48
|
+
execute: "bin/hooks/migrate/delete.sh",
|
49
|
+
exit_on_fail: false,
|
50
|
+
)
|
51
|
+
|
52
|
+
after("apply",
|
53
|
+
on: "migrate/job",
|
54
|
+
execute: "bin/hooks/migrate/wait.sh",
|
55
|
+
)
|
56
|
+
```
|
57
|
+
|
58
|
+
Here's what the `bin/hook/migrate` scripts could look like:
|
59
|
+
|
60
|
+
bin/hooks/migrate/delete.sh
|
61
|
+
|
62
|
+
#!/bin/bash
|
63
|
+
kubectl delete job/migrate
|
64
|
+
|
65
|
+
bin/hooks/migrate/wait.sh
|
66
|
+
|
67
|
+
#!/bin/bash
|
68
|
+
kubectl wait --for=condition=Complete job/migrate --timeout=300s
|
69
|
+
|
70
|
+
The `migrate/delete.sh` script first cleans up old migrate jobs that may have been previously created.
|
71
|
+
|
72
|
+
The `migrate/wait.sh` script waits until the migration job finishes before continuing. Note, the default timeout is 30s, which may not be long enough for your migrations to finish, so we set it to 300s. The `kubectl wait` only returns if the migrate job finishes successfully. If the job fails after it exhausts all its retries, default 6, then you'll see an error like this:
|
73
|
+
|
74
|
+
+ kubectl wait --for=condition=Complete job/migrate --timeout=30s
|
75
|
+
error: timed out waiting for the condition on jobs/migrate
|
76
|
+
ERROR: running bin/hooks/migrate.sh
|
77
|
+
|
78
|
+
There is also an [migration-example](https://github.com/boltops-tools/kubes-examples/tree/master/yaml/migration-example) repo with a smarter version of the wait script.
|
79
|
+
|
80
|
+
## Example Deploy
|
81
|
+
|
82
|
+
Once that is set up, a `kubes deploy` will automatically run migrations. Here's an example deploy:
|
83
|
+
|
84
|
+
$ kubes deploy
|
85
|
+
=> kubectl apply -f .kubes/output/shared/namespace.yaml
|
86
|
+
=> bin/hooks/migrate/delete.sh
|
87
|
+
job.batch "migrate" deleted
|
88
|
+
=> kubectl apply -f .kubes/output/migrate/job.yaml
|
89
|
+
job.batch/migrate created
|
90
|
+
Running hook: after apply on: migrate/job
|
91
|
+
=> bin/hooks/migrate/wait.sh
|
92
|
+
Sun Oct 11 03:22:35 UTC 2020
|
93
|
+
Migration complete
|
94
|
+
=> kubectl apply -f .kubes/output/web/service.yaml
|
95
|
+
service/web unchanged
|
96
|
+
=> kubectl apply -f .kubes/output/web/deployment.yaml
|
97
|
+
deployment.apps/web configured
|
98
|
+
$
|
99
|
+
|
100
|
+
## To Couple or Not to Couple?
|
101
|
+
|
102
|
+
While some companies prefer running the migration step as a part of the app deploy, some prefer to separate it out as a discrete step. Usually, the separate step is still called as part of a pipeline.
|
103
|
+
|
104
|
+
In practice, the decision usually comes down to:
|
105
|
+
|
106
|
+
* The size of your database. If your database is large and the migrations take a long time to run. It makes sense to separate it out.
|
107
|
+
* The risk tolerance of database migration operations. If it's quite risky to run DB migrations, you may want to separate it as discrete step so a human can review it.
|
108
|
+
|
109
|
+
For small apps and databases, it's often pragmatic to just run everything in a single step for simplicity.
|
110
|
+
|
111
|
+
## Migration as Separate Step
|
112
|
+
|
113
|
+
If you would like it to run it as a discrete step, remove the hook in `.kubes/config/hooks/kubectl.rb`, and run it as a separate script like so:
|
114
|
+
|
115
|
+
bin/run/migrate.sh
|
116
|
+
|
117
|
+
#!/bin/bash
|
118
|
+
kubes compile
|
119
|
+
bin/hooks/migrate/delete.sh
|
120
|
+
bin/job/migrate.sh
|
121
|
+
bin/hooks/migrate/wait.sh
|
@@ -0,0 +1,20 @@
|
|
1
|
+
## General Form
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
before(COMMAND_NAME, OPTIONS)
|
5
|
+
````
|
6
|
+
|
7
|
+
The command name corresponds to the `{{ include.command }}` commands: apply, delete, etc.
|
8
|
+
|
9
|
+
## Hook Options
|
10
|
+
|
11
|
+
Name | Description
|
12
|
+
---|---
|
13
|
+
label | A human-friendly label so you can see what hooks is being run during `kubes apply`
|
14
|
+
execute | The script or command to run. IE: path/to/some/script.sh
|
15
|
+
exit_on_fail | Whether or not to continue process if the script returns an failed exit code.
|
16
|
+
{% if include.command == "kubectl" %}on | What resource to run the hook on. IE: shared/namespace, web/deployment, web/service. Note: This option is only used by kubectl hooks.{% endif %}
|
17
|
+
|
18
|
+
## Ruby Hooks
|
19
|
+
|
20
|
+
Instead of using a script for the hook `execute` option, you can also use a Ruby object. This provides some more control over the current process. See: [Ruby Hooks]({% link _docs/config/hooks/ruby.md %})
|
data/docs/_includes/sidebar.html
CHANGED
@@ -53,13 +53,37 @@
|
|
53
53
|
</li>
|
54
54
|
<li><a href="{% link _docs/config.md %}">Config</a>
|
55
55
|
<ul>
|
56
|
+
<li><a href="{% link _docs/config/args.md %}">Args</a>
|
57
|
+
<ul>
|
58
|
+
{% assign docs = site.docs | where: "categories","args" %}
|
59
|
+
{% for doc in docs -%}
|
60
|
+
<li><a href="{{ doc.url }}">{{ doc.nav_text }}</a></li>
|
61
|
+
{% endfor %}
|
62
|
+
</ul>
|
63
|
+
</li>
|
64
|
+
<li><a href="{% link _docs/config/hooks.md %}">Hooks</a>
|
65
|
+
<ul>
|
66
|
+
{% assign docs = site.docs | where: "categories","hooks" %}
|
67
|
+
{% for doc in docs -%}
|
68
|
+
<li><a href="{{ doc.url }}">{{ doc.nav_text }}</a></li>
|
69
|
+
{% endfor %}
|
70
|
+
</ul>
|
71
|
+
</li>
|
56
72
|
<li><a href="{% link _docs/config/docker.md %}">Docker</a></li>
|
57
73
|
<li><a href="{% link _docs/config/env.md %}">Env</a></li>
|
58
|
-
<li><a href="{% link _docs/config/kubectl.md %}">Kubectl</a></li>
|
59
74
|
<li><a href="{% link _docs/config/builder.md %}">Builder</a></li>
|
75
|
+
<li><a href="{% link _docs/config/skip.md %}">Skip Option</a></li>
|
76
|
+
<li><a href="{% link _docs/config/reference.md %}">Reference</a></li>
|
60
77
|
</ul>
|
61
78
|
</li>
|
62
79
|
<li><a href="{% link _docs/yaml.md %}">YAML</a></li>
|
80
|
+
<li><a href="{% link _docs/layering.md %}">Layering</a>
|
81
|
+
<ul>
|
82
|
+
<li><a href="{% link _docs/layering/yaml.md %}">YAML</a></li>
|
83
|
+
<li><a href="{% link _docs/layering/dsl.md %}">DSL</a></li>
|
84
|
+
<li><a href="{% link _docs/layering/merge.md %}">Merge Behavior</a></li>
|
85
|
+
</ul>
|
86
|
+
</li>
|
63
87
|
<li><a href="{% link _docs/dsl.md %}">DSL</a>
|
64
88
|
<ul>
|
65
89
|
<li><a href="{% link _docs/dsl/resources.md %}">Resources</a>
|
@@ -73,16 +97,10 @@
|
|
73
97
|
<li><a href="{% link _docs/dsl/multiple-resources.md %}">Multiple Resources</a>
|
74
98
|
</ul>
|
75
99
|
</li>
|
76
|
-
<li><a href="{% link _docs/layering.md %}">Layering</a>
|
77
|
-
<ul>
|
78
|
-
<li><a href="{% link _docs/layering/yaml.md %}">YAML</a></li>
|
79
|
-
<li><a href="{% link _docs/layering/dsl.md %}">DSL</a></li>
|
80
|
-
<li><a href="{% link _docs/layering/merge.md %}">Merge Behavior</a></li>
|
81
|
-
</ul>
|
82
|
-
</li>
|
83
100
|
<li><a href="{% link _docs/helpers.md %}">Helpers</a></li>
|
84
101
|
<li><a href="{% link _docs/patterns.md %}">Patterns</a>
|
85
102
|
<ul>
|
103
|
+
<li><a href="{% link _docs/patterns/migrations.md %}">Database Migrations</a></li>
|
86
104
|
<li><a href="{% link _docs/patterns/clock-web-worker.md %}">Clock Web Worker</a></li>
|
87
105
|
</ul>
|
88
106
|
</li>
|
@@ -92,8 +110,12 @@
|
|
92
110
|
<li><a href="{% link _docs/extra-env/dsl.md %}">DSL</a></li>
|
93
111
|
</ul>
|
94
112
|
</li>
|
95
|
-
<li
|
96
|
-
|
113
|
+
<li>Misc
|
114
|
+
<ul>
|
115
|
+
<li><a href="{% link _docs/misc/kustomize.md %}">Kustomize Support</a></li>
|
116
|
+
<li><a href="{% link _docs/misc/separate-steps.md %}">Separate Steps</a></li>
|
117
|
+
<li><a href="{% link _docs/misc/auto-context.md %}">Auto Context</a></li>
|
118
|
+
</ul>
|
97
119
|
<li>CI/CD
|
98
120
|
<ul>
|
99
121
|
<li><a href="{% link _docs/ci/cloudbuild.md %}">CloudBuild</a></li>
|
@@ -21,13 +21,20 @@ The exec command finds the latest pod from the deployment and runs `kubectl exec
|
|
21
21
|
|
22
22
|
## Multiple Deployments
|
23
23
|
|
24
|
-
If you have have multiple deployments in your `.kubes/resources` then the command will use the first deployment by default. You can specify the specfic deployment with the `--name` option. Examples:
|
24
|
+
If you have have multiple deployments in your `.kubes/resources` then the command will use the first deployment by default. You can specify the specfic deployment with the `--name` or `-n` option. Examples:
|
25
25
|
|
26
|
-
kubes exec --name
|
27
|
-
kubes exec
|
28
|
-
kubes exec
|
29
|
-
kubes exec
|
30
|
-
kubes exec
|
26
|
+
kubes exec --name web
|
27
|
+
kubes exec -n web
|
28
|
+
kubes exec -n clock
|
29
|
+
kubes exec -n worker
|
30
|
+
kubes exec -n web sh
|
31
|
+
kubes exec -n web ls -l
|
32
|
+
|
33
|
+
## Multiple Pod Containers
|
34
|
+
|
35
|
+
If you have have multiple containers in your pod. You can specify the specfic container with the `--container` or `-c` option. Examples:
|
36
|
+
|
37
|
+
kubes exec --name web
|
31
38
|
|
32
39
|
|
33
40
|
## Options
|
@@ -36,6 +43,7 @@ If you have have multiple deployments in your `.kubes/resources` then the comman
|
|
36
43
|
[--compile], [--no-compile] # whether or not to compile the .kube/resources
|
37
44
|
# Default: true
|
38
45
|
n, [--name=NAME] # deployment name to use. IE: demo-web
|
46
|
+
c, [--container=CONTAINER] # Container name. If omitted, the first container in the pod will be chosen
|
39
47
|
[--verbose], [--no-verbose]
|
40
48
|
[--noop], [--no-noop]
|
41
49
|
```
|