kubernetes_helper 1.14.0 → 1.16.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 +9 -1
- data/lib/kubernetes_helper/version.rb +1 -1
- data/lib/templates/_cd_digital.sh +24 -0
- data/lib/templates/_cd_google.sh +37 -0
- data/lib/templates/_resources.yml +15 -0
- data/lib/templates/cd.sh +2 -37
- data/lib/templates/deployment.yml +9 -1
- data/lib/templates/service.yml +13 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd1b1fbd529561166b5e90b3ece98cd5f9abb81d1d652dcd52d62179daddbd14
|
4
|
+
data.tar.gz: a6bb05e8553de13d43d7b9bc9c46ea5aa1dc03e1adca3fc286cb7b7ed73609ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fde4038a234dafaa435aa6aca47348a090bb79d53a3ba3357a3d632b1f85a849322b70851da89674412abe5d679a72feeb30ac0b86b2de83f4dd9bc3224fb8d
|
7
|
+
data.tar.gz: 89ca63330472ad00a1b06004be34c43b7de2582a509247c75d605c5aa6743b64fd653d51fe3459eb1a9d24071faf18a1632663946d274c2ff7dd425a5dc7f220
|
data/README.md
CHANGED
@@ -43,12 +43,17 @@ Configuration and customization can be done for multiple environments and at any
|
|
43
43
|
- `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
44
|
- `deployment.log_folder` (String, default `/app/log`): Logs to be printed from
|
45
45
|
- `deployment.app_port` (Integer, default 3000): Application port number
|
46
|
+
- `deployment.resources` (Hash, optional): Configure depending on the web app requirements. Sample: `{ cpu: { max: '1', min: '500m' }, mem: { max: '1Gi', min: '500Mi' } }`
|
47
|
+
|
48
|
+
- `deployment.cloudsql_resources` (Hash, optional): Configure depending on the app requirements. Default: `{ cpu: { max: '300m', min: '100m' }, mem: { max: '500Mi', min: '200Mi' } }`
|
49
|
+
- `deployment.logs_resources` (Hash, optional): Configure depending on the app requirements. Default: `{ cpu: { max: '200m', min: '50m' }, mem: { max: '200Mi', min: '50Mi' } }`
|
46
50
|
|
47
51
|
### Application deployment.yml for jobs or services without internet interaction (Optional)
|
48
52
|
- `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
53
|
- `deployment.job_command` (String, optional): Bash command to be used for job container. Sample: `bundle exec sidekiq`
|
50
54
|
- `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
55
|
- `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']`
|
56
|
+
- `deployment.job_resources` (Hash, optional): Configure depending on the job app requirements. Sample: `{ cpu: { max: '1', min: '500m' }, mem: { max: '1Gi', min: '500Mi' } }`
|
52
57
|
|
53
58
|
### Applications secrets.yml (Optional)
|
54
59
|
- `secrets.name` (String): K8s secrets name where env vars will be saved and fetched from. Sample: `my-app-secrets`
|
@@ -57,6 +62,9 @@ Configuration and customization can be done for multiple environments and at any
|
|
57
62
|
- `service.name`: K8s service name. Sample: `my-app-service`
|
58
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
|
59
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
|
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.
|
60
68
|
|
61
69
|
### Application ingress.yml (Optional)
|
62
70
|
- `ingress.name`: Name of k8s ingress for the app: Sample: `my-app-ingress`
|
@@ -65,7 +73,7 @@ Configuration and customization can be done for multiple environments and at any
|
|
65
73
|
- `ingress.certificate_domain` (Optional): Domain name for the certificate. Sample: `myapp.com`. Note: does not support for willcard domains
|
66
74
|
To register multiple domains (Certificate names will be auto-generated like `mysite-com-lets-encrypt`): `certificate_domain: ['mysite.com', 'mysite.de', 'mysite.uk']`
|
67
75
|
|
68
|
-
- `cloud.name` (String, optional): Cloud service name
|
76
|
+
- `cloud.name` (String, optional): Cloud service name: `gcloud | digital_ocean`. Default `gcloud`.
|
69
77
|
|
70
78
|
### Application CD (continuous deployment)
|
71
79
|
- `continuous_deployment.image_name` (String): Partial docker image url. Sample: `gcr.io/my-account/my_app_name`
|
@@ -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
|
-
|
20
|
-
|
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: { min: '1' }, mem: { min: '1Gi' } } %>
|
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
|
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: '300m', min: '100m' }, mem: { max: '500Mi', min: '200Mi' } } %>
|
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 %>
|
data/lib/templates/service.yml
CHANGED
@@ -15,15 +15,27 @@ 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 %>
|
21
26
|
spec:
|
22
27
|
selector:
|
23
28
|
name: '<%=deployment.name%>'
|
24
|
-
type: NodePort
|
29
|
+
type: '<%=service.type || 'NodePort' %>'
|
25
30
|
ports:
|
26
31
|
- port: 80
|
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 %>
|
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.16.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-
|
11
|
+
date: 2022-04-28 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
|