index.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 from the "./app" directory
  22. // and publish it to our ECR repository.
  23. export const ipfsImage = repo.buildAndPushImage('./app')
  24. export const colossusImage = repo.buildAndPushImage({
  25. dockerfile: '../../../colossus.Dockerfile',
  26. context: '../../../',
  27. })
  28. const name = 'storage-node'
  29. // Create a Kubernetes Namespace
  30. const ns = new k8s.core.v1.Namespace(name, {}, { provider: cluster.provider })
  31. // Export the Namespace name
  32. export const namespaceName = ns.metadata.name
  33. // Create a NGINX Deployment
  34. const appLabels = { appClass: name }
  35. const deployment = new k8s.apps.v1.Deployment(
  36. name,
  37. {
  38. metadata: {
  39. namespace: namespaceName,
  40. labels: appLabels,
  41. },
  42. spec: {
  43. replicas: 1,
  44. selector: { matchLabels: appLabels },
  45. template: {
  46. metadata: {
  47. labels: appLabels,
  48. },
  49. spec: {
  50. containers: [
  51. {
  52. name: 'ipfs',
  53. image: ipfsImage,
  54. ports: [{ containerPort: 5001 }, { containerPort: 8080 }],
  55. },
  56. {
  57. name: 'colossus',
  58. image: colossusImage,
  59. env: [
  60. {
  61. name: 'WS_PROVIDER_ENDPOINT_URI',
  62. value: 'wss://18.209.241.63.nip.io/',
  63. },
  64. {
  65. name: 'DEBUG',
  66. value: '*',
  67. },
  68. ],
  69. command: [
  70. 'yarn',
  71. 'colossus',
  72. '--dev',
  73. '--ws-provider',
  74. '$(WS_PROVIDER_ENDPOINT_URI)',
  75. '--ipfs-host',
  76. 'ipfs',
  77. ],
  78. ports: [{ containerPort: 3001 }],
  79. },
  80. ],
  81. },
  82. },
  83. },
  84. },
  85. {
  86. provider: cluster.provider,
  87. }
  88. )
  89. // Export the Deployment name
  90. export const deploymentName = deployment.metadata.name
  91. // Create a LoadBalancer Service for the NGINX Deployment
  92. const service = new k8s.core.v1.Service(
  93. name,
  94. {
  95. metadata: {
  96. labels: appLabels,
  97. namespace: namespaceName,
  98. },
  99. spec: {
  100. type: 'LoadBalancer',
  101. ports: [
  102. { name: 'port-1', port: 5001 },
  103. { name: 'port-2', port: 8080 },
  104. { name: 'port-3', port: 3001 },
  105. ],
  106. selector: appLabels,
  107. },
  108. },
  109. {
  110. provider: cluster.provider,
  111. }
  112. )
  113. // Export the Service name and public LoadBalancer Endpoint
  114. export const serviceName = service.metadata.name
  115. export const serviceHostname = service.status.loadBalancer.ingress[0].hostname
  116. console.log(serviceHostname)