-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Kubernetes YAML with CRD example (#477)
- Loading branch information
Showing
5 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
### Scala an JVM | ||
*.class | ||
*.log | ||
.bsp | ||
.scala-build | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import besom.* | ||
import besom.api.kubernetes as k8s | ||
|
||
@main def main = Pulumi.run { | ||
|
||
val crd = | ||
k8s.yaml.v2.ConfigGroup( | ||
name = "config-group", | ||
k8s.yaml.v2.ConfigGroupArgs( | ||
yaml = """apiVersion: apiextensions.k8s.io/v1 | ||
|kind: CustomResourceDefinition | ||
|metadata: | ||
| # name must match the spec fields below, and be in the form: <plural>.<group> | ||
| name: crontabs.stable.example.com | ||
|spec: | ||
| # group name to use for REST API: /apis/<group>/<version> | ||
| group: stable.example.com | ||
| # list of versions supported by this CustomResourceDefinition | ||
| versions: | ||
| - name: v1 | ||
| # Each version can be enabled/disabled by Served flag. | ||
| served: true | ||
| # One and only one version must be marked as the storage version. | ||
| storage: true | ||
| schema: | ||
| openAPIV3Schema: | ||
| type: object | ||
| properties: | ||
| spec: | ||
| type: object | ||
| properties: | ||
| cronSpec: | ||
| type: string | ||
| image: | ||
| type: string | ||
| replicas: | ||
| type: integer | ||
| # either Namespaced or Cluster | ||
| scope: Namespaced | ||
| names: | ||
| # plural name to be used in the URL: /apis/<group>/<version>/<plural> | ||
| plural: crontabs | ||
| # singular name to be used as an alias on the CLI and for display | ||
| singular: crontab | ||
| # kind is normally the CamelCased singular type. Your resource manifests use this. | ||
| kind: CronTab | ||
| # shortNames allow shorter string to match your resource on the CLI | ||
| shortNames: | ||
| - ct | ||
| """.stripMargin | ||
) | ||
) | ||
|
||
val cronTab = | ||
k8s.yaml.v2.ConfigGroup( | ||
name = "cron-tab", | ||
k8s.yaml.v2.ConfigGroupArgs( | ||
yaml = """apiVersion: "stable.example.com/v1" | ||
|kind: CronTab | ||
|metadata: | ||
| name: my-new-cron-object | ||
|spec: | ||
| cronSpec: "* * * * */5" | ||
| image: my-awesome-cron-image | ||
| """.stripMargin | ||
), | ||
opts = opts(dependsOn = crd) | ||
) | ||
|
||
Stack.exports( | ||
crdResource = crd.resources, | ||
cronTabResource = cronTab.resources | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: kubernetes-yaml-crd | ||
runtime: scala | ||
description: Example of a Kubernetes Application using plain YAML files with custom CRD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Kubernetes application using plain YAML files with custom CRD | ||
|
||
Example based | ||
on [Kubernetes custom resource definitions](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/). | ||
Uses plain YAML files to create custom CronTab CRD and deploy it to Kubernetes cluster. | ||
|
||
## Prerequisites | ||
|
||
Follow the steps in [Pulumi Installation and | ||
Setup](https://www.pulumi.com/docs/get-started/install/) and [Configuring Pulumi | ||
Kubernetes](https://www.pulumi.com/docs/intro/cloud-providers/kubernetes/setup/) to get set up with | ||
Pulumi and Kubernetes. | ||
|
||
## Running the App | ||
|
||
1. Create a new stack: | ||
|
||
```sh | ||
$ pulumi stack init | ||
Enter a stack name: dev | ||
``` | ||
|
||
2. Preview the deployment of the application and perform the deployment: | ||
|
||
```sh | ||
$ pulumi up | ||
``` | ||
|
||
3. You can then manage your CronTab objects using kubectl: | ||
|
||
```sh | ||
$ kubectl get crontab | ||
``` | ||
Should print a list like this: | ||
``` | ||
NAME AGE | ||
my-new-cron-object 6s | ||
``` | ||
|
||
4. You can also view the raw YAML data: | ||
|
||
```sh | ||
$ kubectl get ct -o yaml | ||
``` | ||
|
||
5. From there, feel free to experiment. Simply making edits and running pulumi up will incrementally update your | ||
infrastructure. | ||
|
||
6. Once you've finished experimenting, tear down your stack's resources by destroying and removing it: | ||
|
||
```bash | ||
$ pulumi destroy --yes | ||
$ pulumi stack rm --yes | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//> using scala "3.3.1" | ||
//> using options -Werror -Wunused:all -Wvalue-discard -Wnonunit-statement | ||
//> using dep "org.virtuslab::besom-core:0.3.1" | ||
//> using dep "org.virtuslab::besom-kubernetes:4.11.0-core.0.3" |