forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
98 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,98 @@ | ||
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new) | ||
|
||
# Amazon EKS Distroy Cluster | ||
|
||
This example deploys an Amazon EKS Distro cluster using a [dynamic provider](https://www.pulumi.com/docs/intro/concepts/programming-model/#dynamicproviders) which utilizes [kops](https://github.com/kubernetes/kops) | ||
|
||
## Deploying the App | ||
|
||
To deploy your infrastructure, follow the below steps. | ||
|
||
### Prerequisites | ||
|
||
1. [Install Pulumi](https://www.pulumi.com/docs/get-started/install/) | ||
2. [Install Node.js](https://nodejs.org/en/download/) | ||
3. [Install Kops](https://kops.sigs.k8s.io/getting_started/install/) | ||
4. [Configure AWS Credentials](https://www.pulumi.com/docs/intro/cloud-providers/aws/setup/) | ||
5. [Install `aws-iam-authenticator`](https://docs.aws.amazon.com/eks/latest/userguide/install-aws-iam-authenticator.html) | ||
|
||
### Steps | ||
|
||
After cloning this repo, from this working directory, run these commands: | ||
|
||
1. Install the required Node.js packages: | ||
|
||
```bash | ||
$ npm install | ||
``` | ||
|
||
2. Create a new stack, which is an isolated deployment target for this example: | ||
|
||
```bash | ||
$ pulumi stack init | ||
``` | ||
|
||
3. Set the required configuration variables for this program: | ||
|
||
```bash | ||
$ pulumi config set aws:region us-west-2 | ||
``` | ||
|
||
4. Stand up the EKS cluster, which will also deploy the Kubernetes Dashboard: | ||
|
||
```bash | ||
$ pulumi up | ||
``` | ||
|
||
5. 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 | ||
$ KUBECONFIG=./kubeconfig.json kubectl get nodes | ||
``` | ||
|
||
|
||
7. From there, feel free to experiment. Make edits and run `pulumi up` to incrementally update your stack. | ||
For example, in order to deploy a Helm chart into your cluster, import the `@pulumi/kubernetes/helm` package, | ||
add a `Chart` resource that targets the EKS cluster to `index.ts`, and run `pulumi up`. Note that the Helm client | ||
must be set up in order for the chart to deploy. For more details, see the [Prerequisites](#prerequisites) list. | ||
|
||
```typescript | ||
import * as helm from "@pulumi/kubernetes/helm"; | ||
|
||
// ... existing code here ... | ||
|
||
const myk8s = new k8s.Provider("myk8s", { | ||
kubeconfig: cluster.kubeconfig.apply(JSON.stringify), | ||
}); | ||
|
||
const postgres = new helm.v2.Chart("postgres", { | ||
// stable/[email protected] | ||
repo: "stable", | ||
chart: "postgresql", | ||
version: "0.15.0", | ||
values: { | ||
// Use a stable password. | ||
postgresPassword: "some-password", | ||
// Expose the postgres server via a load balancer. | ||
service: { | ||
type: "LoadBalancer", | ||
}, | ||
}, | ||
}, { providers: { kubernetes: myk8s } }); | ||
``` | ||
|
||
Once the chart has been deployed, you can find its public, load-balanced endpoint via the Kubernetes Dashboard. | ||
|
||
8. Once you've finished experimenting, tear down your stack's resources by destroying and removing it: | ||
|
||
```bash | ||
$ pulumi destroy --yes | ||
$ pulumi stack rm --yes | ||
``` |