Skip to content

Commit 0b3b79e

Browse files
authored
Add Kubernetes YAML with CRD example (#477)
1 parent f4618b5 commit 0b3b79e

File tree

5 files changed

+143
-0
lines changed

5 files changed

+143
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### Scala an JVM
2+
*.class
3+
*.log
4+
.bsp
5+
.scala-build
6+
7+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
8+
hs_err_pid*
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import besom.*
2+
import besom.api.kubernetes as k8s
3+
4+
@main def main = Pulumi.run {
5+
6+
val crd =
7+
k8s.yaml.v2.ConfigGroup(
8+
name = "config-group",
9+
k8s.yaml.v2.ConfigGroupArgs(
10+
yaml = """apiVersion: apiextensions.k8s.io/v1
11+
|kind: CustomResourceDefinition
12+
|metadata:
13+
| # name must match the spec fields below, and be in the form: <plural>.<group>
14+
| name: crontabs.stable.example.com
15+
|spec:
16+
| # group name to use for REST API: /apis/<group>/<version>
17+
| group: stable.example.com
18+
| # list of versions supported by this CustomResourceDefinition
19+
| versions:
20+
| - name: v1
21+
| # Each version can be enabled/disabled by Served flag.
22+
| served: true
23+
| # One and only one version must be marked as the storage version.
24+
| storage: true
25+
| schema:
26+
| openAPIV3Schema:
27+
| type: object
28+
| properties:
29+
| spec:
30+
| type: object
31+
| properties:
32+
| cronSpec:
33+
| type: string
34+
| image:
35+
| type: string
36+
| replicas:
37+
| type: integer
38+
| # either Namespaced or Cluster
39+
| scope: Namespaced
40+
| names:
41+
| # plural name to be used in the URL: /apis/<group>/<version>/<plural>
42+
| plural: crontabs
43+
| # singular name to be used as an alias on the CLI and for display
44+
| singular: crontab
45+
| # kind is normally the CamelCased singular type. Your resource manifests use this.
46+
| kind: CronTab
47+
| # shortNames allow shorter string to match your resource on the CLI
48+
| shortNames:
49+
| - ct
50+
| """.stripMargin
51+
)
52+
)
53+
54+
val cronTab =
55+
k8s.yaml.v2.ConfigGroup(
56+
name = "cron-tab",
57+
k8s.yaml.v2.ConfigGroupArgs(
58+
yaml = """apiVersion: "stable.example.com/v1"
59+
|kind: CronTab
60+
|metadata:
61+
| name: my-new-cron-object
62+
|spec:
63+
| cronSpec: "* * * * */5"
64+
| image: my-awesome-cron-image
65+
| """.stripMargin
66+
),
67+
opts = opts(dependsOn = crd)
68+
)
69+
70+
Stack.exports(
71+
crdResource = crd.resources,
72+
cronTabResource = cronTab.resources
73+
)
74+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: kubernetes-yaml-crd
2+
runtime: scala
3+
description: Example of a Kubernetes Application using plain YAML files with custom CRD
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Kubernetes application using plain YAML files with custom CRD
2+
3+
Example based
4+
on [Kubernetes custom resource definitions](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/).
5+
Uses plain YAML files to create custom CronTab CRD and deploy it to Kubernetes cluster.
6+
7+
## Prerequisites
8+
9+
Follow the steps in [Pulumi Installation and
10+
Setup](https://www.pulumi.com/docs/get-started/install/) and [Configuring Pulumi
11+
Kubernetes](https://www.pulumi.com/docs/intro/cloud-providers/kubernetes/setup/) to get set up with
12+
Pulumi and Kubernetes.
13+
14+
## Running the App
15+
16+
1. Create a new stack:
17+
18+
```sh
19+
$ pulumi stack init
20+
Enter a stack name: dev
21+
```
22+
23+
2. Preview the deployment of the application and perform the deployment:
24+
25+
```sh
26+
$ pulumi up
27+
```
28+
29+
3. You can then manage your CronTab objects using kubectl:
30+
31+
```sh
32+
$ kubectl get crontab
33+
```
34+
Should print a list like this:
35+
```
36+
NAME AGE
37+
my-new-cron-object 6s
38+
```
39+
40+
4. You can also view the raw YAML data:
41+
42+
```sh
43+
$ kubectl get ct -o yaml
44+
```
45+
46+
5. From there, feel free to experiment. Simply making edits and running pulumi up will incrementally update your
47+
infrastructure.
48+
49+
6. Once you've finished experimenting, tear down your stack's resources by destroying and removing it:
50+
51+
```bash
52+
$ pulumi destroy --yes
53+
$ pulumi stack rm --yes
54+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//> using scala "3.3.1"
2+
//> using options -Werror -Wunused:all -Wvalue-discard -Wnonunit-statement
3+
//> using dep "org.virtuslab::besom-core:0.3.1"
4+
//> using dep "org.virtuslab::besom-kubernetes:4.11.0-core.0.3"

0 commit comments

Comments
 (0)