cdk8s-plus-34 0.0.1 → 2.0.0
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.
- package/.jsii +101649 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +185 -0
- package/DCO +34 -0
- package/LICENSE +202 -0
- package/NOTICE +1 -0
- package/OWNERS.md +5 -0
- package/README.md +21 -33
- package/SECURITY.md +5 -0
- package/cdk8s.yaml +11 -0
- package/docs/java.md +150009 -0
- package/docs/plus/config-map.md +98 -0
- package/docs/plus/container.md +133 -0
- package/docs/plus/cronjob.md +67 -0
- package/docs/plus/deployment.md +232 -0
- package/docs/plus/horizontal-pod-autoscaler.md +226 -0
- package/docs/plus/ingress.md +68 -0
- package/docs/plus/job.md +48 -0
- package/docs/plus/namespace.md +58 -0
- package/docs/plus/network-policy.md +341 -0
- package/docs/plus/pod.md +455 -0
- package/docs/plus/pv.md +82 -0
- package/docs/plus/pvc.md +77 -0
- package/docs/plus/rbac.md +104 -0
- package/docs/plus/secret.md +32 -0
- package/docs/plus/service-account.md +35 -0
- package/docs/plus/service.md +41 -0
- package/docs/plus/volume.md +84 -0
- package/docs/python.md +161196 -0
- package/docs/typescript.md +139649 -0
- package/git-hooks/README.md +9 -0
- package/git-hooks/prepare-commit-msg +18 -0
- package/git-hooks/setup.sh +10 -0
- package/lib/_action.d.ts +26 -0
- package/lib/_action.js +39 -0
- package/lib/api-resource.d.ts +298 -0
- package/lib/api-resource.js +430 -0
- package/lib/base.d.ts +79 -0
- package/lib/base.js +92 -0
- package/lib/config-map.d.ts +126 -0
- package/lib/config-map.js +159 -0
- package/lib/container.d.ts +1057 -0
- package/lib/container.js +845 -0
- package/lib/cron-job.d.ts +138 -0
- package/lib/cron-job.js +103 -0
- package/lib/daemon-set.d.ts +45 -0
- package/lib/daemon-set.js +55 -0
- package/lib/deployment.d.ts +235 -0
- package/lib/deployment.js +216 -0
- package/lib/handler.d.ts +62 -0
- package/lib/handler.js +54 -0
- package/lib/horizontal-pod-autoscaler.d.ts +500 -0
- package/lib/horizontal-pod-autoscaler.js +569 -0
- package/lib/imports/k8s.d.ts +25809 -0
- package/lib/imports/k8s.js +19238 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.js +44 -0
- package/lib/ingress.d.ts +230 -0
- package/lib/ingress.js +246 -0
- package/lib/job.d.ts +64 -0
- package/lib/job.js +54 -0
- package/lib/namespace.d.ts +128 -0
- package/lib/namespace.js +109 -0
- package/lib/network-policy.d.ts +311 -0
- package/lib/network-policy.js +344 -0
- package/lib/pod.d.ts +1097 -0
- package/lib/pod.js +1147 -0
- package/lib/probe.d.ts +181 -0
- package/lib/probe.js +88 -0
- package/lib/pv.d.ts +375 -0
- package/lib/pv.js +273 -0
- package/lib/pvc.d.ts +163 -0
- package/lib/pvc.js +154 -0
- package/lib/role-binding.d.ts +138 -0
- package/lib/role-binding.js +165 -0
- package/lib/role.d.ts +268 -0
- package/lib/role.js +401 -0
- package/lib/secret.d.ts +195 -0
- package/lib/secret.js +185 -0
- package/lib/service-account.d.ts +83 -0
- package/lib/service-account.js +105 -0
- package/lib/service.d.ts +289 -0
- package/lib/service.js +182 -0
- package/lib/stateful-set.d.ts +206 -0
- package/lib/stateful-set.js +244 -0
- package/lib/utils.d.ts +4 -0
- package/lib/utils.js +33 -0
- package/lib/volume.d.ts +577 -0
- package/lib/volume.js +377 -0
- package/lib/workload.d.ts +121 -0
- package/lib/workload.js +122 -0
- package/node_modules/balanced-match/.github/FUNDING.yml +2 -0
- package/node_modules/balanced-match/LICENSE.md +21 -0
- package/node_modules/balanced-match/README.md +97 -0
- package/node_modules/balanced-match/index.js +62 -0
- package/node_modules/balanced-match/package.json +48 -0
- package/node_modules/brace-expansion/.github/FUNDING.yml +2 -0
- package/node_modules/brace-expansion/LICENSE +21 -0
- package/node_modules/brace-expansion/README.md +135 -0
- package/node_modules/brace-expansion/index.js +202 -0
- package/node_modules/brace-expansion/package.json +49 -0
- package/node_modules/minimatch/LICENSE +15 -0
- package/node_modules/minimatch/README.md +491 -0
- package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts +2 -0
- package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts.map +1 -0
- package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
- package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js.map +1 -0
- package/node_modules/minimatch/dist/commonjs/ast.d.ts +20 -0
- package/node_modules/minimatch/dist/commonjs/ast.d.ts.map +1 -0
- package/node_modules/minimatch/dist/commonjs/ast.js +747 -0
- package/node_modules/minimatch/dist/commonjs/ast.js.map +1 -0
- package/node_modules/minimatch/dist/commonjs/brace-expressions.d.ts +8 -0
- package/node_modules/minimatch/dist/commonjs/brace-expressions.d.ts.map +1 -0
- package/node_modules/minimatch/dist/commonjs/brace-expressions.js +152 -0
- package/node_modules/minimatch/dist/commonjs/brace-expressions.js.map +1 -0
- package/node_modules/minimatch/dist/commonjs/escape.d.ts +12 -0
- package/node_modules/minimatch/dist/commonjs/escape.d.ts.map +1 -0
- package/node_modules/minimatch/dist/commonjs/escape.js +22 -0
- package/node_modules/minimatch/dist/commonjs/escape.js.map +1 -0
- package/node_modules/minimatch/dist/commonjs/index.d.ts +98 -0
- package/node_modules/minimatch/dist/commonjs/index.d.ts.map +1 -0
- package/node_modules/minimatch/dist/commonjs/index.js +1023 -0
- package/node_modules/minimatch/dist/commonjs/index.js.map +1 -0
- package/node_modules/minimatch/dist/commonjs/package.json +3 -0
- package/node_modules/minimatch/dist/commonjs/unescape.d.ts +17 -0
- package/node_modules/minimatch/dist/commonjs/unescape.d.ts.map +1 -0
- package/node_modules/minimatch/dist/commonjs/unescape.js +24 -0
- package/node_modules/minimatch/dist/commonjs/unescape.js.map +1 -0
- package/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts +2 -0
- package/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts.map +1 -0
- package/node_modules/minimatch/dist/esm/assert-valid-pattern.js +10 -0
- package/node_modules/minimatch/dist/esm/assert-valid-pattern.js.map +1 -0
- package/node_modules/minimatch/dist/esm/ast.d.ts +20 -0
- package/node_modules/minimatch/dist/esm/ast.d.ts.map +1 -0
- package/node_modules/minimatch/dist/esm/ast.js +743 -0
- package/node_modules/minimatch/dist/esm/ast.js.map +1 -0
- package/node_modules/minimatch/dist/esm/brace-expressions.d.ts +8 -0
- package/node_modules/minimatch/dist/esm/brace-expressions.d.ts.map +1 -0
- package/node_modules/minimatch/dist/esm/brace-expressions.js +148 -0
- package/node_modules/minimatch/dist/esm/brace-expressions.js.map +1 -0
- package/node_modules/minimatch/dist/esm/escape.d.ts +12 -0
- package/node_modules/minimatch/dist/esm/escape.d.ts.map +1 -0
- package/node_modules/minimatch/dist/esm/escape.js +18 -0
- package/node_modules/minimatch/dist/esm/escape.js.map +1 -0
- package/node_modules/minimatch/dist/esm/index.d.ts +98 -0
- package/node_modules/minimatch/dist/esm/index.d.ts.map +1 -0
- package/node_modules/minimatch/dist/esm/index.js +1007 -0
- package/node_modules/minimatch/dist/esm/index.js.map +1 -0
- package/node_modules/minimatch/dist/esm/package.json +3 -0
- package/node_modules/minimatch/dist/esm/unescape.d.ts +17 -0
- package/node_modules/minimatch/dist/esm/unescape.d.ts.map +1 -0
- package/node_modules/minimatch/dist/esm/unescape.js +20 -0
- package/node_modules/minimatch/dist/esm/unescape.js.map +1 -0
- package/node_modules/minimatch/package.json +82 -0
- package/package.json +176 -6
- package/rotate.md +85 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# HorizontalPodAutoscaler
|
|
2
|
+
|
|
3
|
+
HorizontalPodAutoscaler allows your services to scale up when demand is high and scale down when they are no longer needed.
|
|
4
|
+
|
|
5
|
+
!!! tip ""
|
|
6
|
+
[API Reference](../../reference/cdk8s-plus-34/typescript.md#horizontalpodautoscaler)
|
|
7
|
+
|
|
8
|
+
## Using a HorizontalPodAutoscaler
|
|
9
|
+
|
|
10
|
+
The example below creates a HorizontalPodAutoscaler that scales the number of replicas of a Deployment based on the average CPU utilization of the pods.
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import * as k from 'cdk8s';
|
|
14
|
+
import * as kplus from 'cdk8s-plus-34';
|
|
15
|
+
|
|
16
|
+
const app = new k.App();
|
|
17
|
+
const chart = new k.Chart(app, 'Chart');
|
|
18
|
+
|
|
19
|
+
// Lets create a deployment for our web server
|
|
20
|
+
const bookstoreWebsite = new kplus.Deployment(chart, 'BookstoreWebsite', {
|
|
21
|
+
containers: [ { image: 'node' } ],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Now define a HorizontalPodAutoscaler
|
|
25
|
+
const hpa = new kplus.HorizontalPodAutoscaler(chart, 'BookstoreWebsiteHpa', {
|
|
26
|
+
target: bookstoreWebsite,
|
|
27
|
+
maxReplicas: 10,
|
|
28
|
+
metrics: [
|
|
29
|
+
kplus.Metric.resourceCpu(kplus.MetricTarget.averageUtilization(70)),
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
// This will scale our website deployment up when the average CPU utilization
|
|
33
|
+
// is 70% or higher up to a maximum of 10 replicas.
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Using the example above, if our web server passes 70% CPU utilization the autoscaler will try and figure out the number of replicas to scale.
|
|
37
|
+
|
|
38
|
+
The autoscaler uses the following formula:
|
|
39
|
+
|
|
40
|
+
> desiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]
|
|
41
|
+
|
|
42
|
+
Based on this formula we can find out how many replicas will be scaled. For example if we have 1 replica and the CPU utilization is at 70%.
|
|
43
|
+
|
|
44
|
+
> desiredReplicas = ceil[1 * ( 70 / 70 )] = 1
|
|
45
|
+
|
|
46
|
+
The autoscaler will try and add 1 replica, meaning we'll have 2 web servers running, the original and the new replica.
|
|
47
|
+
|
|
48
|
+
If the CPU utilization is 140% the autoscaler will try and provision 2 replicas. Scaling us up to 3 web servers total.
|
|
49
|
+
|
|
50
|
+
> desiredReplicas = ceil[1 * ( 140 / 70 )] = 2
|
|
51
|
+
|
|
52
|
+
This works the same way when scaling down.
|
|
53
|
+
|
|
54
|
+
For example if our target CPU utilization is 70% and we have 3 replicas running and the CPU utilization is at 50%.
|
|
55
|
+
|
|
56
|
+
> desiredReplicas = ceil[3 * ( 50 / 70 )] = 2
|
|
57
|
+
|
|
58
|
+
The autoscaler will try and remove 1 replica, meaning we'll have 2 web servers running, the original and the new replica.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
## Metrics
|
|
62
|
+
|
|
63
|
+
The HorizontalPodAutoscaler supports the following metrics:
|
|
64
|
+
|
|
65
|
+
### Resource Metrics
|
|
66
|
+
|
|
67
|
+
Resource metrics are used to scale on a resource like CPU or memory.
|
|
68
|
+
|
|
69
|
+
!!! note ""
|
|
70
|
+
Since the resource usages of all the containers are summed up the total pod utilization may not accurately represent the individual container resource usage. This could lead to situations where a single container might be running with high usage and the HPA will not scale out because the overall pod usage is still within acceptable limits.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import * as kplus from 'cdk8s-plus-34';
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
const hpa = new kplus.HorizontalPodAutoscaler(chart, 'BookstoreWebsiteHpa', {
|
|
78
|
+
target: bookstoreWebsite,
|
|
79
|
+
maxReplicas: 10,
|
|
80
|
+
metrics: [
|
|
81
|
+
kplus.Metric.resourceCpu(kplus.MetricTarget.averageUtilization(70)),
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Pods Metrics
|
|
87
|
+
|
|
88
|
+
Pods metrics are used to scale on a metric describing each pod in the current scale target (for example, transactions-processed-per-second).
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import * as kplus from 'cdk8s-plus-34';
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
const hpa = new kplus.HorizontalPodAutoscaler(chart, 'BookstoreWebsiteHpa', {
|
|
95
|
+
target: bookstoreWebsite,
|
|
96
|
+
maxReplicas: 10,
|
|
97
|
+
metrics: [
|
|
98
|
+
kplus.Metric.pods({
|
|
99
|
+
name: 'requests-per-second',
|
|
100
|
+
target: kplus.MetricTarget.averageUtilization(50),
|
|
101
|
+
labelSelector: kplus.LabelSelector.of({ labels: { app: 'scraper' } }),
|
|
102
|
+
}),
|
|
103
|
+
],
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
## Container Metrics
|
|
109
|
+
|
|
110
|
+
Container metrics are used to scale on one of the scaling target's container metrics.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import * as kplus from 'cdk8s-plus-34';
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
const hpa = new kplus.HorizontalPodAutoscaler(chart, 'BookstoreWebsiteHpa', {
|
|
117
|
+
target: bookstoreWebsite,
|
|
118
|
+
maxReplicas: 10,
|
|
119
|
+
metrics: [
|
|
120
|
+
kplus.Metric.containerMemory(kplus.MetricTarget.value(4096)),
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Object Metrics
|
|
126
|
+
|
|
127
|
+
Object metrics are used to scale on a metric describing a single kubernetes object (for example, requests-per-second on an Ingress object).
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import * as kplus from 'cdk8s-plus-34';
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
const hpa = new kplus.HorizontalPodAutoscaler(chart, 'BookstoreWebsiteHpa', {
|
|
134
|
+
target: bookstoreWebsite,
|
|
135
|
+
maxReplicas: 10,
|
|
136
|
+
metrics: [
|
|
137
|
+
kplus.Metric.object({
|
|
138
|
+
object: ingress,
|
|
139
|
+
name: 'requests-per-second',
|
|
140
|
+
target: kplus.MetricTarget.averageUtilization(50),
|
|
141
|
+
}),
|
|
142
|
+
],
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### External Metrics
|
|
147
|
+
|
|
148
|
+
External metrics are used to scale on a metric not associated with any Kubernetes object (for example, an SQS queue).
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import * as kplus from 'cdk8s-plus-34';
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
const hpa = new kplus.HorizontalPodAutoscaler(chart, 'BookstoreWebsiteHpa', {
|
|
155
|
+
target: bookstoreWebsite,
|
|
156
|
+
maxReplicas: 10,
|
|
157
|
+
metrics: [
|
|
158
|
+
kplus.Metric.external({
|
|
159
|
+
labelSelector: kplus.LabelSelector.of({ labels: { app: 'scraper' } }),
|
|
160
|
+
name: 'sqs-queue',
|
|
161
|
+
target: kplus.MetricTarget.averageUtilization(50),
|
|
162
|
+
}),
|
|
163
|
+
],
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Scaling behavior
|
|
168
|
+
|
|
169
|
+
The HorizontalPodAutoscaler has a few options to control the scaling behavior.
|
|
170
|
+
|
|
171
|
+
### scaleUp /scaleDown
|
|
172
|
+
|
|
173
|
+
The `scaleUp` / `scaleDown` options controls how fast the HorizontalPodAutoscaler scales up and down. They share the same options but have slightly different defaults.
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
const hpa = new kplus.HorizontalPodAutoscaler(chart, 'BookstoreWebsiteHpa', {
|
|
177
|
+
target: bookstoreWebsite,
|
|
178
|
+
maxReplicas: 10,
|
|
179
|
+
scaleUp: {
|
|
180
|
+
stabilizationWindow: 60,
|
|
181
|
+
policies: [
|
|
182
|
+
kplus.PolicyType.pods(4),
|
|
183
|
+
kplus.PolicyType.percent(200),
|
|
184
|
+
],
|
|
185
|
+
},
|
|
186
|
+
scaleDown: {
|
|
187
|
+
stabilizationWindow: 60,
|
|
188
|
+
policies: [
|
|
189
|
+
kplus.PolicyType.pods(2),
|
|
190
|
+
kplus.PolicyType.percent(100),
|
|
191
|
+
],
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
| Option | Description | `scaleUp` Default | `scaleDown` Default |
|
|
197
|
+
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
198
|
+
| `stabilizationWindow` | Defines the window of past metrics that the autoscaler should consider when calculating wether or not autoscaling should occur. | 5 minutes | 0 (no stabilization is performed) |
|
|
199
|
+
| `strategy` | Determines if the the Autoscaler should scale as much or as little as possible. | `ScalingStrategy.MAX_CHANGE` Choose the scaling policy that will scale the most replicas. | `ScalingStrategy.MIN_CHANGE` Choose the scaling policy that will scale the least replicas. |
|
|
200
|
+
| `policies` | Defines how many replicas are scaled. Can be an absolute number or a percentage of the current replica count. | * Increase no more than 4 pods per 60 seconds * Double the number of pods per 60 seconds | * Decrease to `minReplica` count (default 1) |
|
|
201
|
+
|
|
202
|
+
Check out the example below. We have a `scaleUp` policy that will scale up by 4 pods or double the current number of pods per 60 seconds. Because the `strategy` has been configured to `ScalingStrategy.MAX_CHANGE` the autoscaler will choose the policy that will make the most replicas.
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
const hpa = new kplus.HorizontalPodAutoscaler(chart, 'BookstoreWebsiteHpa', {
|
|
206
|
+
target: bookstoreWebsite,
|
|
207
|
+
maxReplicas: 10,
|
|
208
|
+
metrics: [
|
|
209
|
+
kplus.Metric.resourceCpu(kplus.MetricTarget.averageUtilization(70)),
|
|
210
|
+
],
|
|
211
|
+
scaleUp: {
|
|
212
|
+
strategy: kplus.ScalingStrategy.MAX_CHANGE,
|
|
213
|
+
stabilizationWindow: 60,
|
|
214
|
+
policies: [
|
|
215
|
+
kplus.PolicyType.pods(4),
|
|
216
|
+
kplus.PolicyType.percent(200),
|
|
217
|
+
],
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
This means that if we currently have 3 web server pods, and the CPU utilization is at 72% the autoscaler will try and add 6 pods every 60 seconds.
|
|
223
|
+
|
|
224
|
+
This will result in a total of 9 web server pods. If after 60 seconds the CPU utilization is still at 72% the autoscaler will only be allowed to add one more replica because `maxReplicas` has been configured to 10.
|
|
225
|
+
|
|
226
|
+
For more information on HorizontalPodAutoscaler check out the [API Reference](../reference/cdk8s-plus-34/typescript.md#horizontalpodautoscaler).
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Ingress
|
|
2
|
+
|
|
3
|
+
[Ingress] manages external access to services in a cluster, typically through
|
|
4
|
+
HTTP. Ingress may provide load balancing, SSL termination and name-based virtual
|
|
5
|
+
hosting.
|
|
6
|
+
|
|
7
|
+
!!! tip ""
|
|
8
|
+
[API Reference](../../reference/cdk8s-plus-34/typescript.md#ingressv1beta1)
|
|
9
|
+
|
|
10
|
+
You must have an [Ingress controller] to satisfy an Ingress. Only creating an
|
|
11
|
+
Ingress resource has no effect.
|
|
12
|
+
|
|
13
|
+
[Ingress]: https://kubernetes.io/docs/concepts/services-networking/ingress/
|
|
14
|
+
[Ingress controller]: https://kubernetes.io/docs/concepts/services-networking/ingress-controllers
|
|
15
|
+
|
|
16
|
+
The following example will route HTTP requests sent to the `/hello` url prefix
|
|
17
|
+
to a service associated with a deployment of the
|
|
18
|
+
[hashicorp/http-echo](https://github.com/hashicorp/http-echo) image.
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import * as kplus from 'cdk8s-plus-34';
|
|
22
|
+
import { Construct } from 'constructs';
|
|
23
|
+
import { App, Chart, ChartProps } from 'cdk8s';
|
|
24
|
+
|
|
25
|
+
export class MyChart extends Chart {
|
|
26
|
+
constructor(scope: Construct, id: string, props: ChartProps = { }) {
|
|
27
|
+
super(scope, id, props);
|
|
28
|
+
|
|
29
|
+
const helloDeployment = new kplus.Deployment(this, "Deployment", {
|
|
30
|
+
containers: [
|
|
31
|
+
{
|
|
32
|
+
image: 'hashicorp/http-echo',
|
|
33
|
+
args: [ '-text', 'hello ingress' ],
|
|
34
|
+
portNumber: 5678,
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const helloService = helloDeployment.exposeViaService({
|
|
40
|
+
ports: [
|
|
41
|
+
{
|
|
42
|
+
port: 5678,
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const ingress = new kplus.Ingress(this, 'ingress');
|
|
48
|
+
ingress.addRule('/hello', kplus.IngressBackend.fromService(helloService));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const app = new App();
|
|
53
|
+
new MyChart(app, 'ingress');
|
|
54
|
+
app.synth();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
You can use `addHostRule(host, path, backend)` to define a route that will only
|
|
58
|
+
apply to requests with this `Host` header. This can be used to implement virtual
|
|
59
|
+
hosts.
|
|
60
|
+
|
|
61
|
+
The `addDefaultBackend(backend)` and `addHostDefaultBackend(host, backend)`
|
|
62
|
+
methods can be used to define backends that will accept all requests that do not
|
|
63
|
+
match any other rules.
|
|
64
|
+
|
|
65
|
+
The TCP port used to route requests to services will be determined based on
|
|
66
|
+
which ports are exposed by the service (e.g. through `serve()`). If the service
|
|
67
|
+
exposes multiple ports, then a port must be specified via
|
|
68
|
+
`IngressBackend.fromService(service, { port })`.
|
package/docs/plus/job.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Job
|
|
2
|
+
|
|
3
|
+
Jobs are a very useful concept in kubernetes deployments.
|
|
4
|
+
They can be used for add-hoc provisioning tasks, as well as long running processing jobs.
|
|
5
|
+
|
|
6
|
+
In configuration, they don't differ much from regular pods, but offer some
|
|
7
|
+
additional properties.
|
|
8
|
+
|
|
9
|
+
!!! tip ""
|
|
10
|
+
[API Reference](../../reference/cdk8s-plus-34/typescript.md#job)
|
|
11
|
+
|
|
12
|
+
## Delete a Job after its finished
|
|
13
|
+
|
|
14
|
+
You can configure a TTL for the job after it finished its execution successfully.
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import * as kplus from 'cdk8s-plus-34';
|
|
18
|
+
import { Construct } from 'constructs';
|
|
19
|
+
import { App, Chart, ChartProps, Duration } from 'cdk8s';
|
|
20
|
+
|
|
21
|
+
export class MyChart extends Chart {
|
|
22
|
+
constructor(scope: Construct, id: string, props: ChartProps = { }) {
|
|
23
|
+
super(scope, id, props);
|
|
24
|
+
|
|
25
|
+
// let's define a job spec, and set a 1 second TTL.
|
|
26
|
+
const job = new kplus.Job(this, 'LoadData', {
|
|
27
|
+
ttlAfterFinished: Duration.seconds(1)
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// now add a container to all the pods created by this job
|
|
31
|
+
job.addContainer({
|
|
32
|
+
image: 'loader'
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const app = new App();
|
|
38
|
+
new MyChart(app, 'Job');
|
|
39
|
+
app.synth();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Scheduling
|
|
43
|
+
|
|
44
|
+
See [Deployment scheduling](./deployment.md#scheduling).
|
|
45
|
+
|
|
46
|
+
## Connections
|
|
47
|
+
|
|
48
|
+
See [Pod connections](./pod.md#connections).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Namespace
|
|
2
|
+
|
|
3
|
+
Namespaces provides a mechanism for isolating groups of resources within a single cluster.
|
|
4
|
+
|
|
5
|
+
!!! tip ""
|
|
6
|
+
[API Reference](../../reference/cdk8s-plus-34/typescript.md#namespace)
|
|
7
|
+
|
|
8
|
+
## Create a `Namespace`
|
|
9
|
+
|
|
10
|
+
To create a new namespace in the cluster:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import * as kplus from 'cdk8s-plus-34';
|
|
14
|
+
import * as k from 'cdk8s';
|
|
15
|
+
|
|
16
|
+
const app = new k.App();
|
|
17
|
+
const chart = new k.Chart(app, 'Chart');
|
|
18
|
+
|
|
19
|
+
const namespace = new kplus.Namespace(chart, 'BackOfficeNamespace');
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Like any other resource, if you don't specify a name, cdk8s will auto-generate one, which you
|
|
23
|
+
can access by `namespace.name`.
|
|
24
|
+
|
|
25
|
+
## Select namespaces
|
|
26
|
+
|
|
27
|
+
Namespaces can also be selected by various mechanisms. These selections are often used in other
|
|
28
|
+
cdk8s+ API's, such as [pod selection](./pod.md#pod-selection) during scheduling.
|
|
29
|
+
|
|
30
|
+
### Select namespaces by name
|
|
31
|
+
|
|
32
|
+
Select a namespace called `backoffice`.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import * as kplus from 'cdk8s-plus-34';
|
|
36
|
+
|
|
37
|
+
const backoffice = kplus.Namespaces.select(this, 'Backoffice', { names: ['backoffice'] });
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Select namespace by labels
|
|
41
|
+
|
|
42
|
+
Select all namespaces that have the `processing=batch` label.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import * as kplus from 'cdk8s-plus-34';
|
|
46
|
+
|
|
47
|
+
const batch = kplus.Namespaces.select(this, 'Batch', { labels: { processing: 'batch'} });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Select all namespaces
|
|
51
|
+
|
|
52
|
+
Select all namespaces in the cluster.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import * as kplus from 'cdk8s-plus-34';
|
|
56
|
+
|
|
57
|
+
const all = kplus.Namespaces.all();
|
|
58
|
+
```
|