Amazon EKS Cluster
EKS cluster example
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set aws-ts-ekscd pulumi-examples/aws-ts-eksThis example deploys an EKS Kubernetes cluster with an EBS-backed StorageClass and deploys the Kubernetes Dashboard into the cluster.
Deploying the App#
To deploy your infrastructure, follow the below steps.
Prerequisites#
If you’d like to follow the optional instructions in step 7 in order to deploy a Helm chart into your cluster, you’ll also need to set up the Helm client:
-
If you are using Helm v2, initialize the Helm client:
Terminal window helm init --client-only
Steps#
After cloning this repo, from this working directory, run these commands:
-
Install the required Node.js packages:
Terminal window npm install -
Create a new stack, which is an isolated deployment target for this example:
Terminal window pulumi stack init -
Set the required configuration variables for this program:
Terminal window pulumi config set aws:region us-west-2We recommend using
us-west-2to host your EKS cluster as other regions (notablyus-east-1) may have capacity issues that prevent EKS clusters from creating:Diagnostics:aws:eks:Cluster: eksClustererror: Plan apply failed: creating urn:pulumi:aws-ts-eks-example::aws-ts-eks::EKSCluster$aws:eks/cluster:Cluster::eksCluster: error creating EKS Cluster (eksCluster-233c968): UnsupportedAvailabilityZoneException: Cannot create cluster 'eksCluster-233c968' because us-east-1a, the targeted availability zone, does not currently have sufficient capacity to support the cluster. Retry and choose from these availability zones: us-east-1b, us-east-1c, us-east-1dstatus code: 400, request id: 9f031e89-a0b0-11e8-96f8-534c1d26a353We are tracking enabling the creation of VPCs limited to specific AZs to unblock this in
us-east-1: pulumi/pulumi-awsx#32 -
Stand up the EKS cluster, which will also deploy the Kubernetes Dashboard:
Terminal window pulumi up -
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:
Terminal window pulumi stack output kubeconfig --show-secrets >kubeconfig.jsonOnce you have this file in hand, you can interact with your new cluster as usual via
kubectl:Terminal window KUBECONFIG=./kubeconfig.json kubectl get nodes -
You can now connect to the Kubernetes Dashboard by fetching an authentication token and starting the kubectl proxy.
-
Fetch an authentication token:
Terminal window KUBECONFIG=./kubeconfig.json kubectl -n kube-system get secret | grep eks-admin | awk '{print $1}'eks-admin-token-b5zv4KUBECONFIG=./kubeconfig.json kubectl -n kube-system describe secret eks-admin-token-b5zv4Name: eks-admin-token-b5zv4Namespace: kube-systemLabels: <none>Annotations: kubernetes.io/service-account.name=eks-adminkubernetes.io/service-account.uid=bcfe66ac-39be-11e8-97e8-026dce96b6e8Type: kubernetes.io/service-account-tokenData====token: <authentication_token>ca.crt: 1025 bytesnamespace: 11 bytes -
Run the kubectl proxy:
Terminal window KUBECONFIG=./kubeconfig.json kubectl proxy -
Open
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/in a web browser. -
Choose
Tokenauthentication, paste the token retrieved earlier into theTokenfield, and sign in.
-
-
From there, feel free to experiment. Make edits and run
pulumi upto incrementally update your stack. For example, in order to deploy a Helm chart into your cluster, import the@pulumi/kubernetes/helmpackage, add aChartresource that targets the EKS cluster toindex.ts, and runpulumi up. Note that the Helm client must be set up in order for the chart to deploy. For more details, see the Prerequisites list.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/postgresql@0.15.0repo: "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.
-
Once you’ve finished experimenting, tear down your stack’s resources by destroying and removing it:
Terminal window pulumi destroy --yespulumi stack rm --yes