kubes 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/docs/_docs/helpers.md +2 -1
- data/docs/_docs/learn/dsl/delete.md +2 -0
- data/docs/_docs/learn/dsl/deploy.md +5 -0
- data/docs/_docs/learn/dsl/new-project.md +1 -0
- data/docs/_docs/learn/dsl/review-project.md +13 -2
- data/docs/_docs/learn/dsl/update.md +1 -1
- data/docs/_docs/learn/yaml/delete.md +2 -0
- data/docs/_docs/learn/yaml/deploy.md +5 -0
- data/docs/_docs/learn/yaml/new-project.md +1 -0
- data/docs/_docs/learn/yaml/review-project.md +27 -11
- data/docs/_docs/learn/yaml/update.md +1 -1
- data/docs/_includes/learn/review.md +3 -1
- data/lib/kubes/cli/init.rb +2 -2
- data/lib/kubes/compiler/dsl/core/helpers.rb +15 -0
- data/lib/kubes/version.rb +1 -1
- data/lib/templates/dsl/.kubes/resources/base/all.rb.tt +1 -1
- data/lib/templates/dsl/.kubes/resources/shared/namespace.rb.tt +2 -0
- data/lib/templates/dsl/.kubes/resources/web/{deployment.rb.tt → deployment.rb} +3 -1
- data/lib/templates/dsl/.kubes/resources/web/{service.rb.tt → service.rb} +2 -2
- data/lib/templates/yaml/.kubes/resources/base/all.yaml.tt +1 -1
- data/lib/templates/yaml/.kubes/resources/shared/namespace.yaml.tt +6 -0
- data/lib/templates/yaml/.kubes/resources/web/deployment.yaml.tt +2 -2
- data/lib/templates/yaml/.kubes/resources/web/service.yaml.tt +2 -2
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5115dab9c9c9e52678c67ba1c6a956ffe9369961555d6393e8ad0ca40868fdd
|
4
|
+
data.tar.gz: 6f04422236a9df6a5833633c0fdc2b1bc49d31786c0fd1f1f599a75a7b7771eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c60e4d318db13f130929e1e554b93594f23cfda75b3a2e6974f395b1c1440734077bd85d9e11f0460371f62d8810e402db493c7fdf86b3f823ca8eb8810bb32e
|
7
|
+
data.tar.gz: b344b7af0da2964097d564407402cac1b880d134b1d213f1a40deb0234e661c7e08dc15fa3005fcfd4ba6f714d4262f5bd25c17fc876c545d0fac41898cb2a86
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [0.2.2]
|
7
|
+
- #14 init template updates, dockerfile_port helper
|
8
|
+
|
6
9
|
## [0.2.1]
|
7
10
|
- #13 improve network policy dsl
|
8
11
|
|
data/docs/_docs/helpers.md
CHANGED
@@ -7,8 +7,9 @@ Kubes provides some helper methods to help write Kubernetes YAML files. Here's
|
|
7
7
|
Helper | Description
|
8
8
|
--- | ---
|
9
9
|
built_image | Method refers to the latest Docker image built by Kubes. This spares you from having to update the image manually in the deployment resource.
|
10
|
-
|
10
|
+
dockerfile_port | Exposed port extracted from the Dockerfile of the project.
|
11
11
|
extra | The `KUBES_ENV` value.
|
12
|
+
with_extra | Appends the `KUBES_ENV` value to a string if it's set. It's covered in the [Extra Env Docs]({% link _docs/extra-env.md %}).
|
12
13
|
|
13
14
|
Here's also the source code with the helpers: [helpers.rb](https://github.com/boltops-tools/kubes/blob/master/lib/kubes/compiler/shared/helpers.rb).
|
14
15
|
|
@@ -15,6 +15,8 @@ You will be prompted to confirm before deletion. Here's out the output looks lik
|
|
15
15
|
service "demo-web" deleted
|
16
16
|
=> kubectl delete -f .kubes/output/web/deployment.yaml
|
17
17
|
deployment.apps "demo-web" deleted
|
18
|
+
=> kubectl delete -f .kubes/output/shared/namespace.yaml
|
19
|
+
namespace "demo" deleted
|
18
20
|
$
|
19
21
|
|
20
22
|
Let's double-check that the resources have been deleted:
|
@@ -14,6 +14,8 @@ You'll see output like this:
|
|
14
14
|
Pushed 111111111111.dkr.ecr.us-west-2.amazonaws.com/demo:kubes-2020-06-19T04-19-13 docker image.
|
15
15
|
Docker push took 15s.
|
16
16
|
Compiled .kubes/resources files
|
17
|
+
=> kubectl apply -f .kubes/output/shared/namespace.yaml
|
18
|
+
namespace/demo created
|
17
19
|
=> kubectl apply -f .kubes/output/web/service.yaml
|
18
20
|
service/demo-web created
|
19
21
|
=> kubectl apply -f .kubes/output/web/deployment.yaml
|
@@ -34,6 +36,9 @@ Example output:
|
|
34
36
|
|
35
37
|
$ kubes get
|
36
38
|
=> kubectl get --recursive -f .kubes/output
|
39
|
+
NAME STATUS AGE
|
40
|
+
namespace/demo Active 10s
|
41
|
+
|
37
42
|
NAME READY UP-TO-DATE AVAILABLE AGE
|
38
43
|
deployment.apps/demo-web 1/1 1 1 10s
|
39
44
|
|
@@ -17,6 +17,7 @@ Let's generate a starter project:
|
|
17
17
|
create .kubes/config/env/dev.rb
|
18
18
|
create .kubes/config/env/prod.rb
|
19
19
|
create .kubes/resources/base/all.rb
|
20
|
+
create .kubes/resources/shared/namespace.rb
|
20
21
|
create .kubes/resources/web/deployment.rb
|
21
22
|
create .kubes/resources/web/deployment/dev.rb
|
22
23
|
create .kubes/resources/web/deployment/prod.rb
|
@@ -4,7 +4,18 @@ title: Review Project
|
|
4
4
|
|
5
5
|
Let's review the resources.
|
6
6
|
|
7
|
-
##
|
7
|
+
## Namespace
|
8
|
+
|
9
|
+
We'll create a namespace for the app resources:
|
10
|
+
|
11
|
+
.kubes/resources/shared/namespace.rb
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
name "demo"
|
15
|
+
labels(app: "demo")
|
16
|
+
```
|
17
|
+
|
18
|
+
## Deployment
|
8
19
|
|
9
20
|
The `web/deployment.rb` file is a little more interesting:
|
10
21
|
|
@@ -21,7 +32,7 @@ image built_image # IE: user/demo:kubes-2020-06-13T19-55-16-43afc6e
|
|
21
32
|
|
22
33
|
The DSL form is more concise than the YAML form. Also, notice the use of the `built_image` helper. The `built_image` is a kubes helper method that refers to the latest Docker image built. This spares you from updating the image manually.
|
23
34
|
|
24
|
-
## Base
|
35
|
+
## Base Folder
|
25
36
|
|
26
37
|
Also let's check the files in the base folder.
|
27
38
|
|
@@ -6,7 +6,7 @@ Let's update the app. In this case, we don't need to update the Docker image, so
|
|
6
6
|
|
7
7
|
kubes apply
|
8
8
|
|
9
|
-
Here's what the output looks like
|
9
|
+
Here's what the output looks like. Note, the namespace is not shown for conciseness.
|
10
10
|
|
11
11
|
$ kubes apply
|
12
12
|
Compiled .kubes/resources files
|
@@ -15,6 +15,8 @@ You will be prompted to confirm before deletion. Here's out the output looks lik
|
|
15
15
|
service "demo-web" deleted
|
16
16
|
=> kubectl delete -f .kubes/output/web/deployment.yaml
|
17
17
|
deployment.apps "demo-web" deleted
|
18
|
+
=> kubectl delete -f .kubes/output/shared/namespace.yaml
|
19
|
+
namespace "demo" deleted
|
18
20
|
$
|
19
21
|
|
20
22
|
Let's double-check that the resources have been deleted:
|
@@ -14,6 +14,8 @@ You'll see output like this:
|
|
14
14
|
Pushed 111111111111.dkr.ecr.us-west-2.amazonaws.com/demo:kubes-2020-06-19T04-19-13 docker image.
|
15
15
|
Docker push took 15s.
|
16
16
|
Compiled .kubes/resources files
|
17
|
+
=> kubectl apply -f .kubes/output/shared/namespace.yaml
|
18
|
+
namespace/demo created
|
17
19
|
=> kubectl apply -f .kubes/output/web/service.yaml
|
18
20
|
service/demo-web created
|
19
21
|
=> kubectl apply -f .kubes/output/web/deployment.yaml
|
@@ -34,6 +36,9 @@ Example output:
|
|
34
36
|
|
35
37
|
$ kubes get
|
36
38
|
=> kubectl get --recursive -f .kubes/output
|
39
|
+
NAME STATUS AGE
|
40
|
+
namespace/demo Active 7s
|
41
|
+
|
37
42
|
NAME READY UP-TO-DATE AVAILABLE AGE
|
38
43
|
deployment.apps/demo-web 1/1 1 1 7s
|
39
44
|
|
@@ -19,6 +19,7 @@ Let's generate a starter project:
|
|
19
19
|
create .kubes/config/env/prod.rb
|
20
20
|
create .kubes/resources/base/all.yaml
|
21
21
|
create .kubes/resources/base/deployment.yaml
|
22
|
+
create .kubes/resources/shared/namespace.yaml
|
22
23
|
create .kubes/resources/web/deployment.yaml
|
23
24
|
create .kubes/resources/web/deployment/dev.yaml
|
24
25
|
create .kubes/resources/web/deployment/prod.yaml
|
@@ -4,7 +4,22 @@ title: Review Project
|
|
4
4
|
|
5
5
|
Let's review the resources.
|
6
6
|
|
7
|
-
##
|
7
|
+
## Namespace
|
8
|
+
|
9
|
+
We'll create a namespace for the app resources:
|
10
|
+
|
11
|
+
.kubes/resources/shared/namespace.yaml
|
12
|
+
|
13
|
+
```yaml
|
14
|
+
apiVersion: v1
|
15
|
+
kind: Namespace
|
16
|
+
metadata:
|
17
|
+
name: demo
|
18
|
+
labels:
|
19
|
+
app: demo
|
20
|
+
```
|
21
|
+
|
22
|
+
## Deployment
|
8
23
|
|
9
24
|
The `web/deployment.yaml` file is a little more interesting:
|
10
25
|
|
@@ -14,7 +29,7 @@ The `web/deployment.yaml` file is a little more interesting:
|
|
14
29
|
apiVersion: apps/v1
|
15
30
|
kind: Deployment
|
16
31
|
metadata:
|
17
|
-
name:
|
32
|
+
name: web
|
18
33
|
labels:
|
19
34
|
role: web
|
20
35
|
spec:
|
@@ -33,13 +48,13 @@ spec:
|
|
33
48
|
role: web
|
34
49
|
spec:
|
35
50
|
containers:
|
36
|
-
- name:
|
51
|
+
- name: web
|
37
52
|
image: <%= built_image %>
|
38
53
|
```
|
39
54
|
|
40
55
|
Notice the `<%= built_image %>`. Kubes processes the YAML files with ERB templating and replaces these tags. The `built_image` is a kubes helper method that refers to the latest Docker image built by Kubes. This spares you updating the image manually.
|
41
56
|
|
42
|
-
## Base
|
57
|
+
## Base Folder
|
43
58
|
|
44
59
|
Also let's check the files in the base folder.
|
45
60
|
|
@@ -47,7 +62,7 @@ Also let's check the files in the base folder.
|
|
47
62
|
|
48
63
|
```yaml
|
49
64
|
metadata:
|
50
|
-
namespace:
|
65
|
+
namespace: demo
|
51
66
|
```
|
52
67
|
|
53
68
|
.kubes/resources/base/deployment.yaml
|
@@ -68,6 +83,8 @@ spec:
|
|
68
83
|
|
69
84
|
The base folder files are processed first as a part of [Kubes Layering]({% link _docs/layering.md %}). This allows you to define common fields and keep your code DRY.
|
70
85
|
|
86
|
+
The `all.yaml` means all resources will use the demo namespace. The `deployment.yaml` adds common labels to all deployment resource kinds.
|
87
|
+
|
71
88
|
## Service Resource
|
72
89
|
|
73
90
|
Next, let's look at `service.yaml`
|
@@ -78,20 +95,19 @@ Next, let's look at `service.yaml`
|
|
78
95
|
apiVersion: v1
|
79
96
|
kind: Service
|
80
97
|
metadata:
|
81
|
-
name:
|
98
|
+
name: web
|
82
99
|
labels:
|
83
|
-
|
84
|
-
namespace: default
|
100
|
+
role: web
|
85
101
|
spec:
|
86
102
|
ports:
|
87
103
|
- port: 80
|
88
104
|
protocol: TCP
|
89
|
-
targetPort:
|
105
|
+
targetPort: <%= dockerfile_port %>
|
90
106
|
selector:
|
91
|
-
|
107
|
+
role: web
|
92
108
|
type: ClusterIP
|
93
109
|
```
|
94
110
|
|
95
|
-
|
111
|
+
The `dockerfile_port` helper returns the EXPOSE port in the Dockerfile. This spares you updating this manually, you only have to update the Dockerfile.
|
96
112
|
|
97
113
|
Next, we'll deploy the app.
|
@@ -6,7 +6,7 @@ Let's update the app. In this case, we don't need to update the Docker image, so
|
|
6
6
|
|
7
7
|
kubes apply
|
8
8
|
|
9
|
-
Here's what the output looks like
|
9
|
+
Here's what the output looks like. Note, the namespace is not shown for conciseness.
|
10
10
|
|
11
11
|
$ kubes apply
|
12
12
|
Compiled .kubes/resources files
|
@@ -15,7 +15,7 @@ This is where the `--repo` from `kubes init` got saved. The other options are c
|
|
15
15
|
|
16
16
|
## Dockerfie
|
17
17
|
|
18
|
-
The `Dockerfile` is a simple starter example that just runs nginx
|
18
|
+
The `Dockerfile` is a simple starter example that just runs nginx
|
19
19
|
|
20
20
|
Dockerfile:
|
21
21
|
|
@@ -23,3 +23,5 @@ Dockerfile:
|
|
23
23
|
FROM nginx
|
24
24
|
EXPOSE 80
|
25
25
|
CMD ["nginx", "-g", "daemon off;"]
|
26
|
+
|
27
|
+
Note: If your project already has a Dockerfile, kubes will use that instead of generating a starter one.
|
data/lib/kubes/cli/init.rb
CHANGED
@@ -49,7 +49,7 @@ class Kubes::CLI
|
|
49
49
|
ignores = %w[
|
50
50
|
.kubes/output
|
51
51
|
.kubes/state
|
52
|
-
]
|
52
|
+
].map {|l| "#{l}\n"} # the readlines will have lines with \n so keep consistent for processing
|
53
53
|
if File.exist?(".gitignore")
|
54
54
|
lines = IO.readlines(".gitignore")
|
55
55
|
if lines.detect { |l| l.include?('.kubes/output') }
|
@@ -61,7 +61,7 @@ class Kubes::CLI
|
|
61
61
|
lines = ignores
|
62
62
|
end
|
63
63
|
|
64
|
-
text = lines.join(
|
64
|
+
text = lines.join('')
|
65
65
|
IO.write(".gitignore", text)
|
66
66
|
puts "Updated .gitignore"
|
67
67
|
end
|
@@ -1,4 +1,19 @@
|
|
1
1
|
module Kubes::Compiler::Dsl::Core
|
2
2
|
module Helpers
|
3
|
+
def dockerfile_port
|
4
|
+
path = "#{Kubes.root}/Dockerfile"
|
5
|
+
File.exist?(path) ? parse_for_dockerfile_port(path) : 80
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
def parse_for_dockerfile_port(path)
|
10
|
+
lines = IO.read(path).split("\n")
|
11
|
+
expose_line = lines.find { |l| l =~ /^EXPOSE / }
|
12
|
+
if expose_line
|
13
|
+
md = expose_line.match(/EXPOSE (\d+)/)
|
14
|
+
port = md[1] if md
|
15
|
+
end
|
16
|
+
port ? port.to_i : 80
|
17
|
+
end
|
3
18
|
end
|
4
19
|
end
|
data/lib/kubes/version.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
namespace "
|
1
|
+
namespace "<%= app %>"
|
2
2
|
labels(app: "<%= app %>")
|
@@ -1,7 +1,9 @@
|
|
1
|
-
name "
|
1
|
+
name "web"
|
2
2
|
labels(role: "web")
|
3
3
|
|
4
4
|
replicas 1
|
5
5
|
image built_image # IE: user/<%= app %>:kubes-2020-06-13T19-55-16-43afc6e
|
6
6
|
|
7
|
+
# revisionHistoryLimit 1 # uncomment to reduce old ReplicaSets, default is 10 https://bit.ly/3hqrzyP
|
8
|
+
|
7
9
|
# More docs: kubes.guru/docs/dsl/deployment/
|
@@ -1,2 +1,2 @@
|
|
1
1
|
metadata:
|
2
|
-
namespace:
|
2
|
+
namespace: <%= app %>
|
@@ -1,14 +1,14 @@
|
|
1
1
|
apiVersion: v1
|
2
2
|
kind: Service
|
3
3
|
metadata:
|
4
|
-
name:
|
4
|
+
name: web
|
5
5
|
labels:
|
6
6
|
role: web
|
7
7
|
spec:
|
8
8
|
ports:
|
9
9
|
- port: 80
|
10
10
|
protocol: TCP
|
11
|
-
targetPort:
|
11
|
+
targetPort: <%%= dockerfile_port %>
|
12
12
|
selector:
|
13
13
|
role: web
|
14
14
|
type: ClusterIP
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -536,12 +536,14 @@ files:
|
|
536
536
|
- lib/templates/base/.kubes/config/env/prod.rb
|
537
537
|
- lib/templates/docker/Dockerfile
|
538
538
|
- lib/templates/dsl/.kubes/resources/base/all.rb.tt
|
539
|
-
- lib/templates/dsl/.kubes/resources/
|
539
|
+
- lib/templates/dsl/.kubes/resources/shared/namespace.rb.tt
|
540
|
+
- lib/templates/dsl/.kubes/resources/web/deployment.rb
|
540
541
|
- lib/templates/dsl/.kubes/resources/web/deployment/dev.rb
|
541
542
|
- lib/templates/dsl/.kubes/resources/web/deployment/prod.rb
|
542
|
-
- lib/templates/dsl/.kubes/resources/web/service.rb
|
543
|
+
- lib/templates/dsl/.kubes/resources/web/service.rb
|
543
544
|
- lib/templates/yaml/.kubes/resources/base/all.yaml.tt
|
544
545
|
- lib/templates/yaml/.kubes/resources/base/deployment.yaml.tt
|
546
|
+
- lib/templates/yaml/.kubes/resources/shared/namespace.yaml.tt
|
545
547
|
- lib/templates/yaml/.kubes/resources/web/deployment.yaml.tt
|
546
548
|
- lib/templates/yaml/.kubes/resources/web/deployment/dev.yaml
|
547
549
|
- lib/templates/yaml/.kubes/resources/web/deployment/prod.yaml
|