kubernetes_helper 1.15.1 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 150f172f156e7ee7061f651caec568f443526c231b88322f15909fb14db1d928
4
- data.tar.gz: 3a9b2d35c152f5cb4feb9b526fba6caa8c1264679ebb0f80b93b3f6a6f49f711
3
+ metadata.gz: 304a3005e0ef0280b53a2d108a0880a5406354a135027fb57cefff5e0ed5c437
4
+ data.tar.gz: dfb38b6b47866ca50ba1c88d11dcad20101827f93a8f617dca95b3b3e225b31d
5
5
  SHA512:
6
- metadata.gz: f1991a65e8a61d8a4fc44a34a6987c9c3b82f7f19ff746c84f4fdd120487e674957538a3e780f99a5518300cb5230528662e7efb54bde78144d53acd743bad0f
7
- data.tar.gz: b511e26550c54ea1dddcf156526bc0972d45a612eb60cde67a14a67f3b41c0a0bede568684ec45de54c8cac24cd57b615bb464936eff8093bccfb797501c3097
6
+ metadata.gz: d02d6bfefa1404a9a906c964c0ebb2e3979835fbcf539aeb99179cf850e08d87d1aa1c75f878ffb051fa0769a5ea19cf4ff73707bffc8aa5031eed59ee1081fa
7
+ data.tar.gz: 3b40bf03b9498aed70c286170536764bd4ebe3ee8840b197584e831cbd4e5965e27671802dc30a4481de99093e18e9d9f8066728d4e95dbbed58c61032aa61b5
data/README.md CHANGED
@@ -1,10 +1,5 @@
1
1
  # KubernetesHelper
2
2
 
3
- TODO:
4
- - create a release if Business app is running well with the limitations, perhaps test with Buddy app by using the gem from github
5
- - Publish the gem + release new version
6
-
7
-
8
3
  This gem is a helper to manage easily Kubernetes settings for GCloud (easy customization for other cloud services) where configuring and deploying a new application can be done in a couple of minutes.
9
4
  Configuration and customization can be done for multiple environments and at any level which permits to deploy simple and complex applications.
10
5
 
@@ -27,7 +22,7 @@ Configuration and customization can be done for multiple environments and at any
27
22
  Note: The local template will be used instead of the default one.
28
23
 
29
24
  3. Install/setup the application on kubernetes
30
- Open [.kubernetes/README.md](lib/templates/README.md) to see the instructions (customize the file according to your project and keep it updated)
25
+ Open [.kubernetes/README.md](lib/templates/README.md) to see the instructions (customize the file according to your project and keep it updated in your repository)
31
26
 
32
27
 
33
28
  ## Settings API
@@ -54,11 +49,11 @@ Configuration and customization can be done for multiple environments and at any
54
49
  - `deployment.logs_resources` (Hash, optional): Configure depending on the app requirements. Default: `{ cpu: { max: '200m', min: '50m' }, mem: { max: '200Mi', min: '50Mi' } }`
55
50
 
56
51
  ### Application deployment.yml for jobs or services without internet interaction (Optional)
57
- - `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
58
- - `deployment.job_command` (String, optional): Bash command to be used for job container. Sample: `bundle exec sidekiq`
59
- - `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)
60
- - `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']`
61
- - `deployment.job_resources` (Hash, optional): Configure depending on the job app requirements. Sample: `{ cpu: { max: '1', min: '500m' }, mem: { max: '1Gi', min: '500Mi' } }`
52
+ - `deployment.job_apps[].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
53
+ - `deployment.job_apps[].command` (String, optional): Bash command to be used for job container. Sample: `bundle exec sidekiq`
54
+ - `deployment.job_apps[].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)
55
+ - `deployment.job_apps[].services` (Array, Optional): List of linux service names that are required for a healthy job container. Sample: `['sidekiq', 'cron']`. Note: This will be ignored if `sidekiq_alive_gem` was defined.
56
+ - `deployment.job_apps[].resources` (Hash, optional): Configure depending on the job app requirements. Sample: `{ cpu: { max: '1', min: '500m' }, mem: { max: '1Gi', min: '500Mi' } }`
62
57
 
63
58
  ### Applications secrets.yml (Optional)
64
59
  - `secrets.name` (String): K8s secrets name where env vars will be saved and fetched from. Sample: `my-app-secrets`
@@ -68,6 +63,8 @@ Configuration and customization can be done for multiple environments and at any
68
63
  - `service.port_name` (String, default `http-port`): Http port name to connect between k8s ingress and service. Sample: `http-port`. Note: max 15 characters
69
64
  - `service.backend_port_name` (String, default `b-port`): Web backend port name to be connected between k8s service and web deployments. Sample: `b-port`. Note: max 15 characters
70
65
  - `service.type`: K8s service type. By default `NodePort`
66
+ - `service.do_certificate_id`: Digital Ocean certificate ID to be used for the loadbalancer to auto redirect http to https.
67
+ Note: This value can be fetched via `doctl compute certificate list`. If there are no certificates available, you can generate a new one using digital ocean dashboard -> networking -> certificates.
71
68
 
72
69
  ### Application ingress.yml (Optional)
73
70
  - `ingress.name`: Name of k8s ingress for the app: Sample: `my-app-ingress`
@@ -76,7 +73,7 @@ Configuration and customization can be done for multiple environments and at any
76
73
  - `ingress.certificate_domain` (Optional): Domain name for the certificate. Sample: `myapp.com`. Note: does not support for willcard domains
77
74
  To register multiple domains (Certificate names will be auto-generated like `mysite-com-lets-encrypt`): `certificate_domain: ['mysite.com', 'mysite.de', 'mysite.uk']`
78
75
 
79
- - `cloud.name` (String, optional): Cloud service name. Default `gcloud`.
76
+ - `cloud.name` (String, optional): Cloud service name: `gcloud | digital_ocean`. Default `gcloud`.
80
77
 
81
78
  ### Application CD (continuous deployment)
82
79
  - `continuous_deployment.image_name` (String): Partial docker image url. Sample: `gcr.io/my-account/my_app_name`
@@ -91,7 +88,7 @@ Configuration and customization can be done for multiple environments and at any
91
88
  - `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)
92
89
 
93
90
  ### Gem templating partials
94
- - `_container_extra_settings.yml` Partial template to add custom container settings. Receives `pod` as local variable (`web` | `job` | `cloudsql` | `logs`). Sample:
91
+ - `_container_extra_settings.yml` Partial template to add custom container settings. Receives `pod` as local variable (`web` | `job` | `cloudsql` | `logs`) and `pod_name`. Sample:
95
92
  ```yaml
96
93
  <% if locals[:pod] == 'job' %>
97
94
  resources:
@@ -103,7 +100,7 @@ Configuration and customization can be done for multiple environments and at any
103
100
  memory: 1Gi
104
101
  <% end %>
105
102
  ```
106
- - `_custom_containers.yml` Partial template to add extra containers (Receives `pod` as local variable: `web` | `job`). Sample:
103
+ - `_custom_containers.yml` Partial template to add extra containers (Receives `pod` as local variable: `web` | `job`) and `pod_name`. Sample:
107
104
  ```yaml
108
105
  <% if locals[:pod] == 'job' %>
109
106
  - name: scraper
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KubernetesHelper
4
- VERSION = '1.15.1'
4
+ VERSION = '1.17.0'
5
5
  end
@@ -25,7 +25,8 @@ module KubernetesHelper
25
25
  deployment: {
26
26
  log_container: true,
27
27
  log_folder: '/app/log',
28
- external_secrets: {}
28
+ external_secrets: {},
29
+ job_apps: settings[:job_apps] || job_apps_from_old_settings(settings)
29
30
  },
30
31
  service: {
31
32
  port_name: 'http-port',
@@ -75,4 +76,18 @@ module KubernetesHelper
75
76
  FileUtils.cp(templates_path(name), path) unless File.exist?(path)
76
77
  end
77
78
  end
79
+
80
+ def self.job_apps_from_old_settings(settings)
81
+ return [] unless settings[:deployment][:job_name]
82
+
83
+ [
84
+ {
85
+ name: settings[:deployment][:job_name],
86
+ command: settings[:deployment][:job_command],
87
+ services: settings[:deployment][:job_services],
88
+ resources: settings[:deployment][:job_resources],
89
+ sidekiq_alive_gem: settings[:deployment][:job_sidekiq_alive_gem]
90
+ }
91
+ ]
92
+ end
78
93
  end
@@ -13,7 +13,7 @@ documents:
13
13
  rollingUpdate:
14
14
  maxSurge: 1
15
15
  maxUnavailable: 1
16
- minReadySeconds: 5
16
+ minReadySeconds: 10
17
17
  template:
18
18
  metadata:
19
19
  labels:
@@ -76,7 +76,7 @@ documents:
76
76
  env: []
77
77
  volumeMounts:
78
78
  - *cloud_credentials_volume
79
- <%= include_template "_resources.yml", deployment.cloudsql_resources || { cpu: { max: '300m', min: '100m' }, mem: { max: '500Mi', min: '200Mi' } } %>
79
+ <%= include_template "_resources.yml", deployment.cloudsql_resources || { cpu: { min: '1' }, mem: { min: '1Gi' } } %>
80
80
  <%= include_template "_container_extra_settings.yml", { pod: 'cloudsql' } %>
81
81
  <% end %>
82
82
 
@@ -88,7 +88,7 @@ documents:
88
88
  env: []
89
89
  volumeMounts:
90
90
  - *log_volume
91
- <%= include_template "_resources.yml", deployment.logs_resources || { cpu: { max: '200m', min: '50m' }, mem: { max: '200Mi', min: '50Mi' } } %>
91
+ <%= include_template "_resources.yml", deployment.logs_resources || { cpu: { max: '300m', min: '100m' }, mem: { max: '500Mi', min: '200Mi' } } %>
92
92
  <%= include_template "_container_extra_settings.yml", { pod: 'logs' } %>
93
93
  <% end %>
94
94
 
@@ -98,18 +98,19 @@ documents:
98
98
  volumes:
99
99
  <%= include_template "_volumes.yml", { pod: 'web' } %>
100
100
 
101
-
102
- <% if deployment.job_name %>
101
+ <% deployment.job_apps.each do |job_app| %>
103
102
  - apiVersion: apps/v1
104
103
  kind: Deployment
105
104
  metadata:
106
- name: &job_app_name <%=deployment.job_name%>
105
+ name: &job_app_name <%= job_app[:name] %>
107
106
  spec:
108
107
  <<: *default_spec
109
108
  replicas: 1
110
109
  selector:
111
110
  matchLabels:
112
111
  name: *job_app_name
112
+ strategy:
113
+ type: Recreate
113
114
  template:
114
115
  metadata:
115
116
  labels:
@@ -119,18 +120,18 @@ documents:
119
120
  containers:
120
121
  - <<: *app_container
121
122
  name: *job_app_name
122
- <% if deployment.job_command %>
123
- command: [ "/bin/bash", "-c", "<%= deployment.job_command %>" ]
123
+ <% if job_app[:command] %>
124
+ command: [ "/bin/bash", "-c", "<%= job_app[:command] %>" ]
124
125
  <% end %>
125
- <% if deployment.job_resources %>
126
- <%= include_template "_resources.yml", deployment.job_resources %>
126
+ <% if job_app[:resources] %>
127
+ <%= include_template "_resources.yml", job_app[:resources] %>
127
128
  <% end %>
128
- <%= include_template "_container_extra_settings.yml", { pod: 'job' } %>
129
+ <%= include_template "_container_extra_settings.yml", { pod: 'job', pod_name: job_app[:name] } %>
129
130
 
130
- <% if deployment.job_sidekiq_alive_gem %>
131
- <%= include_template "_sidekiq_alive_gem.yml" %>
131
+ <% if job_app[:sidekiq_alive_gem] %>
132
+ <%= include_template "_sidekiq_alive_gem.yml" %>
132
133
  <% else %>
133
- <%= include_template "_job_liveness.yml" %>
134
+ <%= include_template "_job_liveness.yml" %>
134
135
  <% end %>
135
136
 
136
137
  <% if deployment.cloud_secret_name %>
@@ -141,10 +142,10 @@ documents:
141
142
  - <<: *logs_container
142
143
  <% end %>
143
144
 
144
- <%= include_template "_custom_containers.yml", { pod: 'job' } %>
145
+ <%= include_template "_custom_containers.yml", { pod: 'job', pod_name: job_app[:name] } %>
145
146
 
146
147
  volumes:
147
- <%= include_template "_volumes.yml", { pod: 'job' } %>
148
+ <%= include_template "_volumes.yml", { pod: 'job', pod_name: job_app[:name] } %>
148
149
  <% end %>
149
150
 
150
151
  <% if deployment.replicas_range %>
@@ -15,6 +15,11 @@ apiVersion: v1
15
15
  metadata:
16
16
  name: '<%=service.name%>'
17
17
  annotations:
18
+ <% if cloud.name == 'digital_ocean' && service.do_certificate_id %>
19
+ service.beta.kubernetes.io/do-loadbalancer-protocol: "https"
20
+ service.beta.kubernetes.io/do-loadbalancer-certificate-id: <%= service.do_certificate_id %>
21
+ service.beta.kubernetes.io/do-loadbalancer-redirect-http-to-https: "true"
22
+ <% end %>
18
23
  <% if cloud.name == 'gcloud' %>
19
24
  beta.cloud.google.com/backend-config: '{"ports": {"80":"<%=service.name%>-bconfig"}}'
20
25
  <% end %>
@@ -27,3 +32,10 @@ spec:
27
32
  protocol: TCP
28
33
  name: '<%=service.port_name%>'
29
34
  targetPort: '<%=service.backend_port_name%>'
35
+
36
+ <% if cloud.name == 'digital_ocean' && service.do_certificate_id %>
37
+ - name: https
38
+ protocol: TCP
39
+ port: 443
40
+ targetPort: '<%=service.backend_port_name%>'
41
+ <% end %>
@@ -12,10 +12,14 @@ settings = {
12
12
  env_vars: {}, # Sample: { 'CUSTOM_VAR' => 'value' }
13
13
  # command: '', # custom container command (default empty to be managed by Dockerfile)
14
14
  # liveness_path: '/check_liveness', # nil if not exist
15
- # job_name: "#{app_name}-job", # enable if there is any background service
16
- # job_command: 'bundle exec sidekiq -C config/sidekiq.yml',
17
- # job_services: ['sidekiq', 'cron'] # list of linux services needed.
18
15
  # custom_volumes: { my_volume: { kind: 'hostPath', mount_path: '/', settings: { path: '..', type: 'Directory' } } }
16
+ job_apps: [
17
+ # {
18
+ # name: "#{app_name}-job", # enable if there is any background service
19
+ # command: 'bundle exec sidekiq -C config/sidekiq.yml',
20
+ # services: ['sidekiq', 'cron'] # list of linux services needed.
21
+ # }
22
+ ]
19
23
  },
20
24
  secrets: {
21
25
  name: "#{app_name}-secrets"
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.15.1
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - owen2345
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-15 00:00:00.000000000 Z
11
+ date: 2022-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erb