kubernetes_helper 0.3.3 → 1.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 +48 -24
- data/exe/kubernetes_helper +3 -2
- data/lib/kubernetes_helper.rb +6 -3
- data/lib/kubernetes_helper/version.rb +1 -1
- data/lib/templates/README.md +19 -17
- 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: 528e61587a3011330c7e474b523ce04079c8e49483bf894d5eb1806927436888
|
4
|
+
data.tar.gz: 9df4e7aab70108b75831077d2f4390067e5807664050f70e1557f504835144bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ed371a62084598f9bb4755df54ca059ffbeb729731555e4a6a6cf58dceecc0c347741921b5c46fc11408a937c914ea2d3fddaf3da94bc801dd6cd7f9ecc1ed8
|
7
|
+
data.tar.gz: 6248035be5a30995594a39ad56b73b811935b3b55988d067173a530ee0522294f6afb0e6361f664d4f696e7b370ce7b816ed74a53cb3f416c584e12c76ff023d
|
data/README.md
CHANGED
@@ -1,37 +1,61 @@
|
|
1
1
|
# KubernetesHelper
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
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.
|
4
|
+
Configuration and customization can be done for multiple environments and at any level which permits to deploy simple and complex applications.
|
6
5
|
|
7
6
|
## Installation
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
gem 'kubernetes_helper'
|
7
|
+
```bash
|
8
|
+
cd my_app/
|
9
|
+
gem install kubernetes_helper -v '~> 1.0'
|
10
|
+
kubernetes_helper generate_templates
|
13
11
|
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle install
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install kubernetes_helper
|
12
|
+
Note: Requires ruby 1.7+
|
22
13
|
|
23
14
|
## Usage
|
15
|
+
- Run any kubernetes document
|
16
|
+
`DEPLOY_ENV=<env name> kubernetes_helper run_deployment "<document name>" "<bash command>"`
|
17
|
+
Evaluates the kubernetes document with the following details:
|
18
|
+
- Supports for `- documents` to include multiple documents in a file and share yml variables between them (Sample: `lib/templates/deployment.yml#1`)
|
19
|
+
- Replaces all setting values based on `DEPLOY_ENV`
|
20
|
+
- Supports for secrets auto importer using `import_secrets: ['secrets.yml', '<%=secrets.name%>']` (Sample: `lib/templates/deployment.yml#29`)
|
21
|
+
- Supports for template including by `include_template 'template_name.yml.erb'`
|
22
|
+
Sample: `DEPLOY_ENV=beta kubernetes_helper run_deployment "deployment.yml" "kubectl create"`
|
23
|
+
|
24
|
+
- Run kubernetes commands
|
25
|
+
`DEPLOY_ENV=<env name> rake kubernetes_helper:run_command "<bash or k8s commands>"`
|
26
|
+
Replaces all setting variables inside command based on `DEPLOY_ENV` and performs it as a normal bash command.
|
27
|
+
Sample: `DEPLOY_ENV=beta rake kubernetes_helper:run_command "gcloud compute addresses create \#{ingress.ip_name} --global"'`
|
28
|
+
|
29
|
+
- Run kubernetes bash scripts
|
30
|
+
`DEPLOY_ENV=<env name> kubernetes_helper run_script "<script name>"`
|
31
|
+
Performs the script name located inside `.kubernetes` folder or kubernetes_helper template as the second option.
|
32
|
+
All setting variables inside the script will be replaced based on `DEPLOY_ENV`.
|
33
|
+
Sample: `DEPLOY_ENV=beta kubernetes_helper run_script "cd.sh"`
|
34
|
+
|
35
|
+
- Generate templates
|
36
|
+
`DEPLOY_ENV=<env name> kubernetes_helper generate_templates "<mode_or_template_name>"`
|
37
|
+
Copy files based on mode (`basic|advanced`) or a specific file from templates.
|
38
|
+
Sample: `DEPLOY_ENV=beta kubernetes_helper generate_templates "basic"`
|
39
|
+
Sample: `DEPLOY_ENV=beta kubernetes_helper generate_templates "ingress.yml"`
|
40
|
+
|
41
|
+
When performing a script it looks first for file inside .kubernetes folder, if not exist,
|
42
|
+
it looks for the file inside kubernetes_helper template folder.
|
43
|
+
|
44
|
+
## Templating
|
45
|
+
When performing a command or script, the setting variables are replaced based on `DEPLOY_ENV`.
|
46
|
+
All these setting variable values are configured in `.kubernetes/settings.rb` which defines the values based on `DEPLOY_ENV`.
|
47
|
+
These setting variables use [erb](https://github.com/ruby/erb) template gem to define variable replacement and conditional blocks, and so on.
|
48
|
+
Note: Setting variable values are referenced as an object format instead of a hash format for simplicity.
|
49
|
+
|
50
|
+
|
51
|
+
## Deployment
|
52
|
+
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.
|
53
|
+
|
54
|
+
## Sample
|
55
|
+
https://owen2345.github.io/kubernetes_helper/
|
24
56
|
|
25
57
|
## TODO
|
26
|
-
- Documentation
|
27
|
-
- Include conditional blocks
|
28
|
-
- Include hardcoded env values
|
29
|
-
- Tasks
|
30
|
-
- Add docs to include partials using `include_template 'sample.yml.erb'`
|
31
|
-
- Rake verify files
|
32
58
|
- Add one_step_configuration.sh
|
33
|
-
- Fix if/end_if for blocks
|
34
|
-
- Ability to copy specific template
|
35
59
|
|
36
60
|
## Contributing
|
37
61
|
|
data/exe/kubernetes_helper
CHANGED
@@ -9,8 +9,8 @@ case ARGV[0]
|
|
9
9
|
when 'run_command'
|
10
10
|
KubernetesHelper::Core.new(ENV['DEPLOY_ENV']).run_command(ARGV[1])
|
11
11
|
# Run the deployment script.
|
12
|
-
# Sample: DEPLOY_ENV=beta kubernetes_helper run_deployment "
|
13
|
-
when 'run_deployment'
|
12
|
+
# Sample: DEPLOY_ENV=beta kubernetes_helper run_deployment "cd.sh"
|
13
|
+
when 'run_deployment', 'run_script'
|
14
14
|
script_path = KubernetesHelper.settings_path(ARGV[1], use_template: true)
|
15
15
|
KubernetesHelper::Core.new(ENV['DEPLOY_ENV']).run_script(script_path)
|
16
16
|
# Parses kubernetes yml files (supporting multiple documents, Config variables replacement, include secrets).
|
@@ -22,6 +22,7 @@ when 'run_yml'
|
|
22
22
|
.parse_yml_file(KubernetesHelper.settings_path(ARGV[1], use_template: true), output_path)
|
23
23
|
KubernetesHelper.run_cmd("#{ARGV[2]} -f #{output_path}")
|
24
24
|
# Generate template files
|
25
|
+
# Sample: DEPLOY_ENV=beta kubernetes_helper generate_templates "basic"
|
25
26
|
when 'generate_templates' # Sample: kubernetes_helper generate basic
|
26
27
|
mode = ARGV[1] || 'basic'
|
27
28
|
KubernetesHelper.copy_templates(mode)
|
data/lib/kubernetes_helper.rb
CHANGED
@@ -39,11 +39,14 @@ module KubernetesHelper
|
|
39
39
|
file_name ? File.join(path, file_name) : path
|
40
40
|
end
|
41
41
|
|
42
|
-
# @param
|
43
|
-
def self.copy_templates(
|
42
|
+
# @param mode_or_file (basic, advanced, String) mode name or any specific template name
|
43
|
+
def self.copy_templates(mode_or_file)
|
44
44
|
FileUtils.mkdir(settings_path) unless Dir.exist?(settings_path)
|
45
|
+
template_path = templates_path(mode_or_file)
|
46
|
+
return FileUtils.cp(template_path, settings_path(mode_or_file)) if File.exist?(template_path)
|
47
|
+
|
45
48
|
files = %w[README.md secrets.yml settings.rb]
|
46
|
-
files += %w[deployment.yml cd.sh ingress.yml service.yml] if
|
49
|
+
files += %w[deployment.yml cd.sh ingress.yml service.yml] if mode_or_file == 'advanced'
|
47
50
|
files.each do |name|
|
48
51
|
path = settings_path(name)
|
49
52
|
FileUtils.cp(templates_path(name), path) unless File.exist?(path)
|
data/lib/templates/README.md
CHANGED
@@ -2,54 +2,56 @@
|
|
2
2
|
|
3
3
|
## Configure a new application environment
|
4
4
|
- Create the project on Gcloud
|
5
|
-
- Set the project where to work on
|
5
|
+
- Set the project where to work on
|
6
6
|
`gcloud config set project my-project`
|
7
7
|
|
8
|
-
- Create the cluster (Only if not exist)
|
8
|
+
- Create the cluster (Only if not exist)
|
9
9
|
`gcloud container clusters create my-cluster`
|
10
10
|
`# gcloud container clusters list --region europe-west4-a # to list clusters`
|
11
|
+
Note: `--preemptible` recommended for non production environments
|
11
12
|
|
12
|
-
- Use the cluster/project as default
|
13
|
+
- Use the cluster/project as default
|
13
14
|
`gcloud container clusters get-credentials my-cluster --zone europe-west4-a`
|
14
15
|
|
15
|
-
- Install helper for the next commands
|
16
|
+
- Install helper for the next commands
|
16
17
|
`gem install kubernetes_helper`
|
17
18
|
|
18
|
-
- Verify or update k8s settings in .kubernetes/settings.rb
|
19
|
+
- Verify or update k8s settings in .kubernetes/settings.rb
|
20
|
+
Note: Please do not include sensitive values in this file, ENV values are recommended instead.
|
19
21
|
|
20
|
-
- Register shared cloudsql proxy configuration (only if not exists)
|
22
|
+
- Register shared cloudsql proxy configuration (only if not exists)
|
21
23
|
```bash
|
22
24
|
DEPLOY_ENV=beta kubernetes_helper run_command "kubectl create secret generic <%=deployment.cloud_secret_name%> --from-file=credentials.json=<path-to-downloaded/credentials.json>"
|
23
25
|
```
|
24
26
|
|
25
|
-
- Register manually env vars (values must be encrypted using base64)
|
27
|
+
- Register manually env vars (values must be encrypted using base64)
|
26
28
|
Open and register secret values in `.kubernetes/secrets.yml`
|
27
|
-
Note: Enter base64 encoded values
|
29
|
+
Note: Enter base64 encoded values
|
28
30
|
```bash
|
29
31
|
DEPLOY_ENV=beta kubernetes_helper run_yml 'secrets.yml' 'kubectl create'
|
30
32
|
# kubectl get secrets # to list all secrets registered
|
31
33
|
```
|
32
34
|
|
33
|
-
- Create deployment to run application
|
35
|
+
- Create deployment to run application
|
34
36
|
```bash
|
35
37
|
DEPLOY_ENV=beta kubernetes_helper run_yml 'deployment.yml' 'kubectl create'
|
36
38
|
# kubectl get deployment # to list deployments
|
37
39
|
```
|
38
40
|
|
39
|
-
- Create service to connect pods and ingress
|
41
|
+
- Create service to connect pods and ingress
|
40
42
|
```bash
|
41
43
|
DEPLOY_ENV=beta kubernetes_helper run_yml 'service.yml' 'kubectl create'
|
42
44
|
# kubectl get services # to list all registered services
|
43
45
|
```
|
44
46
|
|
45
|
-
- Create the public ip address (only if static ip is required)
|
47
|
+
- Create the public ip address (only if static ip is required)
|
46
48
|
```bash
|
47
49
|
DEPLOY_ENV=beta kubernetes_helper run_command "gcloud compute addresses create <%=ingress.ip_name%> --global"
|
48
50
|
# gcloud compute addresses list # to list static ips generated
|
49
51
|
# Copy new external ip generated by the previous command and point your domain to it
|
50
52
|
```
|
51
53
|
|
52
|
-
- Register ingress to receive external http calls (includes ssl certificates if defined)
|
54
|
+
- Register ingress to receive external http calls (includes ssl certificates if defined)
|
53
55
|
```bash
|
54
56
|
DEPLOY_ENV=beta kubernetes_helper run_yml 'ingress.yml' 'kubectl create'
|
55
57
|
# kubectl get ingress # to list all registered ingresses
|
@@ -60,18 +62,18 @@
|
|
60
62
|
```
|
61
63
|
|
62
64
|
## Apply any k8s setting changes
|
63
|
-
- Secrets
|
65
|
+
- Secrets
|
64
66
|
Open kubernetes secrets and add/edit/remove values and then save it
|
65
67
|
`kubectl edit secret ...`
|
66
68
|
Once secrets were updated, then restart all related pods, see: https://medium.com/devops-dudes/how-to-propagate-a-change-in-kubernetes-secrets-by-restarting-dependent-pods-b71231827656
|
67
69
|
|
68
|
-
- Other settings
|
70
|
+
- Other settings
|
69
71
|
```bash
|
70
72
|
DEPLOY_ENV=beta kubernetes_helper run_yml 'deployment.yml' 'kubectl apply'
|
71
73
|
```
|
72
74
|
|
73
75
|
## Configure continuous deployment for github actions
|
74
|
-
* Go to github repository settings
|
76
|
+
* Go to github repository settings
|
75
77
|
* Register a new secret variable with content downloaded from https://console.cloud.google.com/iam-admin/serviceaccounts
|
76
78
|
(Make sure to attach a "Editor", "Storage Admin" and "Kubernetes engine cluster admin" role to the service account)
|
77
79
|
```bash
|
@@ -79,14 +81,14 @@
|
|
79
81
|
production: PROD_CLOUD_TOKEN=<secret content here>
|
80
82
|
```
|
81
83
|
|
82
|
-
* Add action to run deployment:
|
84
|
+
* Add action to run deployment:
|
83
85
|
```bash
|
84
86
|
env:
|
85
87
|
KB_AUTH_TOKEN: secrets.BETA_CLOUD_TOKEN
|
86
88
|
run: DEPLOY_ENV=beta kubernetes_helper run_deployment 'cd.sh'
|
87
89
|
```
|
88
90
|
|
89
|
-
* Sample:
|
91
|
+
* Sample:
|
90
92
|
```yml
|
91
93
|
- run: sudo gem install kubernetes_helper
|
92
94
|
- name: Staging deployment
|
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: 0
|
4
|
+
version: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- owen2345
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erb
|