kubernetes_helper 1.9.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +71 -2
- data/lib/kubernetes_helper/version.rb +1 -1
- data/lib/templates/_replicas.yml +1 -1
- data/lib/templates/certificate.yml +1 -1
- data/lib/templates/deployment.yml +6 -1
- data/lib/templates/ingress.yml +2 -2
- data/lib/templates/service.yml +2 -2
- data/lib/templates/settings.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad11b73ac23d45b86c9b5789ae815af2ee565d6360462368e96c4b15dfcc3301
|
4
|
+
data.tar.gz: 61df31315a5b137c9e1c4575002b875f87175d72d5319cf0e1439d8c01afaee6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1a177f81e8bf2a9337d233369c39dd7cc42e2baf0c7dca7fdba25984d86014837db2207bcab10a1b9f8b8bc2060b55dee8c0dc0054074ac4846592856c8d778
|
7
|
+
data.tar.gz: 8be87c0b86cc7e4a7711d20d6360e96d5b99d7655ea3a3bed0a8291dec59cc552a9a326911355d2427f0e5548c0976045d7d28204af1c9dcee2c5fd1bc2af1f9
|
data/README.md
CHANGED
@@ -9,7 +9,15 @@ cd my_app/
|
|
9
9
|
gem install kubernetes_helper -v '~> 1.0'
|
10
10
|
kubernetes_helper generate_templates
|
11
11
|
```
|
12
|
-
Note: Requires ruby 1.7+
|
12
|
+
Note: Requires ruby 1.7+
|
13
|
+
|
14
|
+
## Configuration
|
15
|
+
- Edit `.kubernetes/settings.rb` and enter or replace all settings with the valid ones
|
16
|
+
- For special applications where default configurations are not enough, you can do the following:
|
17
|
+
- Download the corresponding template from [lib/templates](lib/templates)
|
18
|
+
- Put it inside `.kubernetes` folder
|
19
|
+
- Customize based on your needs (You can add or use your custom variables from `settings.rb`)
|
20
|
+
Note: The local template will be used instead of the default.
|
13
21
|
|
14
22
|
## Deployment
|
15
23
|
Once you generated the basic templates, it comes with the corresponding [readme.md](/lib/templates/README.md) which includes all the steps to deploy your application.
|
@@ -21,7 +29,7 @@ Once you generated the basic templates, it comes with the corresponding [readme.
|
|
21
29
|
- Supports for `- documents` to include multiple documents in a file and share yml variables between them (Sample: `lib/templates/deployment.yml#1`)
|
22
30
|
- Replaces all setting values based on `DEPLOY_ENV`
|
23
31
|
- Supports for secrets auto importer using `import_secrets: ['secrets.yml', '<%=secrets.name%>']` (Sample: `lib/templates/deployment.yml#29`)
|
24
|
-
- Supports for
|
32
|
+
- Supports for sub templates by `include_template 'template_name.yml.erb', { my_local_var: 10 }`
|
25
33
|
Sample: `DEPLOY_ENV=beta kubernetes_helper run_deployment "deployment.yml" "kubectl create"`
|
26
34
|
|
27
35
|
- Run kubernetes commands
|
@@ -44,6 +52,67 @@ Once you generated the basic templates, it comes with the corresponding [readme.
|
|
44
52
|
When performing a script it looks first for file inside .kubernetes folder, if not exist,
|
45
53
|
it looks for the file inside kubernetes_helper template folder.
|
46
54
|
|
55
|
+
## Settings API
|
56
|
+
Below settings are used when running Continuous Deployment
|
57
|
+
- `continuous_deployment.image_name` (String, Optional): Partial docker image url where `:latest` will be automatically added. Sample: `gcr.io/my-account/my_app_name`
|
58
|
+
- `continuous_deployment.image` (String, Optional, is mandatory if `image_name` is empty): Full docker image url. Sample: `gcr.io/my-account/my_app_name:latest`
|
59
|
+
- `continuous_deployment.project_name`: Cloud project name. Sample: `my-project-name`
|
60
|
+
- `continuous_deployment.cluster_name`: Cluster cluster name. Sample: `my-cluster-name`
|
61
|
+
- `continuous_deployment.cluster_region`: Cluster region name. Sample: `europe-west4-a`
|
62
|
+
- `continuous_deployment.docker_build_cmd`: Docker command to build the corresponding image. Sample: `build --target production -f Dockerfile `
|
63
|
+
- `continuous_deployment.update_deployment` (Boolean, default: false): If true permits to re-generate and update the k8s deployment(s) before applying the new version (new docker image)
|
64
|
+
|
65
|
+
Below settings are used when configuring the application in the k8s environment
|
66
|
+
- `deployment.name` (String): Web deployment name (Note: Underscores are not accepted). Sample: `my-app`
|
67
|
+
- `deployment.replicas` (Integer): Quantity of replicas. Sample: `1`
|
68
|
+
- `deployment.replicas_range` (Array<min, max, cpu_percentage>, Optional): Defines the minimum and the maximum number of pods that could automatically be created when `CPUUtilizationPercentage` is above than defined. Sample: `[1, 3, 50]`
|
69
|
+
- `deployment.cloud_secret_name` (String, Optional): K8s credentials name where cloud secrets will be saved (includes permission like DB). Sample: `my-app-cloud-secret`
|
70
|
+
- `deployment.cloud_sql_instance` (String, Optional): Cloud sql instance name. Sample: `my-project:europe-west1:my-instance-name=tcp:5432` (5432 => postgres, 3306 => mysql)
|
71
|
+
- `deployment.env_vars` (Hash, optional): List of static env variables (Note: Not recommended for sensitive values). Sample: `{ 'RAILS_ENV' => 'production' }`
|
72
|
+
- `deployment.command` (String, Optional): Bash command to be used for web containers. Sample: `rails s -b 0.0.0.0`
|
73
|
+
- `deployment.liveness_path` (String, Optional): Relative path to be used for readiness and liveness checker of the web app. Sample: `/check_liveness`
|
74
|
+
- `deployment.custom_volumes` (Hash<name: path>, Optional): Custom volumes to be mounted. Sample: `{ my_volume: { kind: 'hostPath', mount_path: '/', settings: { path: '..', type: 'Directory' } } }`
|
75
|
+
|
76
|
+
- `deployment.job_name` (String, optional): Job deployment name (Note: Underscores are not accepted). Sample: `my-app-job`. Note: This deployment is created only if this value is present
|
77
|
+
- `deployment.job_command` (String, optional): Bash command to be used for job container. Sample: `bundle exec sidekiq`
|
78
|
+
- `deployment.job_sidekiq_alive_gem` (Boolean, default false): If true will add liveness checker settings using `sidekiq_alive_gem` (`sidekiq_alive` gem needs to be present in your Gemfile)
|
79
|
+
- `deployment.job_services` (Array, Optional, only `job_sidekiq_alive_gem` or `job_services` is allowed): List of linux service names that are required for a healthy job container. Sample: `['sidekiq', 'cron']`
|
80
|
+
|
81
|
+
|
82
|
+
- `secrets.name` (String): K8s secrets name where env vars will be saved and fetched from. Sample: `my-app-secrets`
|
83
|
+
|
84
|
+
- `service.name`: K8s service name. Sample: `my-app-service`
|
85
|
+
- `service.port_name`: Http port name to connect between k8s ingress and service. Sample: `http-port`. Note: max 15 characters
|
86
|
+
- `service.backend_port_name` (String): Web backend port name to be connected between k8s service and web deployments. Sample: `b-port`. Note: max 15 characters
|
87
|
+
|
88
|
+
- `ingress.name`: Name of k8s ingress for the app: Sample: `my-app-ingress`
|
89
|
+
- `ingress.ip_name` (Optional): Static ip address is not created nor assigned if empty value. Sample: `my-app-static-ip`
|
90
|
+
- `ingress.certificate_name` (Optional): Ssl certificate is not created nor assigned if empty value. Sample: `my-app-lets-encrypt`. Note: requires `certificate_domain`
|
91
|
+
- `ingress.certificate_domain` (Optional): Domain name for the certificate. Sample: `myapp.com`. Note: does not support for willcard domains
|
92
|
+
|
93
|
+
### Partials
|
94
|
+
- `_container_extra_settings.yml` Partial template to add custom container settings. Receives `pod` as local variable (`web` | `job` | `cloudsql` | `logs`). Sample:
|
95
|
+
```yaml
|
96
|
+
<% if locals[:pod] == 'job' %>
|
97
|
+
resources:
|
98
|
+
requests:
|
99
|
+
cpu: 50m
|
100
|
+
memory: 256Mi
|
101
|
+
limits:
|
102
|
+
cpu: 500m
|
103
|
+
memory: 1Gi
|
104
|
+
<% end %>
|
105
|
+
```
|
106
|
+
- `_custom_containers.yml` Partial template to add extra containers (Receives `pod` as local variable: `web` | `job`). Sample:
|
107
|
+
```yaml
|
108
|
+
<% if locals[:pod] == 'job' %>
|
109
|
+
- name: scraper
|
110
|
+
image: owencio/easy_scraper
|
111
|
+
...
|
112
|
+
<% end %>
|
113
|
+
```
|
114
|
+
- `_cd_apply_images.sh` Partial template to customize the process to apply the new version (new docker image)
|
115
|
+
|
47
116
|
## Templating
|
48
117
|
When performing a command or script, the setting variables are replaced based on `DEPLOY_ENV`.
|
49
118
|
All these setting variable values are configured in `.kubernetes/settings.rb` which defines the values based on `DEPLOY_ENV`.
|
data/lib/templates/_replicas.yml
CHANGED
@@ -21,7 +21,12 @@ documents:
|
|
21
21
|
spec: &template_spec
|
22
22
|
containers:
|
23
23
|
- &app_container
|
24
|
-
|
24
|
+
<% if continuous_deployment.image_name %>
|
25
|
+
image: '<%= continuous_deployment.image_name %>:latest'
|
26
|
+
<% else %>
|
27
|
+
image: '<%= continuous_deployment.image %>'
|
28
|
+
<% end %>
|
29
|
+
|
25
30
|
<% if deployment.command %>
|
26
31
|
command: ["/bin/bash", "-c", "<%= deployment.command %>"]
|
27
32
|
<% end %>
|
data/lib/templates/ingress.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
<% if ingress.
|
1
|
+
<% if ingress.certificate_name %>
|
2
2
|
<%= include_template "certificate.yml" %>
|
3
3
|
<% end %>
|
4
4
|
|
@@ -17,7 +17,7 @@ metadata:
|
|
17
17
|
kubernetes.io/ingress.global-static-ip-name: "<%=ingress.ip_name%>"
|
18
18
|
<% end %>
|
19
19
|
|
20
|
-
<% if ingress.
|
20
|
+
<% if ingress.certificate_name %>
|
21
21
|
networking.gke.io/managed-certificates: '<%=ingress.certificate_name%>'
|
22
22
|
<% end %>
|
23
23
|
|
data/lib/templates/service.yml
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
apiVersion: cloud.google.com/v1beta1
|
5
5
|
kind: BackendConfig
|
6
6
|
metadata:
|
7
|
-
name: '<%=service.
|
7
|
+
name: '<%=service.name%>-bconfig'
|
8
8
|
spec:
|
9
9
|
timeoutSec: 1800
|
10
10
|
---
|
@@ -16,7 +16,7 @@ metadata:
|
|
16
16
|
name: '<%=service.name%>'
|
17
17
|
annotations:
|
18
18
|
<% if cloud.name == 'gcloud' %>
|
19
|
-
beta.cloud.google.com/backend-config: '{"ports": {"80":"<%=service.
|
19
|
+
beta.cloud.google.com/backend-config: '{"ports": {"80":"<%=service.name%>-bconfig"}}'
|
20
20
|
<% end %>
|
21
21
|
spec:
|
22
22
|
selector:
|
data/lib/templates/settings.rb
CHANGED
@@ -6,6 +6,7 @@ settings = {
|
|
6
6
|
deployment: {
|
7
7
|
name: app_name,
|
8
8
|
replicas: is_production ? 2 : 1,
|
9
|
+
replicas_range: nil, # [min, max] or nil to ignore, sample: is_production ? [1, 2] : nil
|
9
10
|
cloud_secret_name: "#{is_production ? 'production' : 'beta'}-cloud-secret",
|
10
11
|
cloud_sql_instance: 'xxx:xxx:xxx=tcp:5432', # 5432 => postgres, 3306 => mysql
|
11
12
|
env_vars: {}, # Sample: { 'CUSTOM_VAR' => 'value' }
|
@@ -20,10 +21,10 @@ settings = {
|
|
20
21
|
name: "#{app_name}-ingress",
|
21
22
|
ip_name: "#{app_name}-static-ip", # nil if static ip is not necessary
|
22
23
|
certificate_name: "#{app_name}-lets-encrypt", # nil if ssl is not required
|
23
|
-
|
24
|
+
certificate_domain: is_production ? 'myapp.com' : 'beta.myapp.com' # nil if domain is not required
|
24
25
|
},
|
25
26
|
continuous_deployment: {
|
26
|
-
|
27
|
+
image: "gcr.io/my-account/#{app_name}:latest",
|
27
28
|
project_name: 'my-project-name',
|
28
29
|
cluster_name: 'my-cluster-name',
|
29
30
|
cluster_region: 'europe-west4-a',
|
@@ -36,8 +37,7 @@ settings = {
|
|
36
37
|
service: {
|
37
38
|
name: app_name,
|
38
39
|
port_name: 'http-port', # max 15 characters
|
39
|
-
backend_port_name: 'b-port'
|
40
|
-
config_name: "#{app_name}-backend-config"
|
40
|
+
backend_port_name: 'b-port' # max 15 characters
|
41
41
|
}
|
42
42
|
}
|
43
43
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubernetes_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- owen2345
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erb
|