kubes 0.2.6 → 0.3.4
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 +18 -0
- data/docs/_config.yml +1 -1
- data/docs/_docs/auto-context.md +4 -4
- 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 -2
- data/docs/_includes/commands.html +2 -0
- 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/_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/_sass/theme.scss +2 -1
- data/docs/bin/web +1 -1
- data/docs/img/logos/kubes-white.png +0 -0
- data/docs/index.html +2 -2
- data/docs/reference.md +4 -0
- data/lib/kubes/cli.rb +26 -0
- data/lib/kubes/cli/apply.rb +1 -1
- data/lib/kubes/cli/base.rb +4 -0
- data/lib/kubes/cli/delete.rb +7 -2
- data/lib/kubes/cli/describe.rb +1 -1
- 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/init.rb +34 -2
- data/lib/kubes/cli/logs.rb +38 -0
- data/lib/kubes/compiler/dsl/syntax/deployment.rb +85 -2
- data/lib/kubes/compiler/dsl/syntax/service.rb +11 -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 +45 -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/base/all.rb.tt +6 -1
- data/lib/templates/dsl/.kubes/resources/shared/namespace.rb.tt +1 -1
- data/lib/templates/dsl/.kubes/resources/web/deployment.rb +2 -1
- data/lib/templates/dsl/.kubes/resources/web/service.rb +1 -1
- data/lib/templates/yaml/.kubes/resources/base/all.yaml.tt +1 -1
- data/lib/templates/yaml/.kubes/resources/shared/namespace.yaml.tt +1 -1
- metadata +15 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c14d045b8c029e76e1c001f26a0b77c97ecdabc45ddc964660372f2170f95690
|
|
4
|
+
data.tar.gz: 36a0b622a75cc18e74d78537a2a3f421e15de150cb89978434a58d31c37b799b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cd0f40a09c2909be4820c0575d6a8ef850b1977e21cd5d040cb82cb11411500a136608035635f743cb1a967116913856fc5e7997f3fef511b5c07d94d5fe4458
|
|
7
|
+
data.tar.gz: 9f29e9bf7a4615bb2a9864b9acdc9aa83b70583b5743decd5e8c6bac1b85b49bfc90a724403765afe2a86fa1cd1819cccedc53b7b91d6e858a20ececf2630f6a
|
data/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
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.3.4]
|
|
7
|
+
- #24 fix namespace newline and logs for single container
|
|
8
|
+
- #23 init namespace option
|
|
9
|
+
|
|
10
|
+
## [0.3.3]
|
|
11
|
+
- #22 logs -c option. fix kubes logs for pods with multiple containers
|
|
12
|
+
|
|
13
|
+
## [0.3.2]
|
|
14
|
+
- #21 add namespace to logs command
|
|
15
|
+
|
|
16
|
+
## [0.3.1]
|
|
17
|
+
- #20 improve sidecar support. kubes exec -c option also
|
|
18
|
+
|
|
19
|
+
## [0.3.0]
|
|
20
|
+
- #19 new commands: exec, logs
|
|
21
|
+
- delete preview
|
|
22
|
+
- show pods as part of get
|
|
23
|
+
|
|
6
24
|
## [0.2.6]
|
|
7
25
|
- #18 gcloud builder. change to config.builder
|
|
8
26
|
|
data/docs/_config.yml
CHANGED
|
@@ -9,7 +9,7 @@ meta_author: Tung Nguyen
|
|
|
9
9
|
|
|
10
10
|
# Google webmaster tools
|
|
11
11
|
google_verify:
|
|
12
|
-
google_analytics: "
|
|
12
|
+
google_analytics: "UA-98684555-14"
|
|
13
13
|
|
|
14
14
|
# https://ssl.bing.com/webmaster/configure/verify/ownership Option 2 content= goes here
|
|
15
15
|
bing_verify:
|
data/docs/_docs/auto-context.md
CHANGED
|
@@ -22,7 +22,7 @@ You can override configs on a per-env basis with `config/env` files. Examples:
|
|
|
22
22
|
```ruby
|
|
23
23
|
Kubes.configure do |config|
|
|
24
24
|
config.repo = "222222222222.dkr.ecr.us-west-2.amazonaws.com/demo"
|
|
25
|
-
config.kubectl.context = "dev-
|
|
25
|
+
config.kubectl.context = "dev-cluster"
|
|
26
26
|
end
|
|
27
27
|
```
|
|
28
28
|
|
|
@@ -31,7 +31,7 @@ end
|
|
|
31
31
|
```ruby
|
|
32
32
|
Kubes.configure do |config|
|
|
33
33
|
config.repo = "333333333333.dkr.ecr.us-west-2.amazonaws.com/demo"
|
|
34
|
-
config.kubectl.context = "prod-
|
|
34
|
+
config.kubectl.context = "prod-cluster"
|
|
35
35
|
end
|
|
36
36
|
```
|
|
37
37
|
|
|
@@ -39,8 +39,8 @@ end
|
|
|
39
39
|
|
|
40
40
|
With this setup, when you deploy with kubes, it will automatically switch the kubectl context based on `KUBES_ENV`. Example:
|
|
41
41
|
|
|
42
|
-
KUBES_ENV=dev kubes deploy # to dev-
|
|
43
|
-
KUBES_ENV=prod kubes deploy # to prod-
|
|
42
|
+
KUBES_ENV=dev kubes deploy # to dev-cluster context
|
|
43
|
+
KUBES_ENV=prod kubes deploy # to prod-cluster context
|
|
44
44
|
|
|
45
45
|
## context_keep Option
|
|
46
46
|
|
data/docs/_docs/config/env.md
CHANGED
|
@@ -11,7 +11,7 @@ Kubes.configure do |config|
|
|
|
11
11
|
config.repo = "111111111111.dkr.ecr.us-west-2.amazonaws.com/demo"
|
|
12
12
|
config.logger.level = "info"
|
|
13
13
|
# auto-switching
|
|
14
|
-
# config.kubectl.context = "dev-
|
|
14
|
+
# config.kubectl.context = "dev-cluster"
|
|
15
15
|
# config.kubectl.context_keep = false
|
|
16
16
|
end
|
|
17
17
|
```
|
|
@@ -25,7 +25,7 @@ You can override configs on a per-env basis with `config/env` files. Examples:
|
|
|
25
25
|
```ruby
|
|
26
26
|
Kubes.configure do |config|
|
|
27
27
|
config.repo = "222222222222.dkr.ecr.us-west-2.amazonaws.com/demo"
|
|
28
|
-
config.kubectl.context = "dev-
|
|
28
|
+
config.kubectl.context = "dev-cluster"
|
|
29
29
|
end
|
|
30
30
|
```
|
|
31
31
|
|
|
@@ -34,7 +34,7 @@ end
|
|
|
34
34
|
```ruby
|
|
35
35
|
Kubes.configure do |config|
|
|
36
36
|
config.repo = "333333333333.dkr.ecr.us-west-2.amazonaws.com/demo"
|
|
37
|
-
config.kubectl.context = "prod-
|
|
37
|
+
config.kubectl.context = "prod-cluster"
|
|
38
38
|
end
|
|
39
39
|
```
|
|
40
40
|
|
|
@@ -46,15 +46,31 @@ spec:
|
|
|
46
46
|
|
|
47
47
|
## DSL Methods
|
|
48
48
|
|
|
49
|
-
Here's a list of
|
|
49
|
+
Here's a list of some of the methods:
|
|
50
|
+
|
|
51
|
+
kubectl explain service.spec
|
|
52
|
+
|
|
53
|
+
* clusterIP
|
|
54
|
+
* externalIPs
|
|
55
|
+
* externalName
|
|
56
|
+
* externalTrafficPolicy
|
|
57
|
+
* healthCheckNodePort
|
|
58
|
+
* ipFamily
|
|
59
|
+
* loadBalancerIP
|
|
60
|
+
* loadBalancerSourceRanges
|
|
61
|
+
* ports
|
|
62
|
+
* publishNotReadyAddresses
|
|
63
|
+
* selector
|
|
64
|
+
* sessionAffinity
|
|
65
|
+
* sessionAffinityConfig
|
|
66
|
+
* type
|
|
67
|
+
|
|
68
|
+
kubectl explain service.spec.ports
|
|
50
69
|
|
|
51
70
|
* nodePort
|
|
52
71
|
* port
|
|
53
|
-
* portName: Note this field doesn't match the original field name. It's more qualified.
|
|
54
|
-
* ports
|
|
72
|
+
* portName: : Note this field doesn't match the original field name. It's more qualified.
|
|
55
73
|
* protocol
|
|
56
|
-
* selector
|
|
57
74
|
* targetPort
|
|
58
|
-
* type
|
|
59
75
|
|
|
60
76
|
{% include dsl/methods.md name="service" %}
|
|
@@ -7,11 +7,10 @@ If you already a project with an existing Dockerfile, you can use that. If you d
|
|
|
7
7
|
mkdir demo
|
|
8
8
|
cd demo
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
{% include learn/repos.md %}
|
|
11
11
|
|
|
12
12
|
Let's generate a starter project:
|
|
13
13
|
|
|
14
|
-
$ REPO=$(aws ecr describe-repositories --repository-name demo | jq -r '.repositories[].repositoryUri')
|
|
15
14
|
$ kubes init --app demo --repo $REPO --type dsl
|
|
16
15
|
create .kubes/config.rb
|
|
17
16
|
create .kubes/config/env/dev.rb
|
|
@@ -7,11 +7,10 @@ If you already a project with an existing Dockerfile, you can use that. If you d
|
|
|
7
7
|
mkdir demo
|
|
8
8
|
cd demo
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
{% include learn/repos.md %}
|
|
11
11
|
|
|
12
12
|
Let's generate a starter project:
|
|
13
13
|
|
|
14
|
-
$ REPO=$(aws ecr describe-repositories --repository-name demo | jq -r '.repositories[].repositoryUri')
|
|
15
14
|
$ kubes init --app demo --repo $REPO
|
|
16
15
|
create Dockerfile
|
|
17
16
|
create .kubes/config.rb
|
|
@@ -4,7 +4,7 @@ Install kubes via RubyGems.
|
|
|
4
4
|
|
|
5
5
|
gem install kubes
|
|
6
6
|
|
|
7
|
-
Ruby 2.7 and
|
|
7
|
+
Ruby 2.7 and above is recommended.
|
|
8
8
|
|
|
9
9
|
## kubectl
|
|
10
10
|
|
|
@@ -13,3 +13,7 @@ Kubes calls kubectl. Kubes has been tested with kubectl v1.15+. Generally, it sh
|
|
|
13
13
|
## docker
|
|
14
14
|
|
|
15
15
|
Kubes calls docker. Kubes has been tested with docker 18.x-ce+. Generally, it should work with most versions of docker.
|
|
16
|
+
|
|
17
|
+
## gcloud
|
|
18
|
+
|
|
19
|
+
If you are using the [gcloud builder](% link _docs/config/builder.md %), set up and configure the [gcloud cli](https://cloud.google.com/sdk/install).
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
You'll need a Kubernetes cluster and a Docker repo to be able to push to. Setting up a Kubernetes cluster is a little bit out scope for this tutorial. We'll provide the docs and links though. We'll
|
|
1
|
+
You'll need a Kubernetes cluster and a Docker repo to be able to push to. Setting up a Kubernetes cluster is a little bit out scope for this tutorial. We'll provide the docs and links though. We'll provide instructions for AWS and Google.
|
|
2
2
|
|
|
3
|
-
## Create an EKS cluster
|
|
3
|
+
## AWS: Create an EKS cluster
|
|
4
4
|
|
|
5
5
|
Here are the AWS docs to create an EKS cluster:
|
|
6
6
|
|
|
7
7
|
* [Creating an Amazon EKS cluster](https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html)
|
|
8
8
|
|
|
9
|
-
## Create an ECR Repo
|
|
9
|
+
## AWS: Create an ECR Repo
|
|
10
10
|
|
|
11
11
|
Here are the AWS docs to create a repo:
|
|
12
12
|
|
|
@@ -19,4 +19,21 @@ Here are also the commands to create an ECR repo:
|
|
|
19
19
|
|
|
20
20
|
We'll be using the `$REPO` variable for the rest of the tutorial.
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
## Google: Create GKE Cluster
|
|
23
|
+
|
|
24
|
+
Here are the Google docs to create an GKE cluster:
|
|
25
|
+
|
|
26
|
+
* [Creating an Google GKE cluster](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-regional-cluster)
|
|
27
|
+
|
|
28
|
+
## Google: GCR Repo
|
|
29
|
+
|
|
30
|
+
For google, you do not have to create a repo. You simply push to the right repo url. Example:
|
|
31
|
+
|
|
32
|
+
export GOOGLE_PROJECT=project-123
|
|
33
|
+
REPO=gcr.io/$GOOGLE_PROJECT/demo
|
|
34
|
+
|
|
35
|
+
## Repo Variable
|
|
36
|
+
|
|
37
|
+
We'll be using the `$REPO` variable for the rest of the tutorial.
|
|
38
|
+
|
|
39
|
+
Note: Though we're using AWS and Google here, Kubes works with any Cloud Provider. Please adjust your commands and the `$REPO` variable for your cloud provider.
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
For this tutorial, here are examples of AWS ECR and Google GCR repos, though any repo will work.
|
|
2
|
+
|
|
3
|
+
AWS:
|
|
4
|
+
|
|
5
|
+
REPO=$(aws ecr describe-repositories --repository-name demo | jq -r '.repositories[].repositoryUri')
|
|
6
|
+
|
|
7
|
+
Google:
|
|
8
|
+
|
|
9
|
+
export GOOGLE_PROJECT=project-123
|
|
10
|
+
REPO=gcr.io/$GOOGLE_PROJECT/demo
|
|
@@ -4,10 +4,10 @@ The `config.rb` is where you can configure Kubes settings.
|
|
|
4
4
|
|
|
5
5
|
```ruby
|
|
6
6
|
Kubes.configure do |config|
|
|
7
|
-
config.repo = "112233445566.dkr.ecr.us-west-2.amazonaws.com/demo"
|
|
7
|
+
config.repo = "112233445566.dkr.ecr.us-west-2.amazonaws.com/demo" # may be gcr.io/project-123/demo
|
|
8
8
|
config.logger.level = "info"
|
|
9
9
|
# auto-switching
|
|
10
|
-
# config.kubectl.context = "dev-
|
|
10
|
+
# config.kubectl.context = "dev-cluster"
|
|
11
11
|
end
|
|
12
12
|
```
|
|
13
13
|
|
|
@@ -5,11 +5,11 @@ reference: true
|
|
|
5
5
|
|
|
6
6
|
## Usage
|
|
7
7
|
|
|
8
|
-
kubes apply [
|
|
8
|
+
kubes apply [ROLE] [RESOURCE]
|
|
9
9
|
|
|
10
10
|
## Description
|
|
11
11
|
|
|
12
|
-
Apply the Kubernetes YAML files without
|
|
12
|
+
Apply the Kubernetes YAML files without building docker image
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
## Options
|
|
@@ -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/_sass/theme.scss
CHANGED
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
margin: auto;
|
|
14
14
|
text-align: center;
|
|
15
15
|
display: block;
|
|
16
|
+
width: 80%;
|
|
16
17
|
padding-bottom: 30px;
|
|
17
18
|
|
|
18
19
|
@media (min-width: 575px) {
|
|
19
20
|
position: absolute;
|
|
20
21
|
top: 50%;
|
|
21
|
-
|
|
22
|
+
width: 100%;
|
|
22
23
|
margin: 0;
|
|
23
24
|
transform: translateY(-50%);
|
|
24
25
|
}
|
data/docs/bin/web
CHANGED
|
Binary file
|
data/docs/index.html
CHANGED
|
@@ -9,13 +9,13 @@ sidebar: false
|
|
|
9
9
|
<div class="col-sm-8 col-sm-offset-2">
|
|
10
10
|
<div class="header-content">
|
|
11
11
|
<div class="header-content-inner">
|
|
12
|
-
<h1>Kubes</h1>
|
|
12
|
+
<h1>Kubes: Kubernetes Deployment Tool</h1>
|
|
13
13
|
<h2>Kubes is a Kubernetes Deployment Tool. It builds the docker image, creates the Kubernetes YAML, and runs kubectl apply. It automates the deployment process and saves you precious finger-typing energy.</h2>
|
|
14
14
|
</div>
|
|
15
15
|
</div>
|
|
16
16
|
</div>
|
|
17
17
|
<div class="col-sm-4">
|
|
18
|
-
<img src="/img/logos/kubes-
|
|
18
|
+
<img src="/img/logos/kubes-white.png" class="homepage-logo" />
|
|
19
19
|
</div>
|
|
20
20
|
</div>
|
|
21
21
|
</div>
|
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,12 @@ 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
|
+
}
|
|
15
|
+
container_option = Proc.new {
|
|
16
|
+
option :container, aliases: %w[c], desc: "Container name. If omitted, the first container in the pod will be chosen"
|
|
17
|
+
}
|
|
12
18
|
|
|
13
19
|
desc "docker SUBCOMMAND", "Docker subcommands"
|
|
14
20
|
long_desc Help.text(:docker)
|
|
@@ -60,15 +66,35 @@ module Kubes
|
|
|
60
66
|
Describe.new(options.merge(role: role, resource: resource)).run
|
|
61
67
|
end
|
|
62
68
|
|
|
69
|
+
desc "exec", "Exec into the latest container from the deployment"
|
|
70
|
+
long_desc Help.text(:exec)
|
|
71
|
+
compile_option.call
|
|
72
|
+
name_option.call
|
|
73
|
+
container_option.call
|
|
74
|
+
def exec(*cmd)
|
|
75
|
+
Exec.new(options.merge(cmd: cmd)).run
|
|
76
|
+
end
|
|
77
|
+
|
|
63
78
|
desc "get [ROLE] [RESOURCE]", "Get Kubernetes resource using the compiled YAML files"
|
|
64
79
|
long_desc Help.text(:get)
|
|
65
80
|
image_option.call
|
|
66
81
|
compile_option.call
|
|
67
82
|
option :output, aliases: %w[o], desc: "Output format: json|yaml|wide|name"
|
|
83
|
+
option :show_pods, type: :boolean, default: true, desc: "Also show pods from deployments"
|
|
68
84
|
def get(role=nil, resource=nil)
|
|
69
85
|
Get.new(options.merge(role: role, resource: resource)).run
|
|
70
86
|
end
|
|
71
87
|
|
|
88
|
+
desc "logs", "logs from all deployment pods"
|
|
89
|
+
long_desc Help.text(:logs)
|
|
90
|
+
compile_option.call
|
|
91
|
+
name_option.call
|
|
92
|
+
container_option.call
|
|
93
|
+
option :follow, aliases: %w[f], type: :boolean, default: true, desc: "Follow logs"
|
|
94
|
+
def logs(*cmd)
|
|
95
|
+
Logs.new(options.merge(cmd: cmd)).run
|
|
96
|
+
end
|
|
97
|
+
|
|
72
98
|
long_desc Help.text(:init)
|
|
73
99
|
Init.options.each { |args| option(*args) }
|
|
74
100
|
register(Init, "init", "init", "Init project")
|
data/lib/kubes/cli/apply.rb
CHANGED
data/lib/kubes/cli/base.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
|
@@ -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
|
data/lib/kubes/cli/init.rb
CHANGED
|
@@ -6,6 +6,7 @@ class Kubes::CLI
|
|
|
6
6
|
[:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
|
|
7
7
|
[:type, aliases: ["t"], default: "yaml", desc: "Type: dsl or yaml"],
|
|
8
8
|
[:repo, required: true, desc: "Docker repo name. Example: user/repo. Configures .kubes/config.rb"],
|
|
9
|
+
[:namespace, aliases: ["n"], desc: "Namespace to use, defaults to the app option"],
|
|
9
10
|
]
|
|
10
11
|
end
|
|
11
12
|
|
|
@@ -17,6 +18,37 @@ class Kubes::CLI
|
|
|
17
18
|
@options[:app]
|
|
18
19
|
end
|
|
19
20
|
|
|
21
|
+
def namespace
|
|
22
|
+
@options[:namespace] || @options[:app]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def excludes
|
|
26
|
+
if namespace == "default"
|
|
27
|
+
case options[:type]
|
|
28
|
+
when "dsl"
|
|
29
|
+
%w[
|
|
30
|
+
namespace.rb.tt
|
|
31
|
+
]
|
|
32
|
+
else
|
|
33
|
+
%w[
|
|
34
|
+
all.yaml.tt
|
|
35
|
+
namespace.yaml.tt
|
|
36
|
+
]
|
|
37
|
+
end
|
|
38
|
+
else
|
|
39
|
+
[]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def directory_options
|
|
44
|
+
if excludes.empty?
|
|
45
|
+
{}
|
|
46
|
+
else
|
|
47
|
+
pattern = Regexp.new(excludes.join('|'))
|
|
48
|
+
{exclude_pattern: pattern }
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
20
52
|
public
|
|
21
53
|
def create_dockefile
|
|
22
54
|
return if File.exist?("Dockerfile")
|
|
@@ -32,13 +64,13 @@ class Kubes::CLI
|
|
|
32
64
|
def create_dsl_files
|
|
33
65
|
return unless @options[:type] == "dsl"
|
|
34
66
|
set_source("dsl")
|
|
35
|
-
directory ".", "."
|
|
67
|
+
directory ".", ".", directory_options
|
|
36
68
|
end
|
|
37
69
|
|
|
38
70
|
def create_yaml_files
|
|
39
71
|
return if @options[:type] == "dsl"
|
|
40
72
|
set_source("yaml")
|
|
41
|
-
directory ".", "."
|
|
73
|
+
directory ".", ".", directory_options
|
|
42
74
|
end
|
|
43
75
|
|
|
44
76
|
def message
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class Kubes::CLI
|
|
2
|
+
class Logs < Base
|
|
3
|
+
include Kubes::Util::Sh
|
|
4
|
+
|
|
5
|
+
def run
|
|
6
|
+
compile
|
|
7
|
+
deployment = Kubes::Kubectl::Fetch::Deployment.new(@options)
|
|
8
|
+
metadata = deployment.metadata
|
|
9
|
+
name = metadata['name']
|
|
10
|
+
ns = metadata['namespace']
|
|
11
|
+
|
|
12
|
+
follow = " -f" if @options[:follow]
|
|
13
|
+
container = container(deployment)
|
|
14
|
+
c = " -c #{container}" if container
|
|
15
|
+
sh("kubectl logs deployment/#{name}#{follow} -n #{ns}#{c}")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
def container(deployment)
|
|
20
|
+
container = @options[:container]
|
|
21
|
+
return container if container
|
|
22
|
+
|
|
23
|
+
spec = deployment.spec
|
|
24
|
+
containers = spec['template']['spec']['containers']
|
|
25
|
+
names = containers.map { |c| c['name'] }
|
|
26
|
+
if containers.size > 1
|
|
27
|
+
logger.info <<~EOL
|
|
28
|
+
INFO: More than one container found.
|
|
29
|
+
Container names: #{names.join(', ')}
|
|
30
|
+
Using #{names.first}
|
|
31
|
+
Note: You can specify the container to use with --container or -c
|
|
32
|
+
EOL
|
|
33
|
+
|
|
34
|
+
names.first
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
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,
|
|
@@ -33,8 +33,19 @@ module Kubes::Compiler::Dsl::Syntax
|
|
|
33
33
|
|
|
34
34
|
def default_spec
|
|
35
35
|
{
|
|
36
|
+
clusterIP: clusterIP,
|
|
37
|
+
externalIPs: externalIPs,
|
|
38
|
+
externalName: externalName,
|
|
39
|
+
externalTrafficPolicy: externalTrafficPolicy,
|
|
40
|
+
healthCheckNodePort: healthCheckNodePort,
|
|
41
|
+
ipFamily: ipFamily,
|
|
42
|
+
loadBalancerIP: loadBalancerIP,
|
|
43
|
+
loadBalancerSourceRanges: loadBalancerSourceRanges,
|
|
36
44
|
ports: ports,
|
|
45
|
+
publishNotReadyAddresses: publishNotReadyAddresses,
|
|
37
46
|
selector: selector,
|
|
47
|
+
sessionAffinity: sessionAffinity,
|
|
48
|
+
sessionAffinityConfig: sessionAffinityConfig,
|
|
38
49
|
type: type,
|
|
39
50
|
}
|
|
40
51
|
end
|
data/lib/kubes/hooks/builder.rb
CHANGED
data/lib/kubes/kubectl.rb
CHANGED
|
@@ -9,17 +9,29 @@ module Kubes
|
|
|
9
9
|
|
|
10
10
|
def run
|
|
11
11
|
validate!
|
|
12
|
+
|
|
13
|
+
options = @options.dup
|
|
14
|
+
options[:exit_on_fail] = exit_on_fail unless exit_on_fail.nil?
|
|
15
|
+
|
|
12
16
|
params = args.flatten.join(' ')
|
|
13
17
|
command = "kubectl #{@name} #{params}" # @name: apply or delete
|
|
14
|
-
|
|
15
|
-
options[:exit_on_fail] = exit_on_fail unless exit_on_fail.nil?
|
|
18
|
+
|
|
16
19
|
switch_context do
|
|
17
20
|
run_hooks(@name) do
|
|
18
|
-
|
|
21
|
+
if options[:capture]
|
|
22
|
+
capture(command, options)
|
|
23
|
+
else
|
|
24
|
+
sh(command, options)
|
|
25
|
+
end
|
|
19
26
|
end
|
|
20
27
|
end
|
|
21
28
|
end
|
|
22
29
|
|
|
30
|
+
def execute(args, options={})
|
|
31
|
+
command = "kubectl #{args}"
|
|
32
|
+
capture(command)
|
|
33
|
+
end
|
|
34
|
+
|
|
23
35
|
# Useful for kustomize mode
|
|
24
36
|
def validate!
|
|
25
37
|
return true unless Kubes.kustomize?
|
data/lib/kubes/kubectl/batch.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
class Kubes::Kubectl
|
|
2
2
|
class Batch
|
|
3
|
+
include Kubes::Logging
|
|
3
4
|
include Kubes::Util::Consider
|
|
4
5
|
include Ordering
|
|
5
6
|
|
|
@@ -8,8 +9,14 @@ class Kubes::Kubectl
|
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def run
|
|
12
|
+
# @options[:preview] is really only used for kubectl delete
|
|
13
|
+
logger.info "Will run:" if @options[:preview]
|
|
11
14
|
sorted_files.each do |file|
|
|
12
|
-
|
|
15
|
+
if @options[:preview]
|
|
16
|
+
logger.info " kubectl #{@name} -f #{file}"
|
|
17
|
+
else
|
|
18
|
+
Kubes::Kubectl.run(@name, @options.merge(file: file))
|
|
19
|
+
end
|
|
13
20
|
end
|
|
14
21
|
end
|
|
15
22
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
module Kubes::Kubectl::Fetch
|
|
4
|
+
class Base
|
|
5
|
+
include Kubes::Logging
|
|
6
|
+
include Kubes::Util::Sh
|
|
7
|
+
|
|
8
|
+
def initialize(options={})
|
|
9
|
+
@options = options
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def fetch_items
|
|
13
|
+
o = {
|
|
14
|
+
capture: true,
|
|
15
|
+
output: "json",
|
|
16
|
+
show_command: false,
|
|
17
|
+
}
|
|
18
|
+
kubectl = Kubes::Kubectl.new(:get, @options.merge(o)) # kubes get -f .kubes/output
|
|
19
|
+
resp = kubectl.run
|
|
20
|
+
data = JSON.load(resp)
|
|
21
|
+
data['items']
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Kubes::Kubectl::Fetch
|
|
2
|
+
class Deployment < Base
|
|
3
|
+
extend Memoist
|
|
4
|
+
|
|
5
|
+
def metadata
|
|
6
|
+
deployment['metadata']
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def spec
|
|
10
|
+
deployment['spec']
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def deployment
|
|
14
|
+
items = fetch_items
|
|
15
|
+
# Not checking if deployment exists because kubes will error on `kubes get` from missing deployments already
|
|
16
|
+
deployments = items.select { |i| i['kind'] == "Deployment" }
|
|
17
|
+
|
|
18
|
+
if deployments.size > 1 && !@options[:name]
|
|
19
|
+
names = deployments.map { |d| d['metadata']['name'] }
|
|
20
|
+
logger.info <<~EOL
|
|
21
|
+
INFO: More than one deployment found.
|
|
22
|
+
Deployment names: #{names.join(', ')}
|
|
23
|
+
Using #{names.first}
|
|
24
|
+
Note: You can specify the deployment to use with --name or -n
|
|
25
|
+
EOL
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
deployment = find_deployment(deployments)
|
|
29
|
+
unless deployment
|
|
30
|
+
logger.error "ERROR: No deployment found".color(:red)
|
|
31
|
+
exit 1
|
|
32
|
+
end
|
|
33
|
+
deployment
|
|
34
|
+
end
|
|
35
|
+
memoize :deployment
|
|
36
|
+
|
|
37
|
+
def find_deployment(deployments)
|
|
38
|
+
if @options[:name]
|
|
39
|
+
deployments.find { |d| d['metadata']['name'] == @options[:name] }
|
|
40
|
+
else
|
|
41
|
+
deployments.first
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Kubes::Kubectl::Fetch
|
|
2
|
+
class Pods < Base
|
|
3
|
+
def show
|
|
4
|
+
items = fetch_items
|
|
5
|
+
# Not checking if deployment exists because kubes will error on `kubes get` from missing deployments already
|
|
6
|
+
deployments = items.select { |i| i['kind'] == "Deployment" }
|
|
7
|
+
|
|
8
|
+
deployments.each do |deployment|
|
|
9
|
+
logger.info "Pods for deployment #{deployment['metadata']['name']}:".color(:green)
|
|
10
|
+
show_for(deployment)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def show_for(deployment)
|
|
15
|
+
metadata = deployment['metadata']
|
|
16
|
+
labels = metadata['labels'].map { |k,v| "#{k}=#{v}" }.join(',')
|
|
17
|
+
ns = metadata['namespace']
|
|
18
|
+
sh("kubectl get pod -l #{labels} -n #{ns}")
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/kubes/util/sh.rb
CHANGED
|
@@ -32,6 +32,7 @@ module Kubes::Util
|
|
|
32
32
|
|
|
33
33
|
def capture(command, options={})
|
|
34
34
|
exit_on_fail = options[:exit_on_fail].nil? ? true : options[:exit_on_fail]
|
|
35
|
+
logger.info "=> #{command}" if options[:show_command]
|
|
35
36
|
out = `#{command}`.strip
|
|
36
37
|
unless $?.success?
|
|
37
38
|
logger.error "ERROR: running #{command}".color(:red)
|
data/lib/kubes/version.rb
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
name "<%=
|
|
1
|
+
name "<%= namespace %>"
|
|
2
2
|
labels(app: "<%= app %>")
|
|
@@ -7,4 +7,5 @@ image built_image # IE: user/<%= app %>:kubes-2020-06-13T19-55-16-43afc6e
|
|
|
7
7
|
# revisionHistoryLimit 1 # uncomment to reduce old ReplicaSets, default is 10 https://bit.ly/3hqrzyP
|
|
8
8
|
# maxUnavailable 25
|
|
9
9
|
|
|
10
|
-
# More docs: kubes.guru/docs/dsl/deployment/
|
|
10
|
+
# More docs: kubes.guru/docs/dsl/resources/deployment/
|
|
11
|
+
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
metadata:
|
|
2
|
-
namespace: <%=
|
|
2
|
+
namespace: <%= namespace %>
|
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.
|
|
4
|
+
version: 0.3.4
|
|
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-
|
|
11
|
+
date: 2020-08-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -317,6 +317,8 @@ files:
|
|
|
317
317
|
- docs/_includes/layering/layers.md
|
|
318
318
|
- docs/_includes/learn/cluster.md
|
|
319
319
|
- docs/_includes/learn/next-steps.md
|
|
320
|
+
- docs/_includes/learn/repo
|
|
321
|
+
- docs/_includes/learn/repos.md
|
|
320
322
|
- docs/_includes/learn/review.md
|
|
321
323
|
- docs/_includes/learn/start.md
|
|
322
324
|
- docs/_includes/reference.md
|
|
@@ -329,11 +331,15 @@ files:
|
|
|
329
331
|
- docs/_reference/kubes-completion_script.md
|
|
330
332
|
- docs/_reference/kubes-delete.md
|
|
331
333
|
- docs/_reference/kubes-deploy.md
|
|
334
|
+
- docs/_reference/kubes-describe.md
|
|
332
335
|
- docs/_reference/kubes-docker-build.md
|
|
333
336
|
- docs/_reference/kubes-docker-help.md
|
|
334
337
|
- docs/_reference/kubes-docker-push.md
|
|
335
338
|
- docs/_reference/kubes-docker.md
|
|
339
|
+
- docs/_reference/kubes-exec.md
|
|
340
|
+
- docs/_reference/kubes-get.md
|
|
336
341
|
- docs/_reference/kubes-init.md
|
|
342
|
+
- docs/_reference/kubes-logs.md
|
|
337
343
|
- docs/_reference/kubes-version.md
|
|
338
344
|
- docs/_sass/bootstrap-overrides.scss
|
|
339
345
|
- docs/_sass/buttons.scss
|
|
@@ -360,6 +366,7 @@ files:
|
|
|
360
366
|
- docs/img/logos/filler-logo.png
|
|
361
367
|
- docs/img/logos/kubes-black.png
|
|
362
368
|
- docs/img/logos/kubes-sign.png
|
|
369
|
+
- docs/img/logos/kubes-white.png
|
|
363
370
|
- docs/index.html
|
|
364
371
|
- docs/js/app.js
|
|
365
372
|
- docs/opal/app.rb
|
|
@@ -457,12 +464,15 @@ files:
|
|
|
457
464
|
- lib/kubes/cli/deploy.rb
|
|
458
465
|
- lib/kubes/cli/describe.rb
|
|
459
466
|
- lib/kubes/cli/docker.rb
|
|
467
|
+
- lib/kubes/cli/exec.rb
|
|
460
468
|
- lib/kubes/cli/get.rb
|
|
461
469
|
- lib/kubes/cli/help.rb
|
|
462
470
|
- lib/kubes/cli/help/completion.md
|
|
463
471
|
- lib/kubes/cli/help/completion_script.md
|
|
464
472
|
- lib/kubes/cli/help/deploy.md
|
|
473
|
+
- lib/kubes/cli/help/exec.md
|
|
465
474
|
- lib/kubes/cli/init.rb
|
|
475
|
+
- lib/kubes/cli/logs.rb
|
|
466
476
|
- lib/kubes/cli/sequence.rb
|
|
467
477
|
- lib/kubes/command.rb
|
|
468
478
|
- lib/kubes/compiler.rb
|
|
@@ -533,6 +543,9 @@ files:
|
|
|
533
543
|
- lib/kubes/kubectl/args/standard.rb
|
|
534
544
|
- lib/kubes/kubectl/batch.rb
|
|
535
545
|
- lib/kubes/kubectl/decider.rb
|
|
546
|
+
- lib/kubes/kubectl/fetch/base.rb
|
|
547
|
+
- lib/kubes/kubectl/fetch/deployment.rb
|
|
548
|
+
- lib/kubes/kubectl/fetch/pods.rb
|
|
536
549
|
- lib/kubes/kubectl/kustomize.rb
|
|
537
550
|
- lib/kubes/kubectl/ordering.rb
|
|
538
551
|
- lib/kubes/logger.rb
|