kubes 0.6.1 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gcloudignore +22 -0
  3. data/.gitignore +1 -1
  4. data/CHANGELOG.md +15 -0
  5. data/Dockerfile +6 -6
  6. data/Dockerfile.alpine +20 -0
  7. data/README.md +0 -7
  8. data/docker/install/docker.sh +8 -0
  9. data/docker/install/gcloud.sh +18 -0
  10. data/docker/install/kubectl.sh +4 -0
  11. data/docs/_docs/config/hooks/kubes.md +1 -0
  12. data/docs/_docs/config/reference.md +1 -0
  13. data/docs/_docs/dsl/multiple-resources.md +3 -1
  14. data/docs/_docs/helpers.md +1 -13
  15. data/docs/_docs/helpers/aws/secrets.md +14 -2
  16. data/docs/_docs/helpers/aws/ssm.md +2 -2
  17. data/docs/_docs/helpers/custom.md +1 -0
  18. data/docs/_docs/helpers/google.md +19 -1
  19. data/docs/_docs/helpers/google/gke.md +92 -0
  20. data/docs/_docs/helpers/google/secrets.md +29 -1
  21. data/docs/_docs/layering/mix.md +1 -1
  22. data/docs/_docs/plugins.md +12 -0
  23. data/docs/_docs/plugins/aws.md +21 -0
  24. data/docs/_docs/plugins/google.md +22 -0
  25. data/docs/_docs/variables.md +1 -12
  26. data/docs/_docs/variables/advanced.md +2 -0
  27. data/docs/_docs/variables/basic.md +2 -0
  28. data/docs/_docs/vs/custom.md +3 -3
  29. data/docs/_includes/helpers/generator.md +13 -0
  30. data/docs/_includes/layering/layers.md +9 -11
  31. data/docs/_includes/plugins/gke-config.md +6 -0
  32. data/docs/_includes/sidebar.html +6 -0
  33. data/docs/_includes/variables/generator.md +23 -0
  34. data/kubes.gemspec +2 -2
  35. data/lib/kubes/auth.rb +9 -0
  36. data/lib/kubes/cli/apply.rb +0 -1
  37. data/lib/kubes/cli/prune.rb +4 -2
  38. data/lib/kubes/compiler/shared/plugin_helpers.rb +1 -1
  39. data/lib/kubes/config.rb +14 -0
  40. data/lib/kubes/hooks/builder.rb +20 -5
  41. data/lib/kubes/hooks/concern.rb +1 -1
  42. data/lib/kubes/kubectl/batch.rb +7 -0
  43. data/lib/kubes/version.rb +1 -1
  44. metadata +18 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68eb4fe2f49953dd133ed6d5baece88f47ff0078162576a0cc41238bf571b6fc
4
- data.tar.gz: 29821780f33d80b168f20d2f42e38074776230ed7cde8fc474d947c70bc6f099
3
+ metadata.gz: bf9376a1ec924961f11b70829fc8562f362ba6b21a3c143de19fdc3e99d63772
4
+ data.tar.gz: 0ea939256551c293aeb290d868fbbf12d169496ff3ed4974a80ce8dcea2e08cd
5
5
  SHA512:
6
- metadata.gz: 0c6de28da8411c1a62cc6fb310e0057aaae12d4e219c14399002b81731f5ecc3f20b596247a367068a5c83695f7d25ffdb0583004e8e7b3812eaf57646b86709
7
- data.tar.gz: 828253eb8e9943dd39218de79a73cb6ae2c6652b4f6e88e4aebe1b1ab5b6be44ff9aee199cee9208a8abc5f038608c5ad1ead7836799c57813df37f49ed5e0db
6
+ metadata.gz: df78700750ea52afea9ced7e8467fe6a628f934819d84887ac8d409435755a63b1e68c62ad4cb197b24ba70b751313e926dd4f8058de5b20665e3c598e46b289
7
+ data.tar.gz: ff36556409060899721059e38d095bbaa60d4540e2cfc5e229e6fb177fc947e21bb6d5a40d5daf4909b9e58b396b9a7bda28124a190df691ae7e9d3e14e074d9
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ /.bundle
4
+ /.config
5
+ /.yardoc
6
+ /_yardoc
7
+ /coverage
8
+ /doc/
9
+ /Gemfile.lock
10
+ /InstalledFiles
11
+ /lib/bundler/man
12
+ /pkg
13
+ /rdoc
14
+ /spec/reports
15
+ /test/tmp
16
+ /test/version_tmp
17
+ /tmp
18
+
19
+ .git
20
+ pkg
21
+ docs
22
+ spec
data/.gitignore CHANGED
@@ -14,4 +14,4 @@
14
14
  /spec/reports
15
15
  /test/tmp
16
16
  /test/version_tmp
17
- /tmp
17
+ /tmp
@@ -3,6 +3,21 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.6.6] - 2020-11-12
7
+ - dependencies version bump: kubes_aws and kubes_google
8
+
9
+ ## [0.6.5] - 2020-11-12
10
+ - [#39](https://github.com/boltops-tools/kubes/pull/39) google secrets fetcher option
11
+
12
+ ## [0.6.4] - 2020-11-11
13
+ - [#38](https://github.com/boltops-tools/kubes/pull/38) fix auto auth for docker login to registry, docs for secret base64, update dependencies
14
+
15
+ ## [0.6.3] - 2020-11-11
16
+ - [#37](https://github.com/boltops-tools/kubes/pull/37) Dockerfile for ci and hook updates
17
+
18
+ ## [0.6.2]
19
+ - [#36](https://github.com/boltops-tools/kubes/pull/36) add plugin hooks support
20
+
6
21
  ## [0.6.1]
7
22
  - update gemspec dependency to plugins that provide the secrets helpers
8
23
 
data/Dockerfile CHANGED
@@ -1,10 +1,10 @@
1
- FROM ruby:2.7-alpine
1
+ FROM ruby:2.7
2
2
 
3
- RUN apk add --no-cache docker
4
- RUN apk add --no-cache build-base ruby ruby-dev
5
-
6
- RUN wget https://storage.googleapis.com/kubernetes-release/release/v1.18.6/bin/linux/amd64/kubectl
7
- RUN chmod u+x kubectl && mv kubectl /bin/kubectl
3
+ COPY docker docker
4
+ RUN docker/install/docker.sh
5
+ RUN docker/install/gcloud.sh
6
+ ENV PATH=/opt/google/google-cloud-sdk/bin/:$PATH
7
+ RUN docker/install/kubectl.sh
8
8
 
9
9
  WORKDIR /app
10
10
  ADD . /app
@@ -0,0 +1,20 @@
1
+ FROM ruby:2.7-alpine
2
+
3
+ # This Dockerfile is much lighter but won't work with gke whitelisting. Getting this error when the google gke sdk is called:
4
+ #
5
+ # Error loading shared library ld-linux-x86-64.so.2: No such file or directory #986
6
+ #
7
+ # If you don't need gke whitelisting, then this image should work and is lighter.
8
+
9
+ RUN apk add --no-cache docker
10
+ RUN apk add --no-cache build-base ruby ruby-dev
11
+
12
+ RUN wget https://storage.googleapis.com/kubernetes-release/release/v1.19.0/bin/linux/amd64/kubectl
13
+ RUN chmod u+x kubectl && mv kubectl /bin/kubectl
14
+
15
+ WORKDIR /app
16
+ ADD . /app
17
+ RUN bundle install
18
+ RUN rake install
19
+
20
+ ENTRYPOINT ["/usr/local/bundle/bin/kubes"]
data/README.md CHANGED
@@ -18,13 +18,6 @@ Kubes will:
18
18
  2. Compile Kubernetes YAML files from YAML/ERB or a DSL and adjusts the Docker build image
19
19
  3. Deploy via kubectl apply on the compiled Kubernetes YAML files
20
20
 
21
- Features:
22
-
23
- * Automation: [Builds the Docker image](docs/docker.md) and updates the compiled YAML files
24
- * Syntactic Sugar: Use an optional [ERB/YAML](docs/yaml.md) or [DSL](docs/dsl.md) to write your Kubernetes YAML files. You can use a mix of DSL and YAML definitions in the `.kubes/resources` folder.
25
- * Layering: Use the same Kubernetes YAML to build multiple environments like dev and prod with [layering](docs/layering.md).
26
- * CLI Customizations: You can customize the [cli args](docs/kubectl.md). You can also run hooks before and after kubectl commands.
27
-
28
21
  ## Usage
29
22
 
30
23
  kubes init # creates .kubes structure
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+
3
+ apt-get update
4
+ apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y
5
+ curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
6
+ add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
7
+ apt-get update
8
+ apt-get install docker-ce docker-ce-cli containerd.io -y
@@ -0,0 +1,18 @@
1
+ #!/bin/bash -eu
2
+
3
+ [ -e /opt/google ] && exit
4
+
5
+ mkdir -p /opt/google
6
+
7
+ cd /opt/google
8
+ wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-318.0.0-linux-x86_64.tar.gz
9
+ tar zxf google-cloud-sdk*.tar.gz
10
+ rm -f google-cloud-sdk*.tar.gz
11
+
12
+ /opt/google/google-cloud-sdk/install.sh -q
13
+
14
+ cat << FOE >> ~/.bash_profile
15
+
16
+ source /opt/google/google-cloud-sdk/completion.bash.inc
17
+ source /opt/google/google-cloud-sdk/path.bash.inc
18
+ FOE
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ wget https://storage.googleapis.com/kubernetes-release/release/v1.19.0/bin/linux/amd64/kubectl
4
+ chmod u+x kubectl && mv kubectl /bin/kubectl
@@ -13,6 +13,7 @@ Hook | Description
13
13
  compile | When kubes compiles the `.kubes/resources` to `.kubes/output`.
14
14
  apply | When kubes runs all the `kubectl apply` commands.
15
15
  delete | When kubes runs all the `kubectl delete` commands.
16
+ prune | When kubes prunes. IE: To clean old secrets.
16
17
 
17
18
  ## Lifecycle At Kubes Level
18
19
 
@@ -16,6 +16,7 @@ kubectl.order.roles | Change ordering for Kubes Roles. | See [source code](https
16
16
  logger | Logger object | Logger.new($stdout)
17
17
  logger.level | Logger level. Can also be set with `KUBES_LOG_LEVEL` env var | info
18
18
  repo | The Docker repo to use. Required to be set. | nil
19
+ repo_auto_auth | Whether or not to try to auth authorize docker repo registry if not yet logged in. Can also be set with env var `KUBES_REPO_AUTO_AUTO` | true
19
20
  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. | []
20
21
  state.docker_image_path | Where to store the state file with the last build Docker image. | .kubes/state/docker_image.txt
21
22
  suffix_hash | Whether or not to append suffix hash to ConfigMap and Secret | true
@@ -39,7 +39,9 @@ Using multiple files is the general recommended approach.
39
39
 
40
40
  ## Multiple Resources: Block Form
41
41
 
42
- You can also use a block form to create multiple resources. You name the resource files with plural names. An example helps explain:
42
+ You can also use a block form to create multiple resources. The multiple resources block form is an experimental feature.
43
+
44
+ You name the resource files with plural names. An example helps explain:
43
45
 
44
46
  .kubes
45
47
  └── resources
@@ -26,16 +26,4 @@ There are also provider-specific helpers:
26
26
  * [AWS Helpers]({% link _docs/helpers/aws.md %})
27
27
  * [Google Helpers]({% link _docs/helpers/google.md %})
28
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
- ```
29
+ {% include helpers/generator.md %}
@@ -45,11 +45,23 @@ data:
45
45
  USER: dGVzdDIK
46
46
  ```
47
47
 
48
- The values are automatically base64 encoded.
48
+ By default, the values are automatically base64 encoded.
49
49
 
50
50
  ## Base64 Option
51
51
 
52
- The value is automatically base64 encoded. You can set the `base64` option to turn on and off the automated base64 encoding.
52
+ By default, the values are automatically base64 encoded. You can change the default behavior with a config option.
53
+
54
+ .kubes/config.rb
55
+
56
+ ```ruby
57
+ KubesAws.configure do |config|
58
+ config.secrets.base64 = false
59
+ end
60
+ ```
61
+
62
+ Note: The use of `KubesAws.configure` instead of `Kubes.configure` here.
63
+
64
+ You can also set the `base64` option to turn on and off the automated base64 encoding on a per secret basis.
53
65
 
54
66
  ```ruby
55
67
  aws_secret("demo-#{Kubes.env}-USER", base64: true) # default is base64=true
@@ -44,11 +44,11 @@ data:
44
44
  USER: dGVzdDIK
45
45
  ```
46
46
 
47
- The values are automatically base64 encoded.
47
+ The values are base64 encoded based on the SSM parameter type. When the type is a `SecureString`, Kubes base64 encodes it. Other types are not base64 encoded. You can override this behavior with the base64 option, described next.
48
48
 
49
49
  ## Base64 Option
50
50
 
51
- The value is automatically base64 encoded. You can set the `base64` option to turn on and off the automated base64 encoding.
51
+ The value is automatically base64 encoded based on whether or not the SSM parameter type is a `SecureString`. You can explicitly the `base64` option if needed though. Example:
52
52
 
53
53
  ```ruby
54
54
  aws_ssm("/demo/#{Kubes.env}/USER", base64: true) # default is base64=true
@@ -38,3 +38,4 @@ data:
38
38
  DATABASE_ENDPOINT: <%= database_endpoint %>
39
39
  ```
40
40
 
41
+ {% include helpers/generator.md %}
@@ -14,4 +14,22 @@ List of Google helpers:
14
14
  * By default, `KubeGoogle.logger = Kubes.logger`. This means, you can set `logger.level = "debug"` in `.kubes/config.rb` to see more details.
15
15
  * The `gcloud` cli is used to create IAM roles. So `gcloud` is required.
16
16
  * Note: Would like to use the google sdk, but it wasn't obvious how to do so. PRs are welcomed.
17
- * The Google helpers are provided by the [boltops-tools/kubes_google](https://github.com/boltops-tools/kubes_google) library.
17
+ * The Google helpers are provided by the [boltops-tools/kubes_google](https://github.com/boltops-tools/kubes_google) library.
18
+
19
+ ## Authentication
20
+
21
+ Most of the Google helpers use the SDK to call the Google Cloud API. As such, it needs to be authenticated. You can do this by setting the `GOOGLE_APPLICATION_CREDENTIALS` environment variable point to the path with a service account credentials file. IE:
22
+
23
+ .bash_profile
24
+
25
+ export GOOGLE_APPLICATION_CREDENTIALS=~/.gcp/service-account.json
26
+
27
+ If you would like to use a user IAM credentials instead of a service account. You can also run use [application-default login](https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login). Example:
28
+
29
+ gcloud auth application-default login
30
+
31
+ This generates an Application Default Credentials at `.config/gcloud/application_default_credentials.json`. Note, make sure that `GOOGLE_APPLICATION_CREDENTIALS` is not set or else the `application_default_credentials.json` will not be used. Also, the google sdk prints a warning to use a service account instead. You can suppress that warning with this:
32
+
33
+ .bash_profile
34
+
35
+ export GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS=1
@@ -0,0 +1,92 @@
1
+ ---
2
+ title: GKE Whitelisting
3
+ nav_text: GKE
4
+ categories: helpers-google
5
+ ---
6
+
7
+ This page covers how to enable GKE IP Whitelisting. This feature is useful for deploying from a CloudBuild with GKE Private Clusters.
8
+
9
+ GKE Private Clusters whitelist and only allow authorized IPs to communicate with the Kubernetes control plane. An issue with CloudBuild is that the IP address is not well-known. Google creates a VM to run the CI scripts and throws it away when finished. Kubes can detect the IP of the CloudBuild machine, add it to the cluster, deploy, and remove the IP afterward.
10
+
11
+ ## Setup
12
+
13
+ To enable the GKE IP whitelisting feature, it's a few simple configurations:
14
+
15
+ .kubes/config/env/dev.rb
16
+
17
+ ```ruby
18
+ KubesGoogle.configure do |config|
19
+ config.gke.cluster_name = "dev-cluster"
20
+ config.gke.google_region = ENV['GOOGLE_REGION']
21
+ config.gke.google_project = ENV['GOOGLE_PROJECT']
22
+ config.gke.enable_get_credentials = true # enable hook to call: gcloud container clusters get-credentials
23
+ end
24
+ ```
25
+
26
+ Note: The use of `KubesGoogle.configure` instead of `Kubes.configure` here.
27
+
28
+ This enables `kubes apply` before and after hooks to add and remove the current machine IP.
29
+
30
+ ## Options
31
+
32
+ Here are the `config.gke` settings:
33
+
34
+ Name | Description | Default
35
+ ---|---|---
36
+ {% include plugins/gke-config.md %}
37
+
38
+ ## Build Docker Image
39
+
40
+ To build kubes as a Docker image entrypoint for [Google CloudBuild Custom Builder](https://cloud.google.com/cloud-build/docs/configuring-builds/use-community-and-custom-builders).
41
+
42
+ git clone http://github.com/boltops-tools/kubes
43
+ cd kubes
44
+ gcloud builds submit --tag gcr.io/$GOOGLE_PROJECT/kubes
45
+
46
+ Be sure to set GOOGLE_PROJECT to your own project id.
47
+
48
+ ## Example Codebuild YAML
49
+
50
+ cloudbuild.yaml:
51
+
52
+ ```yaml
53
+ steps:
54
+ - name: 'gcr.io/$PROJECT_ID/kubes'
55
+ args: ['deploy']
56
+ env:
57
+ - 'DOCKER_REPO=gcr.io/$PROJECT_ID/demo'
58
+ - 'GOOGLE_PROJECT=$PROJECT_ID' # .kubes/config.rb: config.repo
59
+ - 'KUBES_ENV=$_KUBES_ENV'
60
+ - 'KUBES_EXTRA=$_KUBES_EXTRA'
61
+ - 'KUBES_REPO_AUTO_AUTH=0'
62
+
63
+ substitutions:
64
+ _KUBES_ENV: dev
65
+ _KUBES_EXTRA: ''
66
+ options:
67
+ substitution_option: 'ALLOW_LOOSE'
68
+ ```
69
+
70
+ Make sure to replace the substitutions with your own values. IE: _KUBES_ENV, etc.
71
+
72
+ ## Google CloudBuild IAM Permissions
73
+
74
+ In order to update the GKE cluster master authorized IP and whitelist the CloudBuild IP, you'll need to allow the CloudBuild IAM role permissions.
75
+
76
+ Important: The "Kubernetes Engine Developer" that is available in the Cloud Build Settings page as described in [Configuring access for Cloud Build Service Account](https://cloud.google.com/cloud-build/docs/securing-builds/configure-access-for-cloud-build-service-account) does not suffice. You'll need to add the "Kubernetes Engine Cluster Admin" role. Here are the steps:
77
+
78
+ 1. Go to the Google IAM Console and search "cloudbuild"
79
+ 2. Click "Edit Member"
80
+ 3. Add the "Kubernetes Engine Cluster Admin" role
81
+
82
+ ## Run CloudBuild
83
+
84
+ Run cloudbuild to deploy the dev env:
85
+
86
+ gcloud builds submit --config cloudbuild.yaml
87
+
88
+ To deploy the prod env:
89
+
90
+ gcloud builds submit --config cloudbuild.yaml --substitutions _KUBES_ENV=prod
91
+
92
+ See [gcloud builds submit](https://cloud.google.com/sdk/gcloud/reference/builds/submit) reference docs for more options.
@@ -57,7 +57,19 @@ GOOGLE_PROJECT | Google project id. This is required.
57
57
 
58
58
  ## Base64 Option
59
59
 
60
- The value is automatically base64 encoded. You can set the `base64` option to turn on and off the automated base64 encoding.
60
+ By default, the values are automatically base64 encoded. You can change the default behavior with a config option.
61
+
62
+ .kubes/config.rb
63
+
64
+ ```ruby
65
+ KubesGoogle.configure do |config|
66
+ config.secrets.base64 = true
67
+ end
68
+ ```
69
+
70
+ Note: The use of `KubesGoogle.configure` instead of `Kubes.configure` here.
71
+
72
+ You can also set the `base64` option to turn on and off the automated base64 encoding on a per secret basis.
61
73
 
62
74
  ```ruby
63
75
  google_secret("demo-#{Kubes.env}-USER", base64: true) # default is base64=true
@@ -65,3 +77,19 @@ google_secret("demo-#{Kubes.env}-PASS", base64: false)
65
77
  ```
66
78
 
67
79
  {% include helpers/base64.md %}
80
+
81
+ ## Fetcher Strategy
82
+
83
+ Some systems configured with a VPN seem to have issues with the Google secrets SDK. You may see an error:
84
+
85
+ Handshake failed with fatal error SSL_ERROR_SSL: error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER.
86
+
87
+ As a workaround to this error, you can use the `gcloud` instead of the default `sdk` fetcher strategy. To configure it:
88
+
89
+ .kubes/config.rb
90
+
91
+ ```ruby
92
+ KubesGoogle.configure do |config|
93
+ config.secrets.fetcher = "gcloud"
94
+ end
95
+ ```
@@ -70,7 +70,7 @@ spec:
70
70
 
71
71
  ## Output
72
72
 
73
- The result is the merge layered files.
73
+ The result is the merged layered files.
74
74
 
75
75
  ```yaml
76
76
  metadata:
@@ -0,0 +1,12 @@
1
+ ---
2
+ title: Kubes Plugins
3
+ ---
4
+
5
+ Kubes makes it easier to work with Kubernetes by automating the deployment workflow. Many of the conveniences it adds is done with plugins. For example, `aws_secret`, `aws_ssm`, `google_secret` are implemented with Cloud Provider specific Kubes plugins.
6
+
7
+ ## Baseline Plugins
8
+
9
+ The baseline plugins that currently ship with Kubes are:
10
+
11
+ * [kubes_aws]({% link _docs/plugins/aws.md %})
12
+ * [kubes_google]({% link _docs/plugins/google.md %})
@@ -0,0 +1,21 @@
1
+ ---
2
+ title: AWS Kubes Plugin
3
+ ---
4
+
5
+ The AWS Kubes Plugin adds support helpers like `aws_secret`. You can configure it's behavior. Example:
6
+
7
+ .kubes/config.rb
8
+
9
+ ```ruby
10
+ KubesAws.configure do |config|
11
+ config.secrets.base64 = false
12
+ end
13
+ ```
14
+
15
+ ## Options Reference Table
16
+
17
+ Here's a table with the options:
18
+
19
+ Name | Description | Default
20
+ ---|---|---
21
+ secrets.base64 | Whether or not to automatically base64 encoded values returned by the `aws_secret` helper. | true
@@ -0,0 +1,22 @@
1
+ ---
2
+ title: Google Kubes Plugin
3
+ ---
4
+
5
+ The Google Kubes Plugin adds support helpers like `google_secret`. You can configure it's behavior. Example:
6
+
7
+ .kubes/config.rb
8
+
9
+ ```ruby
10
+ KubesGoogle.configure do |config|
11
+ config.secrets.base64 = true
12
+ end
13
+ ```
14
+
15
+ ## Options Reference Table
16
+
17
+ Here's a table with the options:
18
+
19
+ Name | Description | Default
20
+ ---|---|---
21
+ secrets.base64 | Whether or not to automatically base64 encoded values returned by the `google_secret` helper. | true
22
+ {% include plugins/gke-config.md %}
@@ -9,15 +9,4 @@ You can set variables to be made available to the templates. Generally, it is re
9
9
  * [{{ doc.title }}]({{ doc.url }})
10
10
  {% endfor %}
11
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
- ```
12
+ {% include variables/generator.md %}
@@ -60,3 +60,5 @@ base/KIND/ENV.rb | base/deployment/dev.rb
60
60
  ROLE/KIND.rb | web/deployment.rb
61
61
  ROLE/KIND/base.rb | web/deployment/base.rb
62
62
  ROLE/KIND/ENV.rb | web/deployment/dev.rb
63
+
64
+ {% include variables/generator.md %}
@@ -135,3 +135,5 @@ spec:
135
135
  apiVersion: apps/v1
136
136
  kind: Deployment
137
137
  ```
138
+
139
+ {% include variables/generator.md %}
@@ -4,7 +4,7 @@ nav_text: Custom Solutions
4
4
  categories: vs
5
5
  ---
6
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.
7
+ Kubernetes provides a great platform to run and manage Docker containers. The `kubectl` command is usually how you interact with a Kubernetes cluster. It does its job well and is quite a powerful tool.
8
8
 
9
9
  {% include vs/article.md %}
10
10
 
@@ -51,7 +51,7 @@ We've duplicated `service.yaml` and `deployment.yaml`, though. Instead, it'll be
51
51
 
52
52
  ## PreBuilt Docker Image
53
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.
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 performs these additional steps and then glue things together.
55
55
 
56
56
  ## Kubernetes Resources Galore
57
57
 
@@ -82,7 +82,7 @@ The same code is used to create different environments. Kubes achieves this with
82
82
 
83
83
  ## Hooks
84
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:
85
+ Kubes support a variety of hooks run scripts at any part of the `kubectl` commands. This allows you to customize and add app-specific logic needed. Example:
86
86
 
87
87
  .kubes/config/hooks/kubectl.rb
88
88
 
@@ -0,0 +1,13 @@
1
+ ## Generator
2
+
3
+ To help you get started quickly, you can generate starter helper code.
4
+
5
+ $ kubes new helper custom
6
+ create .kubes/helpers/custom_helper.rb
7
+
8
+ .kubes/helpers/custom_helper.rb
9
+
10
+ ```ruby
11
+ module CustomHelper
12
+ end
13
+ ```
@@ -48,15 +48,13 @@ ROLE/KIND/ENV.{{ include.ext }} | web/deployment/dev.{{ include.ext }}
48
48
  2. Then you can define the core of your resource definition in the `ROLE/KIND.{{ include.ext }}`. Example: `web/deployment.{{ include.ext }}`
49
49
  3. Finally, you can provide environment-specific overrides in the `ROLE/KIND/ENV.{{ include.ext }}`. Example: `web/deployment/dev.{{ include.ext }}`.
50
50
 
51
- Here's an example of the structure:
51
+ Here's a concrete example of layering with the deployment resource kind:
52
52
 
53
- .kubes/resources/
54
- ├── base
55
- │ ├── all.{{ include.ext }}
56
- │ └── deployment.{{ include.ext }}
57
- └── web
58
- ├── deployment
59
- │ ├── dev.{{ include.ext }}
60
- │ └── prod.{{ include.ext }}
61
- ├── deployment.{{ include.ext }}
62
- └── service.{{ include.ext }}
53
+ .kubes/resources/base/all.{{ include.ext }}
54
+ .kubes/resources/base/deployment.{{ include.ext }}
55
+ .kubes/resources/web/deployment.{{ include.ext }}
56
+ .kubes/resources/web/deployment/dev.{{ include.ext }}
57
+
58
+ All of these files get layered and merged together to produce a resulting deployment.{{ include.ext }}
59
+
60
+ .kubes/output/web/deployment.{{ include.ext }}
@@ -0,0 +1,6 @@
1
+ gke.cluster_name | GKE cluster name. This is required when using the [GKE whitelisting feature]({% link _docs/helpers/google/gke.md %}). | nil
2
+ gke.enable_get_credentials | Whether or not to run the hook that calls `gcloud container clusters get-credentials`. This spares you from having to call it manually. | false
3
+ gke.enable_hooks | This will be true when the cluster_name is set. So there's no need to set it. The option provides a quick way to override and disable running the hooks. | true
4
+ gke.google_project | Google project. Can also be set with the env var `GOOGLE_PROJECT`. `GOOGLE_PROJECT` takes precedence. | nil
5
+ gke.google_region | Google region cluster is in. Can also be set with the env var `GOOGLE_REGION`. `GOOGLE_REGION` takes precedence. | nil
6
+ gke.whitelist_ip | Explicit IP to whitelist. By default the IP address of the current machine is automatically detected and used. | nil
@@ -173,6 +173,12 @@
173
173
  <li><a href="{% link _docs/extra-env/dsl.md %}">DSL</a></li>
174
174
  </ul>
175
175
  </li>
176
+ <li><a href="{% link _docs/plugins.md %}">Plugins</a>
177
+ <ul>
178
+ <li><a href="{% link _docs/plugins/aws.md %}">AWS</a></li>
179
+ <li><a href="{% link _docs/plugins/google.md %}">Google</a></li>
180
+ </ul>
181
+ </li>
176
182
  <li>Misc
177
183
  <ul>
178
184
  <li><a href="{% link _docs/misc/kustomize.md %}">Kustomize Support</a></li>
@@ -0,0 +1,23 @@
1
+ ## Generator
2
+
3
+ To help you get started quickly, you can generate starter variable code.
4
+
5
+ $ kubes new variable
6
+ create .kubes/variables/dev.rb
7
+
8
+ .kubes/variables/dev.rb
9
+
10
+ ```ruby
11
+ @example = "dev-value"
12
+ ```
13
+
14
+ To create the prod variables, set `KUBES_ENV=prod`.
15
+
16
+ $ KUBES_ENV=prod kubes new variable
17
+ create .kubes/variables/prod.rb
18
+
19
+ .kubes/variables/prod.rb
20
+
21
+ ```ruby
22
+ @example = "prod-value"
23
+ ```
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "zeitwerk"
30
30
 
31
31
  # core helper libs
32
- spec.add_dependency "kubes_aws", "~> 0.2.0"
33
- spec.add_dependency "kubes_google", "~> 0.2.0"
32
+ spec.add_dependency "kubes_aws", "~> 0.3.1"
33
+ spec.add_dependency "kubes_google", "~> 0.3.3"
34
34
 
35
35
  spec.add_development_dependency "bundler"
36
36
  spec.add_development_dependency "byebug"
@@ -13,6 +13,7 @@ module Kubes
13
13
  # Currently only support ECR and GCR
14
14
  # TODO: consider moving this to plugin gems
15
15
  def strategy_class
16
+ return unless auth?
16
17
  case @image
17
18
  when /\.amazonaws\.com/ # IE: 112233445566.dkr.ecr.us-west-2.amazonaws.com/demo/sinatra
18
19
  Ecr
@@ -20,5 +21,13 @@ module Kubes
20
21
  Gcr
21
22
  end
22
23
  end
24
+
25
+ def auth?
26
+ if ENV['KUBES_REPO_AUTO_AUTH'].nil?
27
+ Kubes.config.repo_auto_auth
28
+ else
29
+ %w[1 true].include?(ENV['KUBES_REPO_AUTO_AUTH'])
30
+ end
31
+ end
23
32
  end
24
33
  end
@@ -4,7 +4,6 @@ class Kubes::CLI
4
4
  compile
5
5
  logger.info "Deploying kubes resources"
6
6
  Kubes::Kubectl::Dispatcher.new(:apply, @options).run
7
- Prune.new(@options.merge(yes: true, quiet: true)).run if Kubes.config.auto_prune # prune old secrets and config maps
8
7
  end
9
8
  end
10
9
  end
@@ -2,15 +2,17 @@ class Kubes::CLI
2
2
  class Prune < Base
3
3
  KINDS = %w[ConfigMap Secret]
4
4
  extend Memoist
5
+ include Kubes::Hooks::Concern
5
6
  include Kubes::Util::Sure
6
7
 
7
8
  def run
8
9
  return unless anything_to_prune?
9
10
  logger.info "Pruning old resources: #{KINDS.join(', ')}"
10
-
11
11
  perform(preview: true) unless @options[:yes]
12
12
  sure?("This will prune/delete resources. Are you sure?")
13
- perform(preview: false)
13
+ run_hooks("kubes.rb", name: "prune") do
14
+ perform(preview: false)
15
+ end
14
16
  end
15
17
 
16
18
  def fetcher
@@ -5,7 +5,7 @@ module Kubes::Compiler::Shared
5
5
  def load_plugin_helpers
6
6
  return if @@plugin_helpers_loaded
7
7
  Kubes::Plugin.plugins.each do |klass|
8
- helpers_class = "#{klass}::Helpers".constantize
8
+ helpers_class = "#{klass}::Helpers".constantize # IE: KubesAws::Helpers
9
9
  self.class.send :include, helpers_class
10
10
  end
11
11
  @@plugin_helpers_loaded = true
@@ -31,6 +31,7 @@ module Kubes
31
31
  config.kubectl.order.kinds = kind_order
32
32
 
33
33
  config.repo = nil # expected to be set by .kubes/config.rb
34
+ config.repo_auto_auth = true
34
35
 
35
36
  config.logger = Logger.new($stderr)
36
37
  config.logger.level = ENV['KUBES_LOG_LEVEL'] || :info
@@ -81,9 +82,22 @@ module Kubes
81
82
  yield(@config)
82
83
  end
83
84
 
85
+ # Load configs example:
86
+ #
87
+ # .kubes/config.rb
88
+ # .kubes/config/env/dev.rb
89
+ # .kubes/config/plugins/google.rb
90
+ # .kubes/config/plugins/google/dev.rb
91
+ #
84
92
  def load_configs
85
93
  evaluate_file(".kubes/config.rb")
86
94
  evaluate_file(".kubes/config/env/#{Kubes.env}.rb")
95
+ Kubes::Plugin.plugins.each do |klass|
96
+ # klass: IE: KubesAws, KubesGoogle
97
+ name = klass.to_s.underscore.sub('kubes_','') # kubes_google => google
98
+ evaluate_file(".kubes/config/plugins/#{name}.rb")
99
+ evaluate_file(".kubes/config/plugins/#{name}/#{Kubes.env}.rb")
100
+ end
87
101
  end
88
102
  end
89
103
  end
@@ -6,20 +6,36 @@ module Kubes::Hooks
6
6
  include Kubes::Logging
7
7
 
8
8
  attr_accessor :name
9
- def initialize(dsl_file, options={})
10
- @dsl_file, @options = dsl_file, options # IE: .kubes/config/hooks/kubectl.rb
9
+ def initialize(file, options={})
10
+ @file, @options = file, options # IE: .kubes/config/hooks/kubectl.rb
11
+ @dsl_file = "#{Kubes.root}/.kubes/config/hooks/#{@file}"
11
12
  @output_file = options[:file] # IE: .kubes/output/web/service.yaml
12
13
  @name = options[:name].to_s
13
14
  @hooks = {before: {}, after: {}}
14
15
  end
15
16
 
16
17
  def build
17
- return @hooks unless File.exist?(@dsl_file)
18
18
  evaluate_file(@dsl_file)
19
+ evaluate_plugin_hooks
19
20
  @hooks.deep_stringify_keys!
20
21
  end
21
22
  memoize :build
22
23
 
24
+ def evaluate_plugin_hooks
25
+ Kubes::Plugin.plugins.each do |klass|
26
+ hooks_class = hooks_class(klass)
27
+ next unless hooks_class
28
+ plugin_hooks = hooks_class.new
29
+ path = "#{plugin_hooks.path}/#{@file}"
30
+ evaluate_file(path)
31
+ end
32
+ end
33
+
34
+ def hooks_class(klass)
35
+ "#{klass}::Hooks".constantize # IE: KubesGoogle::Hooks
36
+ rescue NameError
37
+ end
38
+
23
39
  def run_hooks
24
40
  build
25
41
  run_each_hook("before")
@@ -42,8 +58,7 @@ module Kubes::Hooks
42
58
  id = "#{command} #{type} #{@name}"
43
59
  on = " on: #{hook["on"]}" if hook["on"]
44
60
  label = " label: #{hook["label"]}" if hook["label"]
45
- logger.info "Running #{id} hook.#{on}#{label}"
46
- logger.debug "Hook options: #{hook}"
61
+ logger.info "Hook: Running #{id} hook.#{on}#{label}"
47
62
  Runner.new(hook).run
48
63
  end
49
64
 
@@ -2,7 +2,7 @@ module Kubes::Hooks
2
2
  module Concern
3
3
  # options example: {:name=>"apply", :file=>".kubes/output/web/service.yaml"}
4
4
  def run_hooks(file, options={}, &block)
5
- hooks = Kubes::Hooks::Builder.new("#{Kubes.root}/.kubes/config/hooks/#{file}", options)
5
+ hooks = Kubes::Hooks::Builder.new(file, options)
6
6
  hooks.build # build hooks
7
7
  hooks.run_hooks(&block)
8
8
  end
@@ -22,10 +22,17 @@ class Kubes::Kubectl
22
22
  Kubes::Kubectl.run(@name, @options.merge(file: file))
23
23
  end
24
24
  end
25
+ prune # important to call within run_hooks for case of GKE IP whitelisting
25
26
  end
26
27
  end
27
28
  end
28
29
 
30
+ def prune
31
+ return unless @name == "apply" # only run for apply
32
+ return unless Kubes.config.auto_prune # prune old secrets and config maps
33
+ Kubes::CLI::Prune.new(@options.merge(yes: true, quiet: true)).run
34
+ end
35
+
29
36
  def switch_context(&block)
30
37
  kubectl = Kubes.config.kubectl
31
38
  context = kubectl.context
@@ -1,3 +1,3 @@
1
1
  module Kubes
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-09 00:00:00.000000000 Z
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -142,28 +142,28 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 0.2.0
145
+ version: 0.3.1
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 0.2.0
152
+ version: 0.3.1
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: kubes_google
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 0.2.0
159
+ version: 0.3.3
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 0.2.0
166
+ version: 0.3.3
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: bundler
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -243,15 +243,20 @@ extensions: []
243
243
  extra_rdoc_files: []
244
244
  files:
245
245
  - ".dockerignore"
246
+ - ".gcloudignore"
246
247
  - ".gitignore"
247
248
  - ".rspec"
248
249
  - CHANGELOG.md
249
250
  - Dockerfile
251
+ - Dockerfile.alpine
250
252
  - Gemfile
251
253
  - Guardfile
252
254
  - LICENSE.txt
253
255
  - README.md
254
256
  - Rakefile
257
+ - docker/install/docker.sh
258
+ - docker/install/gcloud.sh
259
+ - docker/install/kubectl.sh
255
260
  - docs/.gitignore
256
261
  - docs/CNAME
257
262
  - docs/Gemfile
@@ -312,6 +317,7 @@ files:
312
317
  - docs/_docs/helpers/google.md
313
318
  - docs/_docs/helpers/google/advanced.md
314
319
  - docs/_docs/helpers/google/advanced/secrets.md
320
+ - docs/_docs/helpers/google/gke.md
315
321
  - docs/_docs/helpers/google/secrets.md
316
322
  - docs/_docs/helpers/google/service-account.md
317
323
  - docs/_docs/intro.md
@@ -356,6 +362,9 @@ files:
356
362
  - docs/_docs/patterns/migrations.md
357
363
  - docs/_docs/patterns/multiple-envs.md
358
364
  - docs/_docs/patterns/secrets.md
365
+ - docs/_docs/plugins.md
366
+ - docs/_docs/plugins/aws.md
367
+ - docs/_docs/plugins/google.md
359
368
  - docs/_docs/resources.md
360
369
  - docs/_docs/resources/base.md
361
370
  - docs/_docs/resources/role.md
@@ -379,6 +388,7 @@ files:
379
388
  - docs/_includes/google_analytics.html
380
389
  - docs/_includes/header.html
381
390
  - docs/_includes/helpers/base64.md
391
+ - docs/_includes/helpers/generator.md
382
392
  - docs/_includes/intro/features.md
383
393
  - docs/_includes/intro/install.md
384
394
  - docs/_includes/js.html
@@ -390,8 +400,10 @@ files:
390
400
  - docs/_includes/learn/repos.md
391
401
  - docs/_includes/learn/review.md
392
402
  - docs/_includes/learn/start.md
403
+ - docs/_includes/plugins/gke-config.md
393
404
  - docs/_includes/reference.md
394
405
  - docs/_includes/sidebar.html
406
+ - docs/_includes/variables/generator.md
395
407
  - docs/_includes/vs/article.md
396
408
  - docs/_includes/vs/kubes/layering.md
397
409
  - docs/_includes/vs/kubes/structure.md