kubes 0.2.3 → 0.3.1
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/.dockerignore +4 -0
- data/CHANGELOG.md +17 -0
- data/Dockerfile +14 -0
- data/docs/_docs/auto-context.md +4 -4
- data/docs/_docs/ci/cloudbuild.md +69 -0
- data/docs/_docs/config/builder.md +46 -0
- data/docs/_docs/config/env.md +3 -3
- data/docs/_docs/dsl/resources/service.md +21 -5
- data/docs/_docs/learn/dsl/deploy.md +2 -0
- data/docs/_docs/learn/dsl/new-project.md +1 -2
- data/docs/_docs/learn/yaml/deploy.md +2 -0
- data/docs/_docs/learn/yaml/new-project.md +1 -1
- data/docs/_includes/intro/install.md +5 -1
- data/docs/_includes/learn/cluster.md +21 -4
- data/docs/_includes/learn/repo +0 -0
- data/docs/_includes/learn/repos.md +10 -0
- data/docs/_includes/learn/review.md +2 -2
- data/docs/_includes/sidebar.html +6 -0
- data/docs/_reference/kubes-apply.md +2 -2
- data/docs/_reference/kubes-delete.md +1 -1
- data/docs/_reference/kubes-deploy.md +1 -1
- data/docs/_reference/kubes-describe.md +24 -0
- data/docs/_reference/kubes-exec.md +42 -0
- data/docs/_reference/kubes-get.md +27 -0
- data/docs/_reference/kubes-init.md +1 -1
- data/docs/_reference/kubes-logs.md +26 -0
- data/docs/bin/web +1 -1
- data/docs/reference.md +4 -0
- data/lib/kubes/cli.rb +22 -0
- data/lib/kubes/cli/apply.rb +1 -1
- data/lib/kubes/cli/base.rb +4 -0
- data/lib/kubes/cli/build.rb +2 -2
- data/lib/kubes/cli/delete.rb +7 -2
- data/lib/kubes/cli/describe.rb +1 -1
- data/lib/kubes/cli/docker.rb +2 -2
- data/lib/kubes/cli/exec.rb +34 -0
- data/lib/kubes/cli/get.rb +3 -1
- data/lib/kubes/cli/help/exec.md +24 -0
- data/lib/kubes/cli/logs.rb +13 -0
- data/lib/kubes/compiler/dsl/syntax/deployment.rb +85 -2
- data/lib/kubes/compiler/dsl/syntax/service.rb +11 -0
- data/lib/kubes/compiler/shared/helpers.rb +2 -1
- data/lib/kubes/config.rb +2 -0
- data/lib/kubes/docker.rb +19 -0
- data/lib/kubes/docker/strategy/build/base.rb +24 -0
- data/lib/kubes/docker/strategy/build/docker.rb +11 -0
- data/lib/kubes/docker/strategy/build/gcloud.rb +10 -0
- data/lib/kubes/docker/strategy/hooks.rb +9 -0
- data/lib/kubes/docker/{base.rb → strategy/image_name.rb} +19 -32
- data/lib/kubes/docker/strategy/push/base.rb +9 -0
- data/lib/kubes/docker/{push.rb → strategy/push/docker.rb} +2 -5
- data/lib/kubes/docker/strategy/push/gcloud.rb +9 -0
- data/lib/kubes/docker/strategy/utils.rb +9 -0
- data/lib/kubes/hooks/builder.rb +2 -1
- data/lib/kubes/kubectl.rb +15 -3
- data/lib/kubes/kubectl/batch.rb +8 -1
- data/lib/kubes/kubectl/fetch/base.rb +24 -0
- data/lib/kubes/kubectl/fetch/deployment.rb +34 -0
- data/lib/kubes/kubectl/fetch/pods.rb +21 -0
- data/lib/kubes/util/sh.rb +1 -0
- data/lib/kubes/version.rb +1 -1
- data/lib/templates/dsl/.kubes/resources/web/deployment.rb +2 -1
- data/lib/templates/dsl/.kubes/resources/web/service.rb +1 -1
- metadata +28 -5
- data/lib/kubes/docker/build.rb +0 -22
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
title: kubes describe
|
3
|
+
reference: true
|
4
|
+
---
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
kubes describe [ROLE] [RESOURCE]
|
9
|
+
|
10
|
+
## Description
|
11
|
+
|
12
|
+
Describe Kubernetes resource using the compiled YAML files
|
13
|
+
|
14
|
+
|
15
|
+
## Options
|
16
|
+
|
17
|
+
```
|
18
|
+
[--image=IMAGE] # override image
|
19
|
+
[--compile], [--no-compile] # whether or not to compile the .kube/resources
|
20
|
+
# Default: true
|
21
|
+
[--verbose], [--no-verbose]
|
22
|
+
[--noop], [--no-noop]
|
23
|
+
```
|
24
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
---
|
2
|
+
title: kubes exec
|
3
|
+
reference: true
|
4
|
+
---
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
kubes exec
|
9
|
+
|
10
|
+
## Description
|
11
|
+
|
12
|
+
Exec into the latest container from the deployment
|
13
|
+
|
14
|
+
The exec command finds the latest pod from the deployment and runs `kubectl exec -ti POD bash` to get you into it. It spares you from having to manually find and type it.
|
15
|
+
|
16
|
+
## Examples
|
17
|
+
|
18
|
+
kubes exec
|
19
|
+
kubes exec sh
|
20
|
+
kubes exec ls -l
|
21
|
+
|
22
|
+
## Multiple Deployments
|
23
|
+
|
24
|
+
If you have have multiple deployments in your `.kubes/resources` then the command will use the first deployment by default. You can specify the specfic deployment with the `--name` option. Examples:
|
25
|
+
|
26
|
+
kubes exec --name demo-web
|
27
|
+
kubes exec --name demo-clock
|
28
|
+
kubes exec --name demo-worker
|
29
|
+
kubes exec --name demo-web sh
|
30
|
+
kubes exec --name demo-web ls -l
|
31
|
+
|
32
|
+
|
33
|
+
## Options
|
34
|
+
|
35
|
+
```
|
36
|
+
[--compile], [--no-compile] # whether or not to compile the .kube/resources
|
37
|
+
# Default: true
|
38
|
+
n, [--name=NAME] # deployment name to use. IE: demo-web
|
39
|
+
[--verbose], [--no-verbose]
|
40
|
+
[--noop], [--no-noop]
|
41
|
+
```
|
42
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
title: kubes get
|
3
|
+
reference: true
|
4
|
+
---
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
kubes get [ROLE] [RESOURCE]
|
9
|
+
|
10
|
+
## Description
|
11
|
+
|
12
|
+
Get Kubernetes resource using the compiled YAML files
|
13
|
+
|
14
|
+
|
15
|
+
## Options
|
16
|
+
|
17
|
+
```
|
18
|
+
[--image=IMAGE] # override image
|
19
|
+
[--compile], [--no-compile] # whether or not to compile the .kube/resources
|
20
|
+
# Default: true
|
21
|
+
o, [--output=OUTPUT] # Output format: json|yaml|wide|name
|
22
|
+
[--show-pods], [--no-show-pods] # Also show pods from deployments
|
23
|
+
# Default: true
|
24
|
+
[--verbose], [--no-verbose]
|
25
|
+
[--noop], [--no-noop]
|
26
|
+
```
|
27
|
+
|
@@ -15,7 +15,7 @@ Init project
|
|
15
15
|
## Options
|
16
16
|
|
17
17
|
```
|
18
|
-
a, --app=APP # Docker repo name. Example:
|
18
|
+
a, --app=APP # Docker repo name. Example: web. Generates .kubes/APP/resources folder
|
19
19
|
[--force] # Bypass overwrite are you sure prompt for existing files
|
20
20
|
t, [--type=TYPE] # Type: dsl or yaml
|
21
21
|
# Default: yaml
|
@@ -0,0 +1,26 @@
|
|
1
|
+
---
|
2
|
+
title: kubes logs
|
3
|
+
reference: true
|
4
|
+
---
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
kubes logs
|
9
|
+
|
10
|
+
## Description
|
11
|
+
|
12
|
+
logs from all deployment pods
|
13
|
+
|
14
|
+
|
15
|
+
## Options
|
16
|
+
|
17
|
+
```
|
18
|
+
[--compile], [--no-compile] # whether or not to compile the .kube/resources
|
19
|
+
# Default: true
|
20
|
+
n, [--name=NAME] # deployment name to use. IE: demo-web
|
21
|
+
f, [--follow], [--no-follow] # Follow logs
|
22
|
+
# Default: true
|
23
|
+
[--verbose], [--no-verbose]
|
24
|
+
[--noop], [--no-noop]
|
25
|
+
```
|
26
|
+
|
data/docs/bin/web
CHANGED
data/docs/reference.md
CHANGED
@@ -10,6 +10,10 @@ title: CLI Reference
|
|
10
10
|
* [kubes completion_script]({% link _reference/kubes-completion_script.md %})
|
11
11
|
* [kubes delete]({% link _reference/kubes-delete.md %})
|
12
12
|
* [kubes deploy]({% link _reference/kubes-deploy.md %})
|
13
|
+
* [kubes describe]({% link _reference/kubes-describe.md %})
|
13
14
|
* [kubes docker]({% link _reference/kubes-docker.md %})
|
15
|
+
* [kubes exec]({% link _reference/kubes-exec.md %})
|
16
|
+
* [kubes get]({% link _reference/kubes-get.md %})
|
14
17
|
* [kubes init]({% link _reference/kubes-init.md %})
|
18
|
+
* [kubes logs]({% link _reference/kubes-logs.md %})
|
15
19
|
* [kubes version]({% link _reference/kubes-version.md %})
|
data/lib/kubes/cli.rb
CHANGED
@@ -9,6 +9,9 @@ module Kubes
|
|
9
9
|
compile_option = Proc.new {
|
10
10
|
option :compile, type: :boolean, default: true, desc: "whether or not to compile the .kube/resources"
|
11
11
|
}
|
12
|
+
name_option = Proc.new {
|
13
|
+
option :name, aliases: %w[n], desc: "deployment name to use. IE: demo-web"
|
14
|
+
}
|
12
15
|
|
13
16
|
desc "docker SUBCOMMAND", "Docker subcommands"
|
14
17
|
long_desc Help.text(:docker)
|
@@ -60,15 +63,34 @@ module Kubes
|
|
60
63
|
Describe.new(options.merge(role: role, resource: resource)).run
|
61
64
|
end
|
62
65
|
|
66
|
+
desc "exec", "Exec into the latest container from the deployment"
|
67
|
+
long_desc Help.text(:exec)
|
68
|
+
compile_option.call
|
69
|
+
name_option.call
|
70
|
+
option :container, aliases: %w[c], desc: "Container name. If omitted, the first container in the pod will be chosen"
|
71
|
+
def exec(*cmd)
|
72
|
+
Exec.new(options.merge(cmd: cmd)).run
|
73
|
+
end
|
74
|
+
|
63
75
|
desc "get [ROLE] [RESOURCE]", "Get Kubernetes resource using the compiled YAML files"
|
64
76
|
long_desc Help.text(:get)
|
65
77
|
image_option.call
|
66
78
|
compile_option.call
|
67
79
|
option :output, aliases: %w[o], desc: "Output format: json|yaml|wide|name"
|
80
|
+
option :show_pods, type: :boolean, default: true, desc: "Also show pods from deployments"
|
68
81
|
def get(role=nil, resource=nil)
|
69
82
|
Get.new(options.merge(role: role, resource: resource)).run
|
70
83
|
end
|
71
84
|
|
85
|
+
desc "logs", "logs from all deployment pods"
|
86
|
+
long_desc Help.text(:logs)
|
87
|
+
compile_option.call
|
88
|
+
name_option.call
|
89
|
+
option :follow, aliases: %w[f], type: :boolean, default: true, desc: "Follow logs"
|
90
|
+
def logs(*cmd)
|
91
|
+
Logs.new(options.merge(cmd: cmd)).run
|
92
|
+
end
|
93
|
+
|
72
94
|
long_desc Help.text(:init)
|
73
95
|
Init.options.each { |args| option(*args) }
|
74
96
|
register(Init, "init", "init", "Init project")
|
data/lib/kubes/cli/apply.rb
CHANGED
data/lib/kubes/cli/base.rb
CHANGED
data/lib/kubes/cli/build.rb
CHANGED
data/lib/kubes/cli/delete.rb
CHANGED
@@ -3,9 +3,14 @@ class Kubes::CLI
|
|
3
3
|
include Kubes::Util::Sure
|
4
4
|
|
5
5
|
def run
|
6
|
+
compile
|
7
|
+
perform(preview: true) unless @options[:yes]
|
6
8
|
sure?("This will delete resources. Are you sure?")
|
7
|
-
|
8
|
-
|
9
|
+
perform(preview: false)
|
10
|
+
end
|
11
|
+
|
12
|
+
def perform(preview: false)
|
13
|
+
Kubes::Kubectl::Decider.new(:delete, @options.merge(preview: preview)).run
|
9
14
|
end
|
10
15
|
end
|
11
16
|
end
|
data/lib/kubes/cli/describe.rb
CHANGED
data/lib/kubes/cli/docker.rb
CHANGED
@@ -4,7 +4,7 @@ class Kubes::CLI
|
|
4
4
|
long_desc Help.text("docker:build")
|
5
5
|
option :push, type: :boolean, default: false
|
6
6
|
def build
|
7
|
-
builder = Kubes::Docker
|
7
|
+
builder = Kubes::Docker.new(options, "build")
|
8
8
|
builder.run
|
9
9
|
push if options[:push]
|
10
10
|
end
|
@@ -13,7 +13,7 @@ class Kubes::CLI
|
|
13
13
|
long_desc Help.text("docker:push")
|
14
14
|
option :push, type: :boolean, default: false
|
15
15
|
def push
|
16
|
-
pusher = Kubes::Docker
|
16
|
+
pusher = Kubes::Docker.new(options, "push")
|
17
17
|
pusher.run
|
18
18
|
end
|
19
19
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Kubes::CLI
|
2
|
+
class Exec < Base
|
3
|
+
include Kubes::Util::Sh
|
4
|
+
|
5
|
+
def run
|
6
|
+
compile
|
7
|
+
metadata = Kubes::Kubectl::Fetch::Deployment.new(@options).metadata
|
8
|
+
|
9
|
+
labels = metadata['labels'].map { |k,v| "#{k}=#{v}" }.join(',')
|
10
|
+
ns = metadata['namespace']
|
11
|
+
|
12
|
+
resp = capture("kubectl get pod -l #{labels} -n #{ns} -o json")
|
13
|
+
data = JSON.load(resp)
|
14
|
+
pod = latest_pod(data['items'])
|
15
|
+
|
16
|
+
unless pod
|
17
|
+
logger.error "ERROR: Unable to find a running pod".color(:red)
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
|
21
|
+
name = pod['metadata']['name']
|
22
|
+
container = " -c #{@options[:container]}" unless @options[:container].nil?
|
23
|
+
cmd = @options[:cmd].empty? ? "bash" : @options[:cmd].join(' ')
|
24
|
+
sh("kubectl exec -n #{ns} -ti #{name}#{container} -- #{cmd}")
|
25
|
+
end
|
26
|
+
|
27
|
+
# get latest running pod
|
28
|
+
def latest_pod(items)
|
29
|
+
running = items.select { |i| i['status']['phase'] == 'Running' }
|
30
|
+
sorted = running.sort_by { |i| i['metadata']['creationTimestamp'] || 0 }
|
31
|
+
sorted.last
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/kubes/cli/get.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
class Kubes::CLI
|
2
2
|
class Get < Base
|
3
3
|
def run
|
4
|
-
|
4
|
+
compile
|
5
5
|
Kubes::Kubectl.run(:get, @options)
|
6
|
+
pods = Kubes::Kubectl::Fetch::Pods.new(@options)
|
7
|
+
pods.show if @options[:show_pods]
|
6
8
|
end
|
7
9
|
end
|
8
10
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
The exec command finds the latest pod from the deployment and runs `kubectl exec -ti POD bash` to get you into it. It spares you from having to manually find and type it.
|
2
|
+
|
3
|
+
## Examples
|
4
|
+
|
5
|
+
kubes exec
|
6
|
+
kubes exec sh
|
7
|
+
kubes exec ls -l
|
8
|
+
|
9
|
+
## Multiple Deployments
|
10
|
+
|
11
|
+
If you have have multiple deployments in your `.kubes/resources` then the command will use the first deployment by default. You can specify the specfic deployment with the `--name` or `-n` option. Examples:
|
12
|
+
|
13
|
+
kubes exec --name web
|
14
|
+
kubes exec -n web
|
15
|
+
kubes exec -n clock
|
16
|
+
kubes exec -n worker
|
17
|
+
kubes exec -n web sh
|
18
|
+
kubes exec -n web ls -l
|
19
|
+
|
20
|
+
## Multiple Pod Containers
|
21
|
+
|
22
|
+
If you have have multiple containers in your pod. You can specify the specfic container with the `--container` or `-c` option. Examples:
|
23
|
+
|
24
|
+
kubes exec --name web
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Kubes::CLI
|
2
|
+
class Logs < Base
|
3
|
+
include Kubes::Util::Sh
|
4
|
+
|
5
|
+
def run
|
6
|
+
compile
|
7
|
+
metadata = Kubes::Kubectl::Fetch::Deployment.new(@options).metadata
|
8
|
+
name = metadata['name']
|
9
|
+
follow = " -f" if @options[:follow]
|
10
|
+
sh("kubectl logs deployment/#{name}#{follow}")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Kubes::Compiler::Dsl::Syntax
|
2
2
|
class Deployment < Resource
|
3
3
|
fields :container, # <Object>
|
4
|
-
:containers, # <[]Object>
|
5
4
|
"matchLabels:hash", # <map[string]string>
|
6
5
|
:sidecar, # <Object>
|
6
|
+
:sidecar_name, # <string>
|
7
|
+
:sidecar_image, # <string>
|
7
8
|
:templateMetadata, # <Object>
|
8
9
|
:templateSpec # <Object>
|
9
10
|
|
@@ -21,6 +22,42 @@ module Kubes::Compiler::Dsl::Syntax
|
|
21
22
|
fields :maxSurge, # <string>
|
22
23
|
:maxUnavailable # <string>
|
23
24
|
|
25
|
+
# kubectl explain deploy.spec.template.spec
|
26
|
+
fields :activeDeadlineSeconds, # <integer>
|
27
|
+
:affinity, # <Object>
|
28
|
+
:automountServiceAccountToken, # <boolean>
|
29
|
+
:containers, # <[]Object> -required-
|
30
|
+
:dnsConfig, # <Object>
|
31
|
+
:dnsPolicy, # <string>
|
32
|
+
:enableServiceLinks, # <boolean>
|
33
|
+
:ephemeralContainers, # <[]Object>
|
34
|
+
:hostAliases, # <[]Object>
|
35
|
+
:hostIPC, # <boolean>
|
36
|
+
:hostNetwork, # <boolean>
|
37
|
+
:hostPID, # <boolean>
|
38
|
+
:hostname, # <string>
|
39
|
+
:imagePullSecrets, # <[]Object>
|
40
|
+
:initContainers, # <[]Object>
|
41
|
+
:nodeName, # <string>
|
42
|
+
:nodeSelector, # <map[string]string>
|
43
|
+
:overhead, # <map[string]string>
|
44
|
+
:preemptionPolicy, # <string>
|
45
|
+
:priority, # <integer>
|
46
|
+
:priorityClassName, # <string>
|
47
|
+
:readinessGates, # <[]Object>
|
48
|
+
:restartPolicy, # <string>
|
49
|
+
:runtimeClassName, # <string>
|
50
|
+
:schedulerName, # <string>
|
51
|
+
:securityContext, # <Object>
|
52
|
+
:serviceAccount, # <string>
|
53
|
+
:serviceAccountName, # <string>
|
54
|
+
:shareProcessNamespace, # <boolean>
|
55
|
+
:subdomain, # <string>
|
56
|
+
:terminationGracePeriodSeconds,# <integer>
|
57
|
+
:tolerations, # <[]Object>
|
58
|
+
:topologySpreadConstraints, # <[]Object>
|
59
|
+
:volumes # <[]Object>
|
60
|
+
|
24
61
|
# kubectl explain deployment.spec.template.spec.containers
|
25
62
|
fields :args, # <[]string>
|
26
63
|
:command, # <[]string>
|
@@ -104,7 +141,42 @@ module Kubes::Compiler::Dsl::Syntax
|
|
104
141
|
end
|
105
142
|
|
106
143
|
def default_templateSpec
|
107
|
-
{
|
144
|
+
{
|
145
|
+
activeDeadlineSeconds: activeDeadlineSeconds,
|
146
|
+
affinity: affinity,
|
147
|
+
automountServiceAccountToken: automountServiceAccountToken,
|
148
|
+
containers: containers,
|
149
|
+
dnsConfig: dnsConfig,
|
150
|
+
dnsPolicy: dnsPolicy,
|
151
|
+
enableServiceLinks: enableServiceLinks,
|
152
|
+
ephemeralContainers: ephemeralContainers,
|
153
|
+
hostAliases: hostAliases,
|
154
|
+
hostIPC: hostIPC,
|
155
|
+
hostNetwork: hostNetwork,
|
156
|
+
hostPID: hostPID,
|
157
|
+
hostname: hostname,
|
158
|
+
imagePullSecrets: imagePullSecrets,
|
159
|
+
initContainers: initContainers,
|
160
|
+
nodeName: nodeName,
|
161
|
+
nodeSelector: nodeSelector,
|
162
|
+
overhead: overhead,
|
163
|
+
preemptionPolicy: preemptionPolicy,
|
164
|
+
priority: priority,
|
165
|
+
priorityClassName: priorityClassName,
|
166
|
+
readinessGates: readinessGates,
|
167
|
+
restartPolicy: restartPolicy,
|
168
|
+
runtimeClassName: runtimeClassName,
|
169
|
+
schedulerName: schedulerName,
|
170
|
+
securityContext: securityContext,
|
171
|
+
serviceAccount: serviceAccount,
|
172
|
+
serviceAccountName: serviceAccountName,
|
173
|
+
shareProcessNamespace: shareProcessNamespace,
|
174
|
+
subdomain: subdomain,
|
175
|
+
terminationGracePeriodSeconds: terminationGracePeriodSeconds,
|
176
|
+
tolerations: tolerations,
|
177
|
+
topologySpreadConstraints: topologySpreadConstraints,
|
178
|
+
volumes: volumes,
|
179
|
+
}
|
108
180
|
end
|
109
181
|
|
110
182
|
def default_templateMetadata
|
@@ -115,6 +187,17 @@ module Kubes::Compiler::Dsl::Syntax
|
|
115
187
|
[container, sidecar].compact
|
116
188
|
end
|
117
189
|
|
190
|
+
def default_sidecar
|
191
|
+
{
|
192
|
+
name: sidecar_name,
|
193
|
+
image: sidecar_image,
|
194
|
+
}
|
195
|
+
end
|
196
|
+
|
197
|
+
def default_sidecar_name
|
198
|
+
"sidecar" if sidecar_image # othewise will create invalid sidecar field w/o image
|
199
|
+
end
|
200
|
+
|
118
201
|
def default_container
|
119
202
|
{
|
120
203
|
args: args,
|