Skip to content

Commit

Permalink
Add AWS EKS example
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelprazak committed Feb 6, 2024
1 parent 7c0bb33 commit 501318b
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
10 changes: 10 additions & 0 deletions examples/aws-eks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### 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*

kubeconfig.json
60 changes: 60 additions & 0 deletions examples/aws-eks/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import besom.*
import besom.api.aws
import besom.api.eks
import besom.api.kubernetes as k8s

@main def main = Pulumi.run {
// Get the default VPC and select the default subnet
val vpc = aws.ec2.getVpc(aws.ec2.GetVpcArgs(default = true))
val subnet = vpc.flatMap(vpc =>
aws.ec2.getSubnet(
aws.ec2.GetSubnetArgs(
vpcId = vpc.id,
defaultForAz = true
)
)
)

// Create an EKS cluster using the default VPC and subnet
val cluster = eks.Cluster(
"my-cluster",
eks.ClusterArgs(
vpcId = vpc.id,
subnetIds = List(subnet.id),
instanceType = "t2.medium",
desiredCapacity = 2,
minSize = 1,
maxSize = 3,
storageClasses = "gp2"
)
)

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

val pod = k8s.core.v1.Pod(
"mypod",
k8s.core.v1.PodArgs(
spec = k8s.core.v1.inputs.PodSpecArgs(
containers = List(
k8s.core.v1.inputs.ContainerArgs(
name = "echo",
image = "k8s.gcr.io/echoserver:1.4"
)
)
)
),
opts = opts(
provider = k8sProvider,
dependsOn = cluster,
deletedWith = cluster // skip deletion to save time, since it will be deleted with the cluster
)
)

// Export the cluster's kubeconfig
Stack(cluster, pod).exports(kubeconfig = cluster.kubeconfig)
}
8 changes: 8 additions & 0 deletions examples/aws-eks/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: aws-eks
description: EKS cluster example
runtime: scala
template:
config:
aws:region:
description: The AWS region to deploy into
default: us-west-2
57 changes: 57 additions & 0 deletions examples/aws-eks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Amazon EKS Cluster

This example deploys an EKS Kubernetes cluster with an EBS-backed StorageClass.

## Prerequisites

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

## Deploying

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 aws-eks-dev
```

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.

We are tracking enabling the creation of VPCs limited to specific AZs to unblock this in `us-east-1`: pulumi/pulumi-awsx#32

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 --show-secrets > 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 pods --all-namespaces
```

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

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

0 comments on commit 501318b

Please sign in to comment.