Created
February 14, 2019 01:50
-
-
Save metral/3adb81a60abd00b767e624838e060ee5 to your computer and use it in GitHub Desktop.
private EKS cluster with public LB
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
import * as awsx from "@pulumi/awsx"; | |
import * as eks from "@pulumi/eks"; | |
import * as k8s from "@pulumi/kubernetes"; | |
const name = "test001" | |
// Pull in existing VPC | |
const vpc = awsx.Network.fromVpc(name, | |
{ | |
vpcId: "vpc-<ID0>", | |
subnetIds: ["subnet-<ID1>", "subnet-<ID2>", "subnet-<ID3>"], | |
usePrivateSubnets: true, | |
securityGroupIds: ["sg-<ID4>"], | |
publicSubnetIds: ["subnet-<ID5>", "subnet-<ID6>", "subnet-<ID7>"], | |
} | |
); | |
// Create an EKS cluster | |
const cluster = new eks.Cluster(name, { | |
vpcId: vpc.vpcId, | |
subnetIds: vpc.subnetIds, | |
desiredCapacity: 2, | |
minSize: 1, | |
maxSize: 2, | |
storageClasses: "gp2", | |
deployDashboard: false, | |
}); | |
// Export the clusters' kubeconfig. | |
export const kubeconfig = cluster.kubeconfig | |
// Create a Kubernetes Namespace | |
const ns = new k8s.core.v1.Namespace(name, {}, { provider: cluster.provider }); | |
export const namespaceName = ns.metadata.apply(m => m.name); | |
// Create a NGINX Deployment | |
const appLabels = { app: name }; | |
export const deployment = new k8s.apps.v1.Deployment(name, | |
{ | |
metadata: { | |
namespace: namespaceName, | |
labels: appLabels, | |
}, | |
spec: { | |
replicas: 1, | |
selector: { matchLabels: appLabels }, | |
template: { | |
metadata: { | |
labels: appLabels, | |
}, | |
spec: { | |
containers: [ | |
{ | |
name: name, | |
image: "nginx:latest", | |
ports: [{ name: "http", containerPort: 80 }] | |
} | |
], | |
} | |
} | |
}, | |
}, | |
{ | |
provider: cluster.provider, | |
} | |
); | |
export const deploymentName = deployment.metadata.apply(m => m.name); | |
// Create a LoadBalancer Service for the NGINX Deployment | |
const service = new k8s.core.v1.Service(name, | |
{ | |
metadata: { | |
labels: appLabels, | |
namespace: namespaceName, | |
}, | |
spec: { | |
type: "LoadBalancer", | |
ports: [{ port: 80, targetPort: "http" }], | |
selector: appLabels, | |
}, | |
}, | |
{ | |
provider: cluster.provider, | |
} | |
); | |
// Export the Service name and public LoadBalancer endpoint | |
export const serviceName = service.metadata.apply(m => m.name); | |
export const serviceHostname = service.status.apply(s => s.loadBalancer.ingress[0].hostname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment