-
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-nginx example * Fix test-examples in Justfile * Fix test-templates in Justfile
- Loading branch information
1 parent
fec6fec
commit 01b1cfd
Showing
6 changed files
with
132 additions
and
17 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
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,47 @@ | ||
import besom.* | ||
import besom.api.kubernetes | ||
import besom.api.kubernetes.core.v1.* | ||
import besom.api.kubernetes.core.v1.inputs.* | ||
import besom.api.kubernetes.apps.v1.* | ||
import besom.api.kubernetes.apps.v1.inputs.* | ||
import besom.api.kubernetes.meta.v1.* | ||
import besom.api.kubernetes.meta.v1.inputs.* | ||
|
||
@main def main = Pulumi.run { | ||
val nginxLabels = Map("app" -> "nginx") | ||
val nginxDeployment = kubernetes.apps.v1.Deployment( | ||
"nginx", | ||
kubernetes.apps.v1.DeploymentArgs( | ||
spec = DeploymentSpecArgs( | ||
replicas = config.getInt("replicas"), | ||
selector = LabelSelectorArgs( | ||
matchLabels = nginxLabels | ||
), | ||
template = PodTemplateSpecArgs( | ||
metadata = ObjectMetaArgs( | ||
labels = nginxLabels | ||
), | ||
spec = PodSpecArgs( | ||
containers = List( | ||
ContainerArgs( | ||
name = "nginx", | ||
image = "nginx:stable", | ||
ports = List( | ||
ContainerPortArgs( | ||
containerPort = 80 | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
|
||
for { | ||
_ <- nginxDeployment | ||
} yield exports( | ||
nginx = nginxDeployment.metadata.name | ||
) | ||
} |
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 @@ | ||
name: kubernetes-nginx | ||
runtime: scala | ||
description: Example of a Kubernetes Stateless Application Deployment, using Nginx | ||
template: |
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,53 @@ | ||
# Stateless Application Using a Kubernetes Deployment | ||
|
||
A version of the [Kubernetes Stateless Application Deployment]( | ||
https://kubernetes.io/docs/tasks/run-application/run-stateless-application-deployment/) example that uses Pulumi. | ||
This example deploys a replicated Nginx server to a Kubernetes cluster, using Scala and no YAML. | ||
|
||
This example is based on a [Pulumi Tutorial available here](https://www.pulumi.com/docs/tutorials/kubernetes/stateless-app/). | ||
|
||
## Prerequisites | ||
|
||
[Follow the instructions](https://www.pulumi.com/docs/clouds/kubernetes/get-started/begin/) | ||
to get started with Pulumi & Kubernetes. | ||
|
||
## Deploying and running the program | ||
|
||
Note: some values in this example will be different from run to run. | ||
These values are indicated with `***`. | ||
|
||
1. Create a new stack, which is an isolated deployment target for this example: | ||
|
||
```bash | ||
pulumi stack init kubernetes-nginx-dev | ||
``` | ||
|
||
2. Run `pulumi up` to preview and deploy changes. After the preview is shown | ||
you will be prompted if you want to continue or not. | ||
|
||
```bash | ||
pulumi config set replicas 2 | ||
pulumi up | ||
``` | ||
|
||
After a couple of minutes, your deployment will be ready, then you can run commands like `kubectl get pods` | ||
to see the application's resources. | ||
The stack's replica count is configurable. By default, it will scale up to three instances, but we can easily change | ||
that to five, by running the `pulumi config` command followed by another `pulumi up`: | ||
|
||
```bash | ||
pulumi config set replicas 5 | ||
pulumi up | ||
``` | ||
|
||
3. From there, feel free to experiment. Simply making edits and running pulumi up will incrementally update your infrastructure. | ||
|
||
4. To clean up resources, destroy your stack and remove it: | ||
|
||
```bash | ||
pulumi destroy | ||
``` | ||
```bash | ||
pulumi stack rm kubernetes-nginx-dev | ||
``` |
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,5 @@ | ||
//> using scala "3.3.1" | ||
//> using plugin "org.virtuslab::besom-compiler-plugin:0.1.0" | ||
//> using dep "org.virtuslab::besom-core:0.1.0" | ||
//> using dep "org.virtuslab::besom-kubernetes:4.3.0-core.0.1.0" | ||
//> using options -Werror -Wunused:all -Wvalue-discard -Wnonunit-statement |