index.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import * as awsx from '@pulumi/awsx'
  2. import * as eks from '@pulumi/eks'
  3. import * as k8s from '@pulumi/kubernetes'
  4. import * as pulumi from '@pulumi/pulumi'
  5. const awsConfig = new pulumi.Config('aws')
  6. // Create a VPC for our cluster.
  7. const vpc = new awsx.ec2.Vpc('vpc', { numberOfAvailabilityZones: 2 })
  8. // Create an EKS cluster with the default configuration.
  9. const cluster = new eks.Cluster('eksctl-my-cluster', {
  10. vpcId: vpc.id,
  11. subnetIds: vpc.publicSubnetIds,
  12. instanceType: 't2.micro',
  13. providerCredentialOpts: {
  14. profileName: awsConfig.get('profile'),
  15. },
  16. })
  17. // Export the cluster's kubeconfig.
  18. export const kubeconfig = cluster.kubeconfig
  19. // Create a repository
  20. const repo = new awsx.ecr.Repository('my-repo')
  21. // Build an image and publish it to our ECR repository.
  22. export const colossusImage = repo.buildAndPushImage({
  23. dockerfile: '../../../colossus.Dockerfile',
  24. context: '../../../',
  25. })
  26. const name = 'storage-node'
  27. // Create a Kubernetes Namespace
  28. const ns = new k8s.core.v1.Namespace(name, {}, { provider: cluster.provider })
  29. // Export the Namespace name
  30. export const namespaceName = ns.metadata.name
  31. // Create a NGINX Deployment
  32. const appLabels = { appClass: name }
  33. const deployment = new k8s.apps.v1.Deployment(
  34. name,
  35. {
  36. metadata: {
  37. namespace: namespaceName,
  38. labels: appLabels,
  39. },
  40. spec: {
  41. replicas: 1,
  42. selector: { matchLabels: appLabels },
  43. template: {
  44. metadata: {
  45. labels: appLabels,
  46. },
  47. spec: {
  48. containers: [
  49. {
  50. name: 'ipfs',
  51. image: 'ipfs/go-ipfs:latest',
  52. ports: [{ containerPort: 5001 }, { containerPort: 8080 }],
  53. },
  54. {
  55. name: 'colossus',
  56. image: colossusImage,
  57. env: [
  58. {
  59. name: 'WS_PROVIDER_ENDPOINT_URI',
  60. // example 'wss://18.209.241.63.nip.io/'
  61. value: process.env.WS_PROVIDER_ENDPOINT_URI,
  62. },
  63. {
  64. name: 'DEBUG',
  65. value: '*',
  66. },
  67. ],
  68. command: [
  69. 'yarn',
  70. 'colossus',
  71. '--dev',
  72. '--ws-provider',
  73. '$(WS_PROVIDER_ENDPOINT_URI)',
  74. '--ipfs-host',
  75. 'ipfs',
  76. ],
  77. ports: [{ containerPort: 3001 }],
  78. },
  79. ],
  80. },
  81. },
  82. },
  83. },
  84. {
  85. provider: cluster.provider,
  86. }
  87. )
  88. // Export the Deployment name
  89. export const deploymentName = deployment.metadata.name
  90. // Create a LoadBalancer Service for the NGINX Deployment
  91. const service = new k8s.core.v1.Service(
  92. name,
  93. {
  94. metadata: {
  95. labels: appLabels,
  96. namespace: namespaceName,
  97. },
  98. spec: {
  99. type: 'LoadBalancer',
  100. ports: [
  101. { name: 'port-1', port: 5001 },
  102. { name: 'port-2', port: 8080 },
  103. { name: 'port-3', port: 3001 },
  104. ],
  105. selector: appLabels,
  106. },
  107. },
  108. {
  109. provider: cluster.provider,
  110. }
  111. )
  112. // Export the Service name and public LoadBalancer Endpoint
  113. export const serviceName = service.metadata.name
  114. export const serviceHostname = service.status.loadBalancer.ingress[0].hostname