Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add aws eks hello world example #399

Merged
merged 7 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add aws eks hello world example
  • Loading branch information
polkx committed Feb 21, 2024
commit 02a72280cde26542bf28784d606fd09086cd92b2
66 changes: 66 additions & 0 deletions examples/aws-eks-hello-world/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import besom.*
import besom.api.eks
import besom.api.kubernetes.apps.v1.inputs.DeploymentSpecArgs
import besom.api.kubernetes.apps.v1.{Deployment, DeploymentArgs}
import besom.api.kubernetes.core.v1.enums.ServiceSpecType
import besom.api.kubernetes.core.v1.inputs.*
import besom.api.kubernetes.core.v1.{Service, ServiceArgs}
import besom.api.kubernetes.meta.v1.inputs.{LabelSelectorArgs, ObjectMetaArgs}
import besom.api.kubernetes.{Provider, ProviderArgs}

@main def main = Pulumi.run {
val appLabels = Map("app" -> "hello-world")
val helloKubernetesPort = 8080

val cluster = eks.Cluster("cluster")

val k8sProvider = Provider(
name = "k8s-provider",
ProviderArgs(kubeconfig = cluster.kubeconfigJson)
)

val deployment = Deployment(
name = "hello-world-deployment",
DeploymentArgs(
spec = DeploymentSpecArgs(
selector = LabelSelectorArgs(matchLabels = appLabels),
replicas = 2,
template = PodTemplateSpecArgs(
metadata = ObjectMetaArgs(appLabels = appLabels),
spec = PodSpecArgs(
containers = ContainerArgs(
name = "hello-world",
image = "paulbouwer/hello-kubernetes:1.5",
ports = List(
ContainerPortArgs(containerPort = helloKubernetesPort)
)
) :: Nil
)
)
)
),
opts = opts(provider = k8sProvider)
)

val service = Service(
name = "hello-world-service",
ServiceArgs(
spec = ServiceSpecArgs(
selector = appLabels,
`type` = ServiceSpecType.LoadBalancer,
ports = List(
ServicePortArgs(port = 80, targetPort = helloKubernetesPort)
)
),
metadata = ObjectMetaArgs(appLabels = appLabels)
),
opts = opts(provider = k8sProvider, dependsOn = deployment)
)

Stack(cluster, service)
.exports(
serviceName = service.metadata.name,
serviceHostname = service.status.loadBalancer.ingress.map(_.map(_.head.hostname)),
kubeconfig = cluster.kubeconfig
)
}
8 changes: 8 additions & 0 deletions examples/aws-eks-hello-world/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: aws-eks-hello-world
runtime: scala
description: A minimal "Hello, World" container in EKS.
template:
config:
aws:region:
description: The AWS region to deploy into
default: us-west-2
58 changes: 58 additions & 0 deletions examples/aws-eks-hello-world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Amazon EKS Cluster: Hello World!

This example deploys an EKS Kubernetes cluster.

## Prerequisites

[Follow the instructions](https://www.pulumi.com/docs/clouds/aws/get-started/begin/)
to get started with Pulumi & AWS.

## Deploying

1. Create a new stack, which is an isolated deployment target for this example:

```bash
pulumi stack init aws-eks
```

2. Set the AWS region:

```bash
pulumi config set aws:region us-west-2
```

We recommend using `us-west-2` to host your EKS cluster as other regions (notably `us-east-1`) may have capacity issues that prevent EKS
clusters from creating.

3. Stand up the EKS cluster:

```bash
pulumi up
```
4. After 10-15 minutes, your cluster will be ready, and the `kubeconfig` JSON you'll use to connect to the cluster will
be available as an output. You can save this `kubeconfig` to a file like so:

```bash
pulumi stack output kubeconfig > kubeconfig.json
```

Once you have this file in hand, you can interact with your new cluster as usual via `kubectl`:

```bash
kubectl --kubeconfig=./kubeconfig.json get all --all-namespaces
```

5. And finally - open the application in your browser to see the running application.

```bash
curl http://$(pulumi stack output serviceHostname)
```

6. To clean up resources, destroy your stack and remove it:

```bash
pulumi destroy
```
```bash
pulumi stack rm aws-eks
```
5 changes: 5 additions & 0 deletions examples/aws-eks-hello-world/project.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//> using scala "3.3.1"
//> using options -Werror -Wunused:all -Wvalue-discard -Wnonunit-statement
//> using plugin "org.virtuslab::besom-compiler-plugin:0.2.1"
//> using dep "org.virtuslab::besom-core:0.2.1"
//> using dep "org.virtuslab::besom-eks:2.2.1-core.0.2"
Loading