kubernetes_helper 1.14.0 → 1.15.1

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: 33da4492b4f95cbd8a47c55b8b2449f99b0c2224e7b52017e12d95c50efa2414
4
- data.tar.gz: d7a12f66bfbd86a252acd1d6e57978a1f73497f7578cc0f9c484b1c4f93983a4
3
+ metadata.gz: 150f172f156e7ee7061f651caec568f443526c231b88322f15909fb14db1d928
4
+ data.tar.gz: 3a9b2d35c152f5cb4feb9b526fba6caa8c1264679ebb0f80b93b3f6a6f49f711
5
5
  SHA512:
6
- metadata.gz: 10cabcc986c70e54adf560d32c834c6421958fdbf0dcaf1d991e9a1bd994cb34c4f9dd126261abc638c2bff1dd899e776840c83da8887c10e0975607cd3641b9
7
- data.tar.gz: 306780df8402e223537b35fc02edaf7f8157b91aa7c8ce0512d38e49e46bcb529a3da06eb495fd0ea167e076423f6cd952ed5a5b9d2dbcf5bf14b34a627d561c
6
+ metadata.gz: f1991a65e8a61d8a4fc44a34a6987c9c3b82f7f19ff746c84f4fdd120487e674957538a3e780f99a5518300cb5230528662e7efb54bde78144d53acd743bad0f
7
+ data.tar.gz: b511e26550c54ea1dddcf156526bc0972d45a612eb60cde67a14a67f3b41c0a0bede568684ec45de54c8cac24cd57b615bb464936eff8093bccfb797501c3097
data/README.md CHANGED
@@ -1,5 +1,10 @@
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
+
3
8
  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.
4
9
  Configuration and customization can be done for multiple environments and at any level which permits to deploy simple and complex applications.
5
10
 
@@ -43,12 +48,17 @@ Configuration and customization can be done for multiple environments and at any
43
48
  - `deployment.log_container` (Boolean, default true): Permits to auto include logs container to print all logs from logs/*.log to stdout (required for papertrail using fluentd)
44
49
  - `deployment.log_folder` (String, default `/app/log`): Logs to be printed from
45
50
  - `deployment.app_port` (Integer, default 3000): Application port number
51
+ - `deployment.resources` (Hash, optional): Configure depending on the web app requirements. Sample: `{ cpu: { max: '1', min: '500m' }, mem: { max: '1Gi', min: '500Mi' } }`
52
+
53
+ - `deployment.cloudsql_resources` (Hash, optional): Configure depending on the app requirements. Default: `{ cpu: { max: '300m', min: '100m' }, mem: { max: '500Mi', min: '200Mi' } }`
54
+ - `deployment.logs_resources` (Hash, optional): Configure depending on the app requirements. Default: `{ cpu: { max: '200m', min: '50m' }, mem: { max: '200Mi', min: '50Mi' } }`
46
55
 
47
56
  ### Application deployment.yml for jobs or services without internet interaction (Optional)
48
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
49
58
  - `deployment.job_command` (String, optional): Bash command to be used for job container. Sample: `bundle exec sidekiq`
50
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)
51
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
62
 
53
63
  ### Applications secrets.yml (Optional)
54
64
  - `secrets.name` (String): K8s secrets name where env vars will be saved and fetched from. Sample: `my-app-secrets`
@@ -57,6 +67,7 @@ Configuration and customization can be done for multiple environments and at any
57
67
  - `service.name`: K8s service name. Sample: `my-app-service`
58
68
  - `service.port_name` (String, default `http-port`): Http port name to connect between k8s ingress and service. Sample: `http-port`. Note: max 15 characters
59
69
  - `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
+ - `service.type`: K8s service type. By default `NodePort`
60
71
 
61
72
  ### Application ingress.yml (Optional)
62
73
  - `ingress.name`: Name of k8s ingress for the app: Sample: `my-app-ingress`
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KubernetesHelper
4
- VERSION = '1.14.0'
4
+ VERSION = '1.15.1'
5
5
  end
@@ -0,0 +1,24 @@
1
+ # Download and install doctl
2
+ if [ -z "$(which doctl)" ]; then
3
+ wget https://github.com/digitalocean/doctl/releases/download/v1.72.0/doctl-1.72.0-linux-amd64.tar.gz
4
+ tar xf ~/doctl-1.72.0-linux-amd64.tar.gz
5
+ sudo mv ~/doctl /usr/local/bin
6
+ fi
7
+
8
+ if [ ! -z "$KB_AUTH_TOKEN" ]
9
+ then
10
+ doctl auth init --access-token $KB_AUTH_TOKEN
11
+ fi
12
+
13
+ ## Build and push containers
14
+ echo "****** building image..."
15
+ <% if continuous_deployment.docker_cmd %>
16
+ <%= continuous_deployment.docker_cmd %>
17
+ <% else %>
18
+ docker <%=continuous_deployment.docker_build_cmd || 'build -f Dockerfile'%> -t $DEPLOY_NAME .
19
+ <% end %>
20
+ docker push $DEPLOY_NAME
21
+
22
+ echo "****** tagging image $DEPLOY_NAME as $LATEST_NAME"
23
+ docker tag $DEPLOY_NAME $LATEST_NAME
24
+ docker push $LATEST_NAME
@@ -0,0 +1,37 @@
1
+ if [ ! -z "$KB_AUTH_TOKEN" ]
2
+ then
3
+ AUTH_PATH="$SCRIPT_DIR/k8s-auth-token.json"
4
+ rm -f -- $AUTH_PATH
5
+ echo $KB_AUTH_TOKEN >> $AUTH_PATH
6
+
7
+ ## ***** GOOGLE CONNECTOR
8
+ # Download and install Google Cloud SDK
9
+ if [ -z "$(which gcloud)" ]; then
10
+ export CLOUDSDK_CORE_DISABLE_PROMPTS=1; curl https://sdk.cloud.google.com | bash && source /home/runner/google-cloud-sdk/path.bash.inc && gcloud --quiet components update kubectl
11
+ fi
12
+
13
+ # Connect to cluster
14
+ gcloud auth activate-service-account --key-file $AUTH_PATH --project $PROJECT_NAME
15
+ gcloud docker --authorize-only --project $PROJECT_NAME
16
+ gcloud container clusters get-credentials $CLUSTER_NAME --region $CLUSTER_REGION
17
+ ## ***** END GOOGLE CONNECTOR
18
+ fi
19
+
20
+
21
+ ALREADY_DEPLOYED="$(gcloud container images list-tags --format='get(tags)' $IMAGE_NAME | grep $CI_COMMIT_SHA || :;)"
22
+ if [ -z $ALREADY_DEPLOYED ]
23
+ then
24
+ ## Build and push containers
25
+ echo "****** image not created yet, building image..."
26
+ <% if continuous_deployment.docker_cmd %>
27
+ <%= continuous_deployment.docker_cmd %>
28
+ <% else %>
29
+ docker <%=continuous_deployment.docker_build_cmd || 'build -f Dockerfile'%> -t $DEPLOY_NAME .
30
+ <% end %>
31
+ docker push $DEPLOY_NAME
32
+ else
33
+ echo "****** image was already created: $ALREADY_DEPLOYED"
34
+ fi
35
+
36
+ echo "****** tagging image $DEPLOY_NAME as $LATEST_NAME"
37
+ gcloud container images add-tag --quiet $DEPLOY_NAME $LATEST_NAME
@@ -0,0 +1,15 @@
1
+ resources:
2
+ limits:
3
+ <% if locals[:cpu] && locals[:cpu][:max] %>
4
+ cpu: <%= locals[:cpu][:max] %>
5
+ <% end %>
6
+ <% if locals[:mem] && locals[:mem][:max] %>
7
+ memory: <%= locals[:mem][:max] %>
8
+ <% end %>
9
+ requests:
10
+ <% if locals[:cpu] && locals[:cpu][:min] %>
11
+ cpu: <%= locals[:cpu][:min] %>
12
+ <% end %>
13
+ <% if locals[:mem] && locals[:mem][:min] %>
14
+ memory: <%= locals[:mem][:min] %>
15
+ <% end %>
data/lib/templates/cd.sh CHANGED
@@ -16,43 +16,8 @@ CI_COMMIT_SHA=${CI_COMMIT_SHA:-$(date +%s) }
16
16
  DEPLOY_NAME="${IMAGE_NAME}:${CI_COMMIT_SHA}"
17
17
  LATEST_NAME="${IMAGE_NAME}:<%= continuous_deployment.image_tag || 'latest' %>"
18
18
 
19
- if [ ! -z "$KB_AUTH_TOKEN" ]
20
- then
21
- AUTH_PATH="$SCRIPT_DIR/k8s-auth-token.json"
22
- rm -f -- $AUTH_PATH
23
- echo $KB_AUTH_TOKEN >> $AUTH_PATH
24
-
25
- ## ***** GOOGLE CONNECTOR
26
- # Download and install Google Cloud SDK
27
- if [ -z "$(which gcloud)" ]; then
28
- export CLOUDSDK_CORE_DISABLE_PROMPTS=1; curl https://sdk.cloud.google.com | bash && source /home/runner/google-cloud-sdk/path.bash.inc && gcloud --quiet components update kubectl
29
- fi
30
-
31
- # Connect to cluster
32
- gcloud auth activate-service-account --key-file $AUTH_PATH --project $PROJECT_NAME
33
- gcloud docker --authorize-only --project $PROJECT_NAME
34
- gcloud container clusters get-credentials $CLUSTER_NAME --region $CLUSTER_REGION
35
- ## ***** END GOOGLE CONNECTOR
36
- fi
37
-
38
-
39
- ALREADY_DEPLOYED="$(gcloud container images list-tags --format='get(tags)' $IMAGE_NAME | grep $CI_COMMIT_SHA || :;)"
40
- if [ -z $ALREADY_DEPLOYED ]
41
- then
42
- ## Build and push containers
43
- echo "****** image not created yet, building image..."
44
- <% if continuous_deployment.docker_cmd %>
45
- <%= continuous_deployment.docker_cmd %>
46
- <% else %>
47
- docker <%=continuous_deployment.docker_build_cmd || 'build -f Dockerfile'%> -t $DEPLOY_NAME .
48
- <% end %>
49
- docker push $DEPLOY_NAME
50
- else
51
- echo "****** image was already created: $ALREADY_DEPLOYED"
52
- fi
53
-
54
- echo "****** tagging image $DEPLOY_NAME as $LATEST_NAME"
55
- gcloud container images add-tag --quiet $DEPLOY_NAME $LATEST_NAME
19
+ <%= include_template "_cd_google.sh" if continuous_deployment.image_name.include?('gcr.io/') %>
20
+ <%= include_template "_cd_digital.sh" if continuous_deployment.image_name.include?('digitalocean.com/') %>
56
21
 
57
22
  ## Update new secrets defined in secrets.yml as ENV vars for deployments
58
23
  <% if continuous_deployment.update_deployment %>
@@ -42,6 +42,9 @@ documents:
42
42
  periodSeconds: 15
43
43
  readinessProbe: *liveness_probe
44
44
  <% end %>
45
+ <% if deployment.resources %>
46
+ <%= include_template "_resources.yml", deployment.resources %>
47
+ <% end %>
45
48
  <%= include_template "_container_extra_settings.yml", { pod: 'web' } %>
46
49
 
47
50
  volumeMounts:
@@ -73,6 +76,7 @@ documents:
73
76
  env: []
74
77
  volumeMounts:
75
78
  - *cloud_credentials_volume
79
+ <%= include_template "_resources.yml", deployment.cloudsql_resources || { cpu: { max: '300m', min: '100m' }, mem: { max: '500Mi', min: '200Mi' } } %>
76
80
  <%= include_template "_container_extra_settings.yml", { pod: 'cloudsql' } %>
77
81
  <% end %>
78
82
 
@@ -80,10 +84,11 @@ documents:
80
84
  - &logs_container # print to stdout all log files
81
85
  name: print-logs
82
86
  image: busybox
83
- command: [/bin/sh, -c, 'until find <%= deployment.log_folder %>/*.log; do sleep 1; done; tail -n+1 -f <%= deployment.log_folder %>/*.log']
87
+ command: [/bin/sh, -c, 'until find <%= deployment.log_folder %>/*.log; do sleep 5; done; tail -n+1 -f <%= deployment.log_folder %>/*.log']
84
88
  env: []
85
89
  volumeMounts:
86
90
  - *log_volume
91
+ <%= include_template "_resources.yml", deployment.logs_resources || { cpu: { max: '200m', min: '50m' }, mem: { max: '200Mi', min: '50Mi' } } %>
87
92
  <%= include_template "_container_extra_settings.yml", { pod: 'logs' } %>
88
93
  <% end %>
89
94
 
@@ -117,6 +122,9 @@ documents:
117
122
  <% if deployment.job_command %>
118
123
  command: [ "/bin/bash", "-c", "<%= deployment.job_command %>" ]
119
124
  <% end %>
125
+ <% if deployment.job_resources %>
126
+ <%= include_template "_resources.yml", deployment.job_resources %>
127
+ <% end %>
120
128
  <%= include_template "_container_extra_settings.yml", { pod: 'job' } %>
121
129
 
122
130
  <% if deployment.job_sidekiq_alive_gem %>
@@ -21,7 +21,7 @@ metadata:
21
21
  spec:
22
22
  selector:
23
23
  name: '<%=deployment.name%>'
24
- type: NodePort
24
+ type: '<%=service.type || 'NodePort' %>'
25
25
  ports:
26
26
  - port: 80
27
27
  protocol: TCP
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.14.0
4
+ version: 1.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - owen2345
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-21 00:00:00.000000000 Z
11
+ date: 2022-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erb
@@ -41,11 +41,14 @@ files:
41
41
  - lib/kubernetes_helper/version.rb
42
42
  - lib/templates/README.md
43
43
  - lib/templates/_cd_apply_images.sh
44
+ - lib/templates/_cd_digital.sh
45
+ - lib/templates/_cd_google.sh
44
46
  - lib/templates/_container_extra_settings.yml
45
47
  - lib/templates/_custom_containers.yml
46
48
  - lib/templates/_custom_volumes.yml
47
49
  - lib/templates/_job_liveness.yml
48
50
  - lib/templates/_replicas.yml
51
+ - lib/templates/_resources.yml
49
52
  - lib/templates/_sidekiq_alive_gem.yml
50
53
  - lib/templates/_volumes.yml
51
54
  - lib/templates/cd.sh